Skip to content

g1t/apps/web/app/lib/artifacts.test.ts

20 lines806 bytesCodeBlame
1import assert from "node:assert/strict";
2import { test } from "node:test";
3
4import { expiresIn, formatBytes } from "./artifacts.ts";
5
6test("sizes read as KB, MB or GB", () => {
7 assert.equal(formatBytes(10), "1 KB");
8 assert.equal(formatBytes(412_870), "403 KB");
9 assert.equal(formatBytes(18_734_120), "17.9 MB");
10 assert.equal(formatBytes(5 * 1024 ** 3), "5.00 GB");
11});
12
13test("expiry reads from now", () => {
14 const now = Date.parse("2026-10-08T12:00:00Z");
15 assert.equal(expiresIn("2026-10-22T12:00:00Z", now), "expires in 14 days");
16 assert.equal(expiresIn("2026-10-09T13:00:00Z", now), "expires tomorrow");
17 assert.equal(expiresIn("2026-10-08T20:00:00Z", now), "expires today");
18 assert.equal(expiresIn("2026-10-08T11:00:00Z", now), "expired");
19 assert.equal(expiresIn(null, now), "");
20});