diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index aa8b818..91029a4 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -51,3 +51,15 @@ jobs: run: make -C tests/simple run-base - name: Build and run wevaled 'simple' test run: make -C tests/simple run-wevaled + + test-js: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-node@v4 + with: + node-version: latest + - run: npm install + working-directory: npm/weval + - run: npm test + working-directory: npm/weval diff --git a/npm/weval/index.js b/npm/weval/index.js index 66f4bee..aff6873 100644 --- a/npm/weval/index.js +++ b/npm/weval/index.js @@ -14,7 +14,14 @@ const __dirname = dirname(fileURLToPath(import.meta.url)); const TAG = "v0.3.2"; -async function getWeval() { +/** + * Download Weval from GitHub releases + * + * @param {object} [opts] + * @param {string} [opts.downloadDir] - Directory to which the binary should be downloaded + * @returns {string} path to the downloaded binary on disk + */ +export async function getWeval(opts) { const knownPlatforms = { "win32 x64 LE": "x86_64-windows", "darwin arm64 LE": "aarch64-macos", @@ -38,7 +45,7 @@ async function getWeval() { const assetSuffix = platform == "win32" ? "zip" : "tar.xz"; const exeSuffix = platform == "win32" ? ".exe" : ""; - const exeDir = join(__dirname, platformName); + const exeDir = join(opts && opts.downloadDir ? opts.downloadDir : __dirname, platformName); const exe = join(exeDir, `weval${exeSuffix}`); // If we already have the executable installed, then return it diff --git a/npm/weval/package.json b/npm/weval/package.json index 52f73ea..7199ba9 100644 --- a/npm/weval/package.json +++ b/npm/weval/package.json @@ -4,6 +4,7 @@ "description": "The WebAssembly partial evaluator", "type": "module", "scripts": { + "test": "node ./tests/index.mjs", "version": "node ./update.js $npm_package_version" }, "dependencies": { diff --git a/npm/weval/tests/download.mjs b/npm/weval/tests/download.mjs new file mode 100644 index 0000000..e5f142c --- /dev/null +++ b/npm/weval/tests/download.mjs @@ -0,0 +1,17 @@ +import assert from "node:assert"; +import { test } from "node:test"; +import { tmpdir } from "node:os"; +import { join } from "node:path"; +import { mkdtemp, access } from 'node:fs/promises'; + +import { getWeval } from "../index.js"; + +export default async function tests() { + test("downloading works", async () => { + const downloadDir = await mkdtemp(join(tmpdir(), "weval-dl-")); + const wevalPath = await getWeval({ downloadDir }); + assert(wevalPath); + await access(wevalPath); + console.log(`weval path: ${wevalPath}`); + }); +} diff --git a/npm/weval/tests/index.mjs b/npm/weval/tests/index.mjs new file mode 100644 index 0000000..fc6542d --- /dev/null +++ b/npm/weval/tests/index.mjs @@ -0,0 +1,3 @@ +import { default as downloadTests } from "./download.mjs"; + +await downloadTests();