Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Yarn v2+, pnpm, and some test organization #8

Merged
merged 3 commits into from
Sep 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion tests/archives.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { describe } from "node:test";
import { binaryOnPathTest } from "./index.ts";

const archiveTools = [
Expand All @@ -8,4 +9,6 @@ const archiveTools = [
{ binary: "zstd" },
];

archiveTools.forEach(binaryOnPathTest);
await describe("Archive tools", () => {
archiveTools.forEach(binaryOnPathTest);
});
13 changes: 8 additions & 5 deletions tests/data-manip.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { describe } from "node:test";
import { binaryOnPathTest, binaryVersionTest } from "./index.ts";

const dataManipTools = [
Expand All @@ -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]*$/,
});
});
113 changes: 79 additions & 34 deletions tests/dataloader-languages.test.ts
Original file line number Diff line number Diff line change
@@ -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"]);
});
});
5 changes: 4 additions & 1 deletion tests/editing-tools.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { describe } from "node:test";
import { binaryOnPathTest } from "./index.ts";

const textManipTools: { binary: string }[] = [
Expand All @@ -13,4 +14,6 @@ const textManipTools: { binary: string }[] = [
{ binary: "vim" },
];

textManipTools.forEach(binaryOnPathTest);
describe("editing tools", () => {
textManipTools.forEach(binaryOnPathTest);
});
5 changes: 4 additions & 1 deletion tests/general-cli.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { describe } from "node:test";
import { binaryOnPathTest } from "./index.ts";

const generalCliTools: { binary: string }[] = [
Expand All @@ -10,4 +11,6 @@ const generalCliTools: { binary: string }[] = [
{ binary: "vmstat" },
];

generalCliTools.forEach(binaryOnPathTest);
describe("General CLI tools", () => {
generalCliTools.forEach(binaryOnPathTest);
});
5 changes: 4 additions & 1 deletion tests/images.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { describe } from "node:test";
import { binaryOnPathTest } from "./index.ts";

const imageTools = [
Expand All @@ -6,4 +7,6 @@ const imageTools = [
{ binary: "convert", name: "imagemagick" },
];

imageTools.forEach(binaryOnPathTest);
describe("Image tools", () => {
imageTools.forEach(binaryOnPathTest);
});
14 changes: 8 additions & 6 deletions tests/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
});
}
Expand All @@ -45,9 +47,9 @@ export function binaryOnPathTest({
});
}

function assertSemver(
actual,
expected,
export function assertSemver(
actual: string,
expected: string,
{
prefix,
suffix,
Expand Down
5 changes: 4 additions & 1 deletion tests/networking.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { describe } from "node:test";
import { binaryOnPathTest } from "./index.ts";

const networkingTools = [
Expand All @@ -10,4 +11,6 @@ const networkingTools = [
{ binary: "wget" },
];

networkingTools.forEach(binaryOnPathTest);
describe("Networking tools", () => {
networkingTools.forEach(binaryOnPathTest);
});