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

35 lines1,553 bytesCodeBlame
1import assert from "node:assert/strict";
2import { test } from "node:test";
3
4import { formatBytes, installCommands, shortDigest } from "./packages.ts";
5
6test("sizes read as registries show them", () => {
7 assert.equal(formatBytes(0), "0 B");
8 assert.equal(formatBytes(812), "812 B");
9 assert.equal(formatBytes(12_340_000), "12.3 MB");
10 assert.equal(formatBytes(1_400_000_000), "1.4 GB");
11 assert.equal(formatBytes(250_000_000), "250 MB");
12});
13
14test("digests shorten for lists", () => {
15 assert.equal(shortDigest("sha256:3f2a9c1b7d0e55aa"), "3f2a9c1b7d0e");
16});
17
18test("an npm package is installed after .npmrc names its scope's registry, and a token for private ones", () => {
19 const pkg = { ecosystem: "npm" as const, address: "g1t.sh/-/npm/@acme/ui", name: "ui", workspace: "acme" };
20 assert.deepEqual(installCommands(pkg, "1.2.0", "ada"), {
21 registry: "npm config set @acme:registry=https://g1t.sh/-/npm/",
22 login: "npm config set //g1t.sh/-/npm/:_authToken=YOUR_TOKEN",
23 install: "npm install @acme/ui@1.2.0",
24 });
25 assert.equal(installCommands(pkg, null, "ada").install, "npm install @acme/ui");
26});
27
28test("a container image is pulled by its address and tag", () => {
29 const pkg = { ecosystem: "container" as const, address: "g1t.sh/acme/web", name: "web", workspace: "acme" };
30 assert.deepEqual(installCommands(pkg, "latest", "ada"), {
31 login: "docker login g1t.sh -u ada",
32 install: "docker pull g1t.sh/acme/web:latest",
33 });
34 assert.equal(installCommands(pkg, null, "ada").install, "docker pull g1t.sh/acme/web");
35});