Skip to content

Commit 695a8a1

Browse files
authored
Yarn v2+, pnpm, and some test organization (#8)
* some organization of tests * support yarn v2+ * pnpm and some more organization
1 parent aea7fcd commit 695a8a1

9 files changed

+118
-52
lines changed

Dockerfile

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,9 @@ EOF
1919
RUN --mount=type=cache,target=/var/cache/apt,id=framework-runtime-node \
2020
apt update \
2121
&& apt install -y --no-install-recommends nodejs \
22-
&& npm install --global yarn
23-
RUN npm install --global svgo
22+
&& corepack enable \
23+
&& corepack enable pnpm \
24+
&& npm install --global svgo
2425

2526
# == python ======================
2627
FROM base AS python

tests/archives.test.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { describe } from "node:test";
12
import { binaryOnPathTest } from "./index.ts";
23

34
const archiveTools = [
@@ -8,4 +9,6 @@ const archiveTools = [
89
{ binary: "zstd" },
910
];
1011

11-
archiveTools.forEach(binaryOnPathTest);
12+
await describe("Archive tools", () => {
13+
archiveTools.forEach(binaryOnPathTest);
14+
});

tests/data-manip.test.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { describe } from "node:test";
12
import { binaryOnPathTest, binaryVersionTest } from "./index.ts";
23

34
const dataManipTools = [
@@ -6,10 +7,12 @@ const dataManipTools = [
67
{ binary: "csv2parquet" },
78
];
89

9-
dataManipTools.forEach(binaryOnPathTest);
10+
describe("Data manipulation tools", () => {
11+
dataManipTools.forEach(binaryOnPathTest);
1012

11-
binaryVersionTest({
12-
binary: "duckdb",
13-
semver: "^1",
14-
extract: /^v(.*) [0-9a-f]*$/,
13+
binaryVersionTest({
14+
binary: "duckdb",
15+
semver: "^1",
16+
extract: /^v(.*) [0-9a-f]*$/,
17+
});
1518
});

tests/dataloader-languages.test.ts

Lines changed: 79 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,86 @@
1-
import { test } from "node:test";
2-
import { binaryVersionTest, runCommandInContainer } from "./index.ts";
3-
4-
const dataLoaderLanguages = [
5-
{ binary: "node", semver: "^20.17" },
6-
{ binary: "npm", semver: "^10.5" },
7-
{ binary: "yarn", semver: "^1.22" },
8-
{
9-
binary: "python3",
10-
semver: "^3.11",
11-
prefix: "Python",
12-
},
13-
{
1+
import { test, describe } from "node:test";
2+
import assert from "node:assert/strict";
3+
import {
4+
assertSemver,
5+
binaryOnPathTest,
6+
binaryVersionTest,
7+
runCommandInContainer,
8+
} from "./index.ts";
9+
10+
describe("Dataloader languages", () => {
11+
describe("Python", () => {
12+
binaryVersionTest({
13+
binary: "python3",
14+
semver: "^3.11",
15+
prefix: "Python",
16+
});
17+
18+
binaryOnPathTest({ binary: "pip" });
19+
20+
test(`A Python virtual environment is activated`, async () => {
21+
// should not throw
22+
await runCommandInContainer(["pip", "install", "requests"]);
23+
});
24+
});
25+
26+
describe("JavaScript", () => {
27+
binaryVersionTest({ binary: "node", semver: "^20.17" });
28+
binaryVersionTest({ binary: "npm", semver: "^10.5" });
29+
30+
binaryVersionTest({
31+
binary: "yarn",
32+
semver: "^1.22",
33+
expectStderr: /^! Corepack is about to download.*yarn/,
34+
});
35+
test("Yarn v2+ is available, and uses corepack", async () => {
36+
const { stdout, stderr } = await runCommandInContainer([
37+
"sh",
38+
"-c",
39+
"mkdir test && cd test && yarn init -2",
40+
]);
41+
assert.ok(!stdout.includes("You don't seem to have Corepack enabled"));
42+
assert.ok(!stderr.includes("You don't seem to have Corepack enabled"));
43+
});
44+
test("yarn ^4.4.1 is available via corepack", async () => {
45+
const { stdout, stderr } = await runCommandInContainer([
46+
"sh",
47+
"-c",
48+
"mkdir test && cd test && yarn init -2 > /dev/null && yarn --version",
49+
]);
50+
assertSemver(stdout, "^4.4.1");
51+
});
52+
53+
binaryVersionTest({
54+
binary: "pnpm",
55+
semver: "^9.10",
56+
expectStderr: /^! Corepack is about to download.*pnpm/,
57+
});
58+
});
59+
60+
binaryVersionTest({
1461
binary: "Rscript",
1562
semver: "^4.4.1",
1663
extract: /^Rscript \(R\) version ([^\s]+)/,
17-
},
18-
{
19-
name: "Rust",
20-
binary: "cargo",
21-
semver: "^1.81",
22-
extract: /^cargo ([\d.]+)/,
23-
},
24-
{
25-
binary: "rust-script",
26-
semver: "^0.35",
27-
prefix: "rust-script",
28-
},
29-
{
64+
});
65+
66+
describe("Rust", () => {
67+
binaryVersionTest({
68+
name: "Rust",
69+
binary: "cargo",
70+
semver: "^1.81",
71+
extract: /^cargo ([\d.]+)/,
72+
});
73+
74+
binaryVersionTest({
75+
binary: "rust-script",
76+
semver: "^0.35",
77+
prefix: "rust-script",
78+
});
79+
});
80+
81+
binaryVersionTest({
3082
binary: "perl",
3183
semver: "^5.36",
3284
extract: /^This is perl 5,[^(]* \(([^)]+)\)/,
33-
},
34-
];
35-
36-
dataLoaderLanguages.forEach(binaryVersionTest);
37-
38-
await test(`A Python virtual environment is activated`, async () => {
39-
// should not throw
40-
await runCommandInContainer(["pip", "install", "requests"]);
85+
});
4186
});

tests/editing-tools.test.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { describe } from "node:test";
12
import { binaryOnPathTest } from "./index.ts";
23

34
const textManipTools: { binary: string }[] = [
@@ -13,4 +14,6 @@ const textManipTools: { binary: string }[] = [
1314
{ binary: "vim" },
1415
];
1516

16-
textManipTools.forEach(binaryOnPathTest);
17+
describe("editing tools", () => {
18+
textManipTools.forEach(binaryOnPathTest);
19+
});

tests/general-cli.test.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { describe } from "node:test";
12
import { binaryOnPathTest } from "./index.ts";
23

34
const generalCliTools: { binary: string }[] = [
@@ -10,4 +11,6 @@ const generalCliTools: { binary: string }[] = [
1011
{ binary: "vmstat" },
1112
];
1213

13-
generalCliTools.forEach(binaryOnPathTest);
14+
describe("General CLI tools", () => {
15+
generalCliTools.forEach(binaryOnPathTest);
16+
});

tests/images.test.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { describe } from "node:test";
12
import { binaryOnPathTest } from "./index.ts";
23

34
const imageTools = [
@@ -6,4 +7,6 @@ const imageTools = [
67
{ binary: "convert", name: "imagemagick" },
78
];
89

9-
imageTools.forEach(binaryOnPathTest);
10+
describe("Image tools", () => {
11+
imageTools.forEach(binaryOnPathTest);
12+
});

tests/index.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,20 @@ export interface AssertBinaryVersionOptions {
1313
semver: string;
1414
extract?: RegExp;
1515
prefix?: string;
16+
expectStderr?: RegExp;
1617
}
1718

18-
export function binaryVersionTest({
19+
export async function binaryVersionTest({
1920
binary,
2021
name = binary,
2122
semver,
2223
extract,
2324
prefix,
25+
expectStderr = /^$/,
2426
}: AssertBinaryVersionOptions) {
25-
test(`${name} ${semver} is available`, async () => {
27+
await test(`${name} ${semver} is available`, async () => {
2628
const res = await runCommandInContainer([binary, "--version"]);
27-
assert.equal(res.stderr, "");
29+
assert.ok(res.stderr.match(expectStderr), `Expected stderr to match, got: ${res.stderr}`);
2830
assertSemver(res.stdout, semver, { extract, prefix });
2931
});
3032
}
@@ -45,9 +47,9 @@ export function binaryOnPathTest({
4547
});
4648
}
4749

48-
function assertSemver(
49-
actual,
50-
expected,
50+
export function assertSemver(
51+
actual: string,
52+
expected: string,
5153
{
5254
prefix,
5355
suffix,

tests/networking.test.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { describe } from "node:test";
12
import { binaryOnPathTest } from "./index.ts";
23

34
const networkingTools = [
@@ -10,4 +11,6 @@ const networkingTools = [
1011
{ binary: "wget" },
1112
];
1213

13-
networkingTools.forEach(binaryOnPathTest);
14+
describe("Networking tools", () => {
15+
networkingTools.forEach(binaryOnPathTest);
16+
});

0 commit comments

Comments
 (0)