Skip to content

Commit

Permalink
Stop using javy-cli in javy tests (#725)
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffcharles committed Aug 14, 2024
1 parent 0a5972a commit 6fa604d
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 187 deletions.
177 changes: 0 additions & 177 deletions npm/javy/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion npm/javy/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
},
"devDependencies": {
"@rollup/plugin-node-resolve": "^15.0.1",
"javy-cli": "^0.2.0",
"rollup": "^4.1.4",
"rollup-plugin-swc": "^0.2.1",
"typescript": "^5.2.2",
Expand Down
49 changes: 40 additions & 9 deletions npm/javy/tests/runner.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { spawn } from "node:child_process";
import fs from "node:fs";
import path from "node:path";
import * as stream from "node:stream";
import { tmpdir } from "node:os";
import { join } from "node:path";
Expand All @@ -9,17 +11,22 @@ import {
TextEncoderStream,
} from "node:stream/web";
import { unlink } from "node:fs/promises";
import * as gzip from "node:zlib";

import { rollup } from "rollup";
import swc from "rollup-plugin-swc";
import nodeResolve from "@rollup/plugin-node-resolve";

import * as tests from "./tests.js";

const JAVY_VERSION = "v3.0.1";

const javyPath = path.join(tmpdir(), "javy");

async function main() {
console.log("Running tests...");

await forceJavyDownload(); // trying to download Javy in parallel causes problems with the tests
await downloadJavy(JAVY_VERSION);

const resultPromises = Object.entries(tests).map(
async ([testName, testFunc]) => {
Expand All @@ -41,13 +48,6 @@ async function main() {
}
await main();

async function forceJavyDownload() {
let { exitCode, stderr } = await runCommand("javy", ["--version"]);
if (await exitCode !== 0) {
throw Error(await collectStream(stderr));
}
}

/**
* Passes the stream's controller to a callback where strings can be enqueue.
* @param {(ctr: ReadableStreamDefaultController<string>) => Promise<void>} f
Expand Down Expand Up @@ -123,7 +123,7 @@ export async function runJS({ source, stdin, expectedOutput }) {
}

async function compileWithJavy(infile, outfile) {
const { exitCode, stdout, stderr } = await runCommand("javy", [
const { exitCode, stdout, stderr } = await runCommand(javyPath, [
"compile",
"-o",
outfile,
Expand Down Expand Up @@ -173,3 +173,34 @@ function emptyStream() {
},
});
}

async function downloadJavy(version) {
let platformArch;
if (process.platform === "linux" && (process.arch === "arm" || process.arch === "arm64")) {
platformArch = "arm-linux";
} else if (process.platform === "linux" && process.arch === "x64") {
platformArch = "x86_64-linux";
} else if (process.platform === "darwin" && (process.arch === "arm" || process.arch === "arm64")) {
platformArch = "arm-macos";
} else if (process.platform === "darwin" && process.arch === "x64") {
platformArch = "x86_64-macos";
} else if (process.platform === "win32" && (process.arch === "x64" || process.arch === "ia32")) {
platformArch = "x86_64-windows";
} else {
throw new Error(`Platform and architecture unsupported: ${process.platform}/${process.arch}`);
}
const url = `https://github.com/bytecodealliance/javy/releases/download/${version}/javy-${platformArch}-${version}.gz`;
const response = await fetch(url);
if (!response.ok) {
throw new Error(`Error downloading Javy from ${url}: ${response.status}: ${response.statusText}`);
}
const gunzip = gzip.createGunzip();
const output = fs.createWriteStream(javyPath);
await new Promise((resolve, reject) => {
stream.pipeline(response.body, gunzip, output, (err, val) => {
if (err) return reject(err);
return resolve(val);
});
});
await fs.promises.chmod(javyPath, 0o775);
}

0 comments on commit 6fa604d

Please sign in to comment.