node/test/wasi/test-wasi-not-started.js
Antoine du Hamel bd462ad81b
test: add lint rule to enforce trailing commas
Only activated on some subfolders to minimize the diff, ideally this
rule would be applied gradually to the entire codebase in follow-up
commits.

PR-URL: https://github.com/nodejs/node/pull/45468
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Jiawen Geng <technicalcute@gmail.com>
2022-11-17 13:02:11 +00:00

40 lines
1.1 KiB
JavaScript

'use strict';
require('../common');
if (process.argv[2] === 'wasi-child') {
const assert = require('assert');
const fs = require('fs');
const path = require('path');
const { WASI } = require('wasi');
const wasi = new WASI({
args: ['foo', '-bar', '--baz=value'],
});
const importObject = { wasi_snapshot_preview1: wasi.wasiImport };
const modulePath = path.join(__dirname, 'wasm', 'main_args.wasm');
const buffer = fs.readFileSync(modulePath);
assert.rejects(async () => {
const { instance } = await WebAssembly.instantiate(buffer, importObject);
instance.exports._start();
}, {
name: 'Error',
code: 'ERR_WASI_NOT_STARTED',
message: 'wasi.start() has not been called',
});
} else {
const assert = require('assert');
const cp = require('child_process');
const child = cp.spawnSync(process.execPath, [
'--experimental-wasi-unstable-preview1',
__filename,
'wasi-child',
], {
env: { ...process.env, NODE_DEBUG_NATIVE: 'wasi' },
});
assert.strictEqual(child.signal, null);
assert.strictEqual(child.status, 0);
}