From 695a8a1068f4bbcd5138c77cada72e60ba2a29f9 Mon Sep 17 00:00:00 2001 From: Michael Cooper Date: Tue, 10 Sep 2024 21:34:23 -0700 Subject: [PATCH] Yarn v2+, pnpm, and some test organization (#8) * some organization of tests * support yarn v2+ * pnpm and some more organization --- Dockerfile | 5 +- tests/archives.test.ts | 5 +- tests/data-manip.test.ts | 13 ++-- tests/dataloader-languages.test.ts | 113 ++++++++++++++++++++--------- tests/editing-tools.test.ts | 5 +- tests/general-cli.test.ts | 5 +- tests/images.test.ts | 5 +- tests/index.ts | 14 ++-- tests/networking.test.ts | 5 +- 9 files changed, 118 insertions(+), 52 deletions(-) diff --git a/Dockerfile b/Dockerfile index 9c2be74..c04b9f7 100644 --- a/Dockerfile +++ b/Dockerfile @@ -19,8 +19,9 @@ 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 \ + && corepack enable pnpm \ + && npm install --global svgo # == python ====================== FROM base AS python 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/dataloader-languages.test.ts b/tests/dataloader-languages.test.ts index d12d0b5..e1e8a08 100644 --- a/tests/dataloader-languages.test.ts +++ b/tests/dataloader-languages.test.ts @@ -1,41 +1,86 @@ -import { test } from "node:test"; -import { 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", - }, - { +import { test, describe } from "node:test"; +import assert from "node:assert/strict"; +import { + assertSemver, + binaryOnPathTest, + binaryVersionTest, + runCommandInContainer, +} from "./index.ts"; + +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", - }, - { + }); + + describe("Rust", () => { + binaryVersionTest({ + name: "Rust", + binary: "cargo", + semver: "^1.81", + extract: /^cargo ([\d.]+)/, + }); + + binaryVersionTest({ + binary: "rust-script", + semver: "^0.35", + prefix: "rust-script", + }); + }); + + binaryVersionTest({ binary: "perl", semver: "^5.36", extract: /^This is perl 5,[^(]* \(([^)]+)\)/, - }, -]; - -dataLoaderLanguages.forEach(binaryVersionTest); - -await test(`A Python virtual environment is activated`, async () => { - // should not throw - await runCommandInContainer(["pip", "install", "requests"]); + }); }); 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/index.ts b/tests/index.ts index 9173f79..8631845 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 }); }); } @@ -45,9 +47,9 @@ export function binaryOnPathTest({ }); } -function assertSemver( - actual, - expected, +export function assertSemver( + actual: string, + expected: string, { prefix, suffix, 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); +});