-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add general CLI utilities and expand tests (#2)
* Add general CLI utilities and expand tests * remove outdated todo * prefer forEach for test iteration Co-authored-by: Philippe Rivière <[email protected]> * check perl version --------- Co-authored-by: Philippe Rivière <[email protected]>
- Loading branch information
Showing
13 changed files
with
362 additions
and
102 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { spawn } from "node:child_process"; | ||
import { glob } from "glob"; | ||
import { IMAGE_TAG, StringStream } from "../tests/index.ts"; | ||
import { dirname } from "node:path"; | ||
import { run as runTests } from "node:test"; | ||
import { spec } from "node:test/reporters"; | ||
|
||
export async function buildTestImage() { | ||
console.log("building image..."); | ||
let stdio = new StringStream(); | ||
let process = spawn("docker", ["buildx", "build", "-t", IMAGE_TAG, ".."], { | ||
cwd: import.meta.dirname, | ||
stdio: "pipe", | ||
}); | ||
process.stdout.pipe(stdio); | ||
process.stderr.pipe(stdio); | ||
|
||
await new Promise((resolve, reject) => { | ||
process.on("close", (code) => { | ||
if (code !== 0) | ||
reject( | ||
new Error( | ||
`docker buildx build failed with code ${code}\n${stdio.string}` | ||
) | ||
); | ||
resolve(undefined); | ||
}); | ||
process.on("error", reject); | ||
}); | ||
} | ||
|
||
const files = await glob(["tests/**/*.test.ts"], { | ||
cwd: dirname(import.meta.dirname), | ||
}); | ||
|
||
await buildTestImage(); | ||
runTests({ files, concurrency: true }) | ||
.on("test:fail", () => { | ||
process.exitCode = 1; | ||
}) | ||
.compose(new spec()) | ||
.pipe(process.stdout); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,12 +6,14 @@ | |
"type": "module", | ||
"scripts": { | ||
"build": "docker build . -t observablehq/framework-runtime:latest", | ||
"test": "node --import tsx/esm --test ./test.ts" | ||
"test": "yarn tsx bin/test.ts" | ||
}, | ||
"packageManager": "[email protected]", | ||
"devDependencies": { | ||
"@types/dockerode": "^3.3.28", | ||
"@types/node": "^20", | ||
"dockerode": "^4.0.2", | ||
"glob": "^10.3.12", | ||
"semver": "^7.6.0", | ||
"tsx": "^4.7.1", | ||
"typescript": "^5.4.3" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { binaryOnPathTest } from "./index.ts"; | ||
|
||
const archiveTools = [ | ||
{ binary: "bzip2" }, | ||
{ binary: "gzip" }, | ||
{ binary: "tar" }, | ||
{ binary: "zip" }, | ||
{ binary: "zstd" }, | ||
]; | ||
|
||
archiveTools.forEach(binaryOnPathTest); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { binaryOnPathTest, binaryVersionTest } from "./index.ts"; | ||
|
||
const dataManipTools = [ | ||
{ binary: "jq" }, | ||
{ binary: "in2csv", name: "csvkit" }, | ||
{ binary: "csv2parquet" }, | ||
]; | ||
|
||
dataManipTools.forEach(binaryOnPathTest); | ||
|
||
binaryVersionTest({ | ||
binary: "duckdb", | ||
semver: "^0.10.1", | ||
extract: /^v(.*) [0-9a-f]*$/, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { binaryVersionTest } from "./index.ts"; | ||
|
||
const dataLoaderLanguages = [ | ||
{ binary: "node", semver: "^20" }, | ||
{ binary: "npm", semver: "^10.5" }, | ||
{ binary: "yarn", semver: "^1.22" }, | ||
{ | ||
binary: "python3", | ||
semver: "^3.11", | ||
prefix: "Python", | ||
}, | ||
{ | ||
binary: "Rscript", | ||
semver: "^4.3", | ||
extract: /^Rscript \(R\) version ([^\s]+)/, | ||
}, | ||
{ | ||
name: "Rust", | ||
binary: "cargo", | ||
semver: "^1.77", | ||
extract: /^cargo ([\d.]+)/, | ||
}, | ||
{ | ||
binary: "rust-script", | ||
semver: "^0.34", | ||
prefix: "rust-script", | ||
}, | ||
{ | ||
binary: "perl", | ||
semver: "^5.36", | ||
extract: /^This is perl 5,[^(]* \(([^)]+)\)/, | ||
}, | ||
]; | ||
|
||
dataLoaderLanguages.forEach(binaryVersionTest); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { binaryOnPathTest } from "./index.ts"; | ||
|
||
const generalCliTools: { binary: string }[] = [ | ||
{ binary: "md5sum" }, | ||
{ binary: "sha256sum" }, | ||
{ binary: "sha512sum" }, | ||
{ binary: "shasum" }, | ||
{ binary: "top" }, | ||
{ binary: "uptime" }, | ||
{ binary: "vmstat" }, | ||
]; | ||
|
||
generalCliTools.forEach(binaryOnPathTest); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { binaryOnPathTest } from "./index.ts"; | ||
|
||
const imageTools = [ | ||
{ binary: "svgo" }, | ||
{ binary: "optipng" }, | ||
{ binary: "convert", name: "imagemagick" }, | ||
]; | ||
|
||
imageTools.forEach(binaryOnPathTest); |
Oops, something went wrong.