Skip to content

Commit 7db68aa

Browse files
Test each channel specific binaries through RUBY_NPM_PACKAGE_ROOT
1 parent ad66f8c commit 7db68aa

File tree

5 files changed

+29
-14
lines changed

5 files changed

+29
-14
lines changed

packages/npm-packages/ruby-3_2-wasm-wasi/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"README.md"
1212
],
1313
"scripts": {
14-
"test": "cd ../ruby-wasm-wasi && npm test",
14+
"test": "RUBY_NPM_PACKAGE_ROOT=../ruby-3_2-wasm-wasi npm -C ../ruby-wasm-wasi test",
1515
"build:deps": "cd ../ruby-wasm-wasi && npm run build",
1616
"build:static": "../ruby-wasm-wasi/tools/pack-static-files.sh ./dist",
1717
"build:rollup": "rollup -c rollup.config.mjs",

packages/npm-packages/ruby-head-wasm-wasi/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"README.md"
1212
],
1313
"scripts": {
14-
"test": "cd ../ruby-wasm-wasi && npm test",
14+
"test": "RUBY_NPM_PACKAGE_ROOT=../ruby-head-wasm-wasi npm -C ../ruby-wasm-wasi test",
1515
"build:deps": "cd ../ruby-wasm-wasi && npm run build",
1616
"build:static": "../ruby-wasm-wasi/tools/pack-static-files.sh ./dist",
1717
"build:rollup": "rollup -c rollup.config.mjs",

packages/npm-packages/ruby-wasm-wasi/test/init.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,13 @@ const rubyModule = (async () => {
77
let binaryPath;
88
if (process.env.RUBY_ROOT) {
99
binaryPath = path.join(process.env.RUBY_ROOT, "./usr/local/bin/ruby");
10+
} else if (process.env.RUBY_NPM_PACKAGE_ROOT) {
11+
binaryPath = path.join(
12+
process.env.RUBY_NPM_PACKAGE_ROOT,
13+
"./dist/ruby.debug+stdlib.wasm"
14+
);
1015
} else {
11-
binaryPath = path.join(__dirname, "./../dist/ruby.debug+stdlib.wasm");
16+
throw new Error("RUBY_ROOT or RUBY_NPM_PACKAGE_ROOT must be set");
1217
}
1318
const binary = await fs.readFile(binaryPath);
1419
return await WebAssembly.compile(binary.buffer);

packages/npm-packages/ruby-wasm-wasi/test/package.test.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,18 @@ const initRubyVM = async (rubyModule: WebAssembly.Module, args: string[]) => {
2929

3030
describe("Packaging validation", () => {
3131
jest.setTimeout(20 /*sec*/ * 1000);
32+
if (!process.env.RUBY_NPM_PACKAGE_ROOT) {
33+
return;
34+
}
3235

3336
const moduleCache = new Map<string, WebAssembly.Module>();
3437
const loadWasmModule = async (file: string) => {
3538
if (moduleCache.has(file)) {
3639
return moduleCache.get(file)!;
3740
}
38-
const binary = await fs.readFile(path.join(__dirname, `./../dist/${file}`));
41+
const binary = await fs.readFile(
42+
path.join(process.env.RUBY_NPM_PACKAGE_ROOT, `./dist/${file}`)
43+
);
3944
const mod = await WebAssembly.compile(binary.buffer);
4045
moduleCache.set(file, mod);
4146
return mod;

packages/npm-packages/ruby-wasm-wasi/tools/run-test-unit.mjs

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,24 @@ import path from "path";
77
import * as nodeWasi from "wasi";
88
import { RubyVM } from "../dist/index.cjs.js";
99

10-
const instantiateNodeWasi = async (rootTestFile) => {
11-
const dirname = path.dirname(new URL(import.meta.url).pathname);
10+
const deriveRubySetup = () => {
11+
let preopens = {}
1212
let binaryPath;
13-
let preopens = {
14-
__root__: path.join(dirname, ".."),
15-
};
1613
if (process.env.RUBY_ROOT) {
1714
binaryPath = path.join(process.env.RUBY_ROOT, "./usr/local/bin/ruby");
1815
preopens["/usr"] = path.join(process.env.RUBY_ROOT, "./usr");
16+
} else if (process.env.RUBY_NPM_PACKAGE_ROOT) {
17+
binaryPath = path.join(process.env.RUBY_NPM_PACKAGE_ROOT, "./dist/ruby.debug+stdlib.wasm");
1918
} else {
20-
binaryPath = path.join(dirname, "../dist/ruby.debug+stdlib.wasm");
19+
throw new Error("RUBY_ROOT or RUBY_NPM_PACKAGE_ROOT must be set");
2120
}
21+
return { binaryPath, preopens };
22+
}
23+
24+
const instantiateNodeWasi = async (rootTestFile) => {
25+
const dirname = path.dirname(new URL(import.meta.url).pathname);
26+
const { binaryPath, preopens } = deriveRubySetup();
27+
preopens["__root__"] = path.join(dirname, "..");
2228
const binary = await fs.readFile(binaryPath);
2329
const rubyModule = await WebAssembly.compile(binary);
2430
const wasi = new nodeWasi.WASI({
@@ -81,11 +87,10 @@ const instantiateWasmerWasi = async (rootTestFile) => {
8187

8288
const dirname = path.dirname(new URL(import.meta.url).pathname);
8389
await loadToMemFs('/__root__/test', path.join(dirname, '../test'));
84-
const preopens = {
85-
__root__: '/__root__',
86-
};
8790

88-
const binaryPath = path.join(dirname, "../dist/ruby+stdlib.wasm");
91+
const { binaryPath, preopens } = deriveRubySetup();
92+
preopens["__root__"] = '/__root__';
93+
8994
if (process.env.RUBY_ROOT) {
9095
console.error('For now, testing with RUBY_ROOT is not supported.');
9196
}

0 commit comments

Comments
 (0)