Skip to content

Commit 60f064c

Browse files
chore(tests): add test for downloading weval
Signed-off-by: Victor Adossi <[email protected]>
1 parent 4c3059f commit 60f064c

File tree

5 files changed

+42
-2
lines changed

5 files changed

+42
-2
lines changed

.github/workflows/ci.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,3 +51,15 @@ jobs:
5151
run: make -C tests/simple run-base
5252
- name: Build and run wevaled 'simple' test
5353
run: make -C tests/simple run-wevaled
54+
55+
test-js:
56+
runs-on: ubuntu-latest
57+
steps:
58+
- uses: actions/checkout@v4
59+
- uses: actions/setup-node@v4
60+
with:
61+
node-version: latest
62+
- run: npm install
63+
working-directory: npm/weval
64+
- run: npm test
65+
working-directory: npm/weval

npm/weval/index.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,14 @@ const __dirname = dirname(fileURLToPath(import.meta.url));
1414

1515
const TAG = "v0.3.2";
1616

17-
async function getWeval() {
17+
/**
18+
* Download Weval from GitHub releases
19+
*
20+
* @param {object} [opts]
21+
* @param {string} [opts.downloadDir] - Directory to which the binary should be downloaded
22+
* @returns {string} path to the downloaded binary on disk
23+
*/
24+
export async function getWeval(opts) {
1825
const knownPlatforms = {
1926
"win32 x64 LE": "x86_64-windows",
2027
"darwin arm64 LE": "aarch64-macos",
@@ -38,7 +45,7 @@ async function getWeval() {
3845
const assetSuffix = platform == "win32" ? "zip" : "tar.xz";
3946
const exeSuffix = platform == "win32" ? ".exe" : "";
4047

41-
const exeDir = join(__dirname, platformName);
48+
const exeDir = join(opts && opts.downloadDir ? opts.downloadDir : __dirname, platformName);
4249
const exe = join(exeDir, `weval${exeSuffix}`);
4350

4451
// If we already have the executable installed, then return it

npm/weval/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"description": "The WebAssembly partial evaluator",
55
"type": "module",
66
"scripts": {
7+
"test": "node ./tests/index.mjs",
78
"version": "node ./update.js $npm_package_version"
89
},
910
"dependencies": {

npm/weval/tests/download.mjs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import assert from "node:assert";
2+
import { test } from "node:test";
3+
import { tmpdir } from "node:os";
4+
import { join } from "node:path";
5+
import { mkdtemp, access } from 'node:fs/promises';
6+
7+
import { getWeval } from "../index.js";
8+
9+
export default async function tests() {
10+
test("downloading works", async () => {
11+
const downloadDir = await mkdtemp(join(tmpdir(), "weval-dl-"));
12+
const wevalPath = await getWeval({ downloadDir });
13+
assert(wevalPath);
14+
await access(wevalPath);
15+
console.log(`weval path: ${wevalPath}`);
16+
});
17+
}

npm/weval/tests/index.mjs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import { default as downloadTests } from "./download.mjs";
2+
3+
await downloadTests();

0 commit comments

Comments
 (0)