From 5af0036e65cb1b6fd4e0904a4333a2e864f35222 Mon Sep 17 00:00:00 2001 From: Michael Cooper Date: Tue, 10 Sep 2024 16:16:57 -0700 Subject: [PATCH 1/3] some organization of tests --- tests/archives.test.ts | 5 ++++- tests/data-manip.test.ts | 13 ++++++++----- tests/editing-tools.test.ts | 5 ++++- tests/general-cli.test.ts | 5 ++++- tests/images.test.ts | 5 ++++- tests/networking.test.ts | 5 ++++- 6 files changed, 28 insertions(+), 10 deletions(-) diff --git a/tests/archives.test.ts b/tests/archives.test.ts index f4ae48b..d31fd89 100644 --- a/tests/archives.test.ts +++ b/tests/archives.test.ts @@ -1,3 +1,4 @@ +import { describe } from "node:test"; import { binaryOnPathTest } from "./index.ts"; const archiveTools = [ @@ -8,4 +9,6 @@ const archiveTools = [ { binary: "zstd" }, ]; -archiveTools.forEach(binaryOnPathTest); +await describe("Archive tools", () => { + archiveTools.forEach(binaryOnPathTest); +}); diff --git a/tests/data-manip.test.ts b/tests/data-manip.test.ts index b24de73..e5270a4 100644 --- a/tests/data-manip.test.ts +++ b/tests/data-manip.test.ts @@ -1,3 +1,4 @@ +import { describe } from "node:test"; import { binaryOnPathTest, binaryVersionTest } from "./index.ts"; const dataManipTools = [ @@ -6,10 +7,12 @@ const dataManipTools = [ { binary: "csv2parquet" }, ]; -dataManipTools.forEach(binaryOnPathTest); +describe("Data manipulation tools", () => { + dataManipTools.forEach(binaryOnPathTest); -binaryVersionTest({ - binary: "duckdb", - semver: "^1", - extract: /^v(.*) [0-9a-f]*$/, + binaryVersionTest({ + binary: "duckdb", + semver: "^1", + extract: /^v(.*) [0-9a-f]*$/, + }); }); diff --git a/tests/editing-tools.test.ts b/tests/editing-tools.test.ts index 7a111fb..1560bfe 100644 --- a/tests/editing-tools.test.ts +++ b/tests/editing-tools.test.ts @@ -1,3 +1,4 @@ +import { describe } from "node:test"; import { binaryOnPathTest } from "./index.ts"; const textManipTools: { binary: string }[] = [ @@ -13,4 +14,6 @@ const textManipTools: { binary: string }[] = [ { binary: "vim" }, ]; -textManipTools.forEach(binaryOnPathTest); +describe("editing tools", () => { + textManipTools.forEach(binaryOnPathTest); +}); diff --git a/tests/general-cli.test.ts b/tests/general-cli.test.ts index 785e136..aa400f3 100644 --- a/tests/general-cli.test.ts +++ b/tests/general-cli.test.ts @@ -1,3 +1,4 @@ +import { describe } from "node:test"; import { binaryOnPathTest } from "./index.ts"; const generalCliTools: { binary: string }[] = [ @@ -10,4 +11,6 @@ const generalCliTools: { binary: string }[] = [ { binary: "vmstat" }, ]; -generalCliTools.forEach(binaryOnPathTest); +describe("General CLI tools", () => { + generalCliTools.forEach(binaryOnPathTest); +}); diff --git a/tests/images.test.ts b/tests/images.test.ts index 7a70efa..4724424 100644 --- a/tests/images.test.ts +++ b/tests/images.test.ts @@ -1,3 +1,4 @@ +import { describe } from "node:test"; import { binaryOnPathTest } from "./index.ts"; const imageTools = [ @@ -6,4 +7,6 @@ const imageTools = [ { binary: "convert", name: "imagemagick" }, ]; -imageTools.forEach(binaryOnPathTest); +describe("Image tools", () => { + imageTools.forEach(binaryOnPathTest); +}); diff --git a/tests/networking.test.ts b/tests/networking.test.ts index 8b88a58..aab52d4 100644 --- a/tests/networking.test.ts +++ b/tests/networking.test.ts @@ -1,3 +1,4 @@ +import { describe } from "node:test"; import { binaryOnPathTest } from "./index.ts"; const networkingTools = [ @@ -10,4 +11,6 @@ const networkingTools = [ { binary: "wget" }, ]; -networkingTools.forEach(binaryOnPathTest); +describe("Networking tools", () => { + networkingTools.forEach(binaryOnPathTest); +}); From bdc3d9ec253ea773125d5c859a52c1fb227239f0 Mon Sep 17 00:00:00 2001 From: Michael Cooper Date: Tue, 10 Sep 2024 16:17:24 -0700 Subject: [PATCH 2/3] support yarn v2+ --- Dockerfile | 4 +-- tests/dataloader-languages.test.ts | 44 ++++++++++++++++++++---------- tests/index.ts | 12 ++++---- 3 files changed, 39 insertions(+), 21 deletions(-) diff --git a/Dockerfile b/Dockerfile index 9c2be74..392ab25 100644 --- a/Dockerfile +++ b/Dockerfile @@ -19,8 +19,8 @@ EOF RUN --mount=type=cache,target=/var/cache/apt,id=framework-runtime-node \ apt update \ && apt install -y --no-install-recommends nodejs \ - && npm install --global yarn -RUN npm install --global svgo + && corepack enable \ + && npm install --global svgo # == python ====================== FROM base AS python diff --git a/tests/dataloader-languages.test.ts b/tests/dataloader-languages.test.ts index d12d0b5..e1263ba 100644 --- a/tests/dataloader-languages.test.ts +++ b/tests/dataloader-languages.test.ts @@ -1,15 +1,8 @@ -import { test } from "node:test"; -import { binaryVersionTest, runCommandInContainer } from "./index.ts"; +import { test, describe } from "node:test"; +import assert from "node:assert/strict"; +import { binaryOnPathTest, binaryVersionTest, runCommandInContainer } from "./index.ts"; const dataLoaderLanguages = [ - { binary: "node", semver: "^20.17" }, - { binary: "npm", semver: "^10.5" }, - { binary: "yarn", semver: "^1.22" }, - { - binary: "python3", - semver: "^3.11", - prefix: "Python", - }, { binary: "Rscript", semver: "^4.4.1", @@ -33,9 +26,32 @@ const dataLoaderLanguages = [ }, ]; -dataLoaderLanguages.forEach(binaryVersionTest); +describe("Python", () => { + binaryVersionTest({ + binary: "python3", + semver: "^3.11", + prefix: "Python", + }); + + binaryOnPathTest({binary: "pip"}) + + test(`A Python virtual environment is activated`, async () => { + // should not throw + await runCommandInContainer(["pip", "install", "requests"]); + }); +}); + +describe("JavaScript", () => { + binaryVersionTest({ binary: "node", semver: "^20.17" }); + binaryVersionTest({ binary: "npm", semver: "^10.5" }); + binaryVersionTest({ + binary: "yarn", + semver: "^1.22", + expectStderr: /^! Corepack is about to download.*yarn/, + }); -await test(`A Python virtual environment is activated`, async () => { - // should not throw - await runCommandInContainer(["pip", "install", "requests"]); + test("Yarn Berry is available, and uses corepack", async () => { + const { stdout, stderr } = await runCommandInContainer(["sh", "-c", "mkdir test && cd test && yarn init -2"]); + assert.ok(!stdout.includes("You don't seem to have Corepack enabled")); + }); }); diff --git a/tests/index.ts b/tests/index.ts index 9173f79..4946302 100644 --- a/tests/index.ts +++ b/tests/index.ts @@ -13,18 +13,20 @@ export interface AssertBinaryVersionOptions { semver: string; extract?: RegExp; prefix?: string; + expectStderr?: RegExp; } -export function binaryVersionTest({ +export async function binaryVersionTest({ binary, name = binary, semver, extract, prefix, + expectStderr = /^$/, }: AssertBinaryVersionOptions) { - test(`${name} ${semver} is available`, async () => { + await test(`${name} ${semver} is available`, async () => { const res = await runCommandInContainer([binary, "--version"]); - assert.equal(res.stderr, ""); + assert.ok(res.stderr.match(expectStderr), `Expected stderr to match, got: ${res.stderr}`); assertSemver(res.stdout, semver, { extract, prefix }); }); } @@ -46,8 +48,8 @@ export function binaryOnPathTest({ } function assertSemver( - actual, - expected, + actual: string, + expected: string, { prefix, suffix, From 46d10d9073a152a7d5e2ce395c332dae97b83e04 Mon Sep 17 00:00:00 2001 From: Michael Cooper Date: Tue, 10 Sep 2024 16:32:48 -0700 Subject: [PATCH 3/3] pnpm and some more organization --- Dockerfile | 1 + tests/dataloader-languages.test.ts | 117 ++++++++++++++++++----------- tests/index.ts | 2 +- 3 files changed, 75 insertions(+), 45 deletions(-) diff --git a/Dockerfile b/Dockerfile index 392ab25..c04b9f7 100644 --- a/Dockerfile +++ b/Dockerfile @@ -20,6 +20,7 @@ RUN --mount=type=cache,target=/var/cache/apt,id=framework-runtime-node \ apt update \ && apt install -y --no-install-recommends nodejs \ && corepack enable \ + && corepack enable pnpm \ && npm install --global svgo # == python ====================== diff --git a/tests/dataloader-languages.test.ts b/tests/dataloader-languages.test.ts index e1263ba..e1e8a08 100644 --- a/tests/dataloader-languages.test.ts +++ b/tests/dataloader-languages.test.ts @@ -1,57 +1,86 @@ import { test, describe } from "node:test"; import assert from "node:assert/strict"; -import { binaryOnPathTest, binaryVersionTest, runCommandInContainer } from "./index.ts"; +import { + assertSemver, + binaryOnPathTest, + binaryVersionTest, + runCommandInContainer, +} from "./index.ts"; -const dataLoaderLanguages = [ - { +describe("Dataloader languages", () => { + describe("Python", () => { + binaryVersionTest({ + binary: "python3", + semver: "^3.11", + prefix: "Python", + }); + + binaryOnPathTest({ binary: "pip" }); + + test(`A Python virtual environment is activated`, async () => { + // should not throw + await runCommandInContainer(["pip", "install", "requests"]); + }); + }); + + describe("JavaScript", () => { + binaryVersionTest({ binary: "node", semver: "^20.17" }); + binaryVersionTest({ binary: "npm", semver: "^10.5" }); + + binaryVersionTest({ + binary: "yarn", + semver: "^1.22", + expectStderr: /^! Corepack is about to download.*yarn/, + }); + test("Yarn v2+ is available, and uses corepack", async () => { + const { stdout, stderr } = await runCommandInContainer([ + "sh", + "-c", + "mkdir test && cd test && yarn init -2", + ]); + assert.ok(!stdout.includes("You don't seem to have Corepack enabled")); + assert.ok(!stderr.includes("You don't seem to have Corepack enabled")); + }); + test("yarn ^4.4.1 is available via corepack", async () => { + const { stdout, stderr } = await runCommandInContainer([ + "sh", + "-c", + "mkdir test && cd test && yarn init -2 > /dev/null && yarn --version", + ]); + assertSemver(stdout, "^4.4.1"); + }); + + binaryVersionTest({ + binary: "pnpm", + semver: "^9.10", + expectStderr: /^! Corepack is about to download.*pnpm/, + }); + }); + + binaryVersionTest({ binary: "Rscript", semver: "^4.4.1", extract: /^Rscript \(R\) version ([^\s]+)/, - }, - { - name: "Rust", - binary: "cargo", - semver: "^1.81", - extract: /^cargo ([\d.]+)/, - }, - { - binary: "rust-script", - semver: "^0.35", - prefix: "rust-script", - }, - { - binary: "perl", - semver: "^5.36", - extract: /^This is perl 5,[^(]* \(([^)]+)\)/, - }, -]; - -describe("Python", () => { - binaryVersionTest({ - binary: "python3", - semver: "^3.11", - prefix: "Python", }); - binaryOnPathTest({binary: "pip"}) + describe("Rust", () => { + binaryVersionTest({ + name: "Rust", + binary: "cargo", + semver: "^1.81", + extract: /^cargo ([\d.]+)/, + }); - test(`A Python virtual environment is activated`, async () => { - // should not throw - await runCommandInContainer(["pip", "install", "requests"]); + binaryVersionTest({ + binary: "rust-script", + semver: "^0.35", + prefix: "rust-script", + }); }); -}); -describe("JavaScript", () => { - binaryVersionTest({ binary: "node", semver: "^20.17" }); - binaryVersionTest({ binary: "npm", semver: "^10.5" }); - binaryVersionTest({ - binary: "yarn", - semver: "^1.22", - expectStderr: /^! Corepack is about to download.*yarn/, - }); - - test("Yarn Berry is available, and uses corepack", async () => { - const { stdout, stderr } = await runCommandInContainer(["sh", "-c", "mkdir test && cd test && yarn init -2"]); - assert.ok(!stdout.includes("You don't seem to have Corepack enabled")); + binaryVersionTest({ + binary: "perl", + semver: "^5.36", + extract: /^This is perl 5,[^(]* \(([^)]+)\)/, }); }); diff --git a/tests/index.ts b/tests/index.ts index 4946302..8631845 100644 --- a/tests/index.ts +++ b/tests/index.ts @@ -47,7 +47,7 @@ export function binaryOnPathTest({ }); } -function assertSemver( +export function assertSemver( actual: string, expected: string, {