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>
This commit is contained in:
Antoine du Hamel 2022-11-17 08:02:11 -05:00 committed by GitHub
parent 6638f09fe1
commit bd462ad81b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
22 changed files with 130 additions and 102 deletions

View File

@ -8,6 +8,7 @@ rules:
multiline-comment-style: [error, separate-lines] multiline-comment-style: [error, separate-lines]
prefer-const: error prefer-const: error
symbol-description: off symbol-description: off
comma-dangle: [error, always-multiline]
no-restricted-syntax: no-restricted-syntax:
# Config copied from .eslintrc.js # Config copied from .eslintrc.js
@ -68,3 +69,30 @@ rules:
# Global scoped methods and vars # Global scoped methods and vars
globals: globals:
WebAssembly: false WebAssembly: false
overrides:
- files:
- addons/*/*.js
- async-hooks/*.js
- common/*.js
- es-module/*.js
- es-module/*.mjs
- internet/*.js
- js-native-api/*/*.js
- known_issues/*.js
- message/*.js
- node-api/*/*.js
- parallel/*.js
- parallel/*.mjs
- pseudo-tty/*.js
- pummel/*.js
- sequential/*.js
- sequential/*.mjs
rules:
comma-dangle: [error, {
arrays: always-multiline,
exports: only-multiline,
functions: only-multiline,
imports: only-multiline,
objects: only-multiline,
}]

View File

@ -110,20 +110,20 @@ expectWarning('DeprecationWarning', [
expectWarning('DeprecationWarning', { expectWarning('DeprecationWarning', {
DEP0XXX: 'Foobar is deprecated', DEP0XXX: 'Foobar is deprecated',
DEP0XX2: 'Baz is also deprecated' DEP0XX2: 'Baz is also deprecated',
}); });
expectWarning({ expectWarning({
DeprecationWarning: { DeprecationWarning: {
DEP0XXX: 'Foobar is deprecated', DEP0XXX: 'Foobar is deprecated',
DEP0XX1: 'Baz is also deprecated' DEP0XX1: 'Baz is also deprecated',
}, },
Warning: [ Warning: [
['Multiple array entries are fine', 'SpecialWarningCode'], ['Multiple array entries are fine', 'SpecialWarningCode'],
['No code is also fine'], ['No code is also fine'],
], ],
SingleEntry: ['This will also work', 'WarningCode'], SingleEntry: ['This will also work', 'WarningCode'],
SingleString: 'Single string entries without code will also work' SingleString: 'Single string entries without code will also work',
}); });
``` ```
@ -720,7 +720,7 @@ validateSnapshotNodes('TLSWRAP', [
{ name: 'enc_out' }, { name: 'enc_out' },
{ name: 'enc_in' }, { name: 'enc_in' },
{ name: 'TLSWrap' }, { name: 'TLSWrap' },
] ],
}, },
]); ]);
``` ```

View File

@ -9,7 +9,7 @@ const resource = new ResourceLoader(workerData.wptPath);
global.self = global; global.self = global;
global.GLOBAL = { global.GLOBAL = {
isWindow() { return false; }, isWindow() { return false; },
isShadowRealm() { return false; } isShadowRealm() { return false; },
}; };
global.require = require; global.require = require;
@ -25,7 +25,7 @@ if (workerData.initScript) {
} }
runInThisContext(workerData.harness.code, { runInThisContext(workerData.harness.code, {
filename: workerData.harness.filename filename: workerData.harness.filename,
}); });
// eslint-disable-next-line no-undef // eslint-disable-next-line no-undef

View File

@ -23,7 +23,7 @@ fs.readdirSync(apilinks).forEach((fixture) => {
execFileSync( execFileSync(
process.execPath, process.execPath,
[script, outputPath, input], [script, outputPath, input],
{ encoding: 'utf-8' } { encoding: 'utf-8' },
); );
const expectedLinks = JSON.parse(expectedContent); const expectedLinks = JSON.parse(expectedContent);
@ -38,6 +38,6 @@ fs.readdirSync(apilinks).forEach((fixture) => {
assert.strictEqual( assert.strictEqual(
Object.keys(actualLinks).length, 0, Object.keys(actualLinks).length, 0,
`unexpected links returned ${JSON.stringify(actualLinks)}` `unexpected links returned ${JSON.stringify(actualLinks)}`,
); );
}); });

View File

@ -10,7 +10,7 @@ const script = path.join(
'..', '..',
'tools', 'tools',
'doc', 'doc',
'deprecationCodes.mjs' 'deprecationCodes.mjs',
); );
const mdPath = path.join( const mdPath = path.join(
@ -19,7 +19,7 @@ const mdPath = path.join(
'..', '..',
'doc', 'doc',
'api', 'api',
'deprecations.md' 'deprecations.md',
); );
const cp = spawn(process.execPath, [script, mdPath], { encoding: 'utf-8', stdio: 'inherit' }); const cp = spawn(process.execPath, [script, mdPath], { encoding: 'utf-8', stdio: 'inherit' });

View File

@ -23,8 +23,8 @@ import {
const testLinksMapper = { const testLinksMapper = {
'foo': { 'foo': {
'command line options': 'cli.html#cli-options', 'command line options': 'cli.html#cli-options',
'web server': 'example.html' 'web server': 'example.html',
} },
}; };
function toHTML({ input, filename, nodeVersion, versions }) { function toHTML({ input, filename, nodeVersion, versions }) {
@ -58,7 +58,7 @@ const testData = [
'id="foo_static_method_buffer_from_array"></a></h4>' + 'id="foo_static_method_buffer_from_array"></a></h4>' +
'<ul><li><code>array</code><a ' + '<ul><li><code>array</code><a ' +
'href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/' + 'href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/' +
'Reference/Global_Objects/Array" class="type">&#x3C;Array></a></li></ul>' 'Reference/Global_Objects/Array" class="type">&#x3C;Array></a></li></ul>',
}, },
{ {
file: fixtures.path('doc_with_yaml.md'), file: fixtures.path('doc_with_yaml.md'),
@ -99,7 +99,7 @@ const testData = [
'" id="something">#</a></span>' + '" id="something">#</a></span>' +
'<a aria-hidden="true" class="legacy" id="foo_something"></a></h3>' + '<a aria-hidden="true" class="legacy" id="foo_something"></a></h3>' +
'<!-- This is not a metadata comment --> ' + '<!-- This is not a metadata comment --> ' +
'<p>Describe <code>Something</code> in more detail here. </p></section>' '<p>Describe <code>Something</code> in more detail here. </p></section>',
}, },
{ {
file: fixtures.path('sample_document.md'), file: fixtures.path('sample_document.md'),
@ -129,7 +129,7 @@ const testData = [
'<h3>See also<span><a class="mark"' + '<h3>See also<span><a class="mark"' +
'href="#see-also" id="see-also">#</a></span><a aria-hidden="true"' + 'href="#see-also" id="see-also">#</a></span><a aria-hidden="true"' +
'class="legacy" id="foo_see_also"></a></h3><p>Check' + 'class="legacy" id="foo_see_also"></a></h3><p>Check' +
'out also<a href="https://nodejs.org/">this guide</a></p></section>' 'out also<a href="https://nodejs.org/">this guide</a></p></section>',
}, },
{ {
file: fixtures.path('document_with_special_heading.md'), file: fixtures.path('document_with_special_heading.md'),

View File

@ -41,12 +41,12 @@ const testData = [
desc: '<ol>\n<li>fish</li>\n<li>fish</li>\n</ol>\n' + desc: '<ol>\n<li>fish</li>\n<li>fish</li>\n</ol>\n' +
'<ul>\n<li>Red fish</li>\n<li>Blue fish</li>\n</ul>', '<ul>\n<li>Red fish</li>\n<li>Blue fish</li>\n</ul>',
type: 'module', type: 'module',
displayName: 'Seussian Rhymes' displayName: 'Seussian Rhymes',
}], }],
type: 'module', type: 'module',
displayName: 'Sample Markdown' displayName: 'Sample Markdown',
}] }],
} },
}, },
{ {
file: fixtures.path('order_of_end_tags_5873.md'), file: fixtures.path('order_of_end_tags_5873.md'),
@ -68,18 +68,18 @@ const testData = [
params: [{ params: [{
textRaw: '`array` {Array}', textRaw: '`array` {Array}',
name: 'array', name: 'array',
type: 'Array' type: 'Array',
}] }],
}, },
] ],
}], }],
type: 'module', type: 'module',
displayName: 'Subsection' displayName: 'Subsection',
}], }],
type: 'module', type: 'module',
displayName: 'Title' displayName: 'Title',
}] }],
} },
}, },
{ {
file: fixtures.path('doc_with_yaml.md'), file: fixtures.path('doc_with_yaml.md'),
@ -96,12 +96,12 @@ const testData = [
name: 'foobar', name: 'foobar',
meta: { meta: {
added: ['v1.0.0'], added: ['v1.0.0'],
changes: [] changes: [],
}, },
desc: '<p>Describe <code>Foobar</code> in more detail ' + desc: '<p>Describe <code>Foobar</code> in more detail ' +
'here.</p>', 'here.</p>',
type: 'module', type: 'module',
displayName: 'Foobar' displayName: 'Foobar',
}, },
{ {
textRaw: 'Foobar II', textRaw: 'Foobar II',
@ -113,12 +113,12 @@ const testData = [
'pr-url': 'https://github.com/nodejs/node/pull/3276', 'pr-url': 'https://github.com/nodejs/node/pull/3276',
'description': 'The `error` parameter can now be ' + 'description': 'The `error` parameter can now be ' +
'an arrow function.' }, 'an arrow function.' },
] ],
}, },
desc: '<p>Describe <code>Foobar II</code> in more detail ' + desc: '<p>Describe <code>Foobar II</code> in more detail ' +
'here. fg(1)</p>', 'here. fg(1)</p>',
type: 'module', type: 'module',
displayName: 'Foobar II' displayName: 'Foobar II',
}, },
{ {
textRaw: 'Deprecated thingy', textRaw: 'Deprecated thingy',
@ -126,12 +126,12 @@ const testData = [
meta: { meta: {
added: ['v1.0.0'], added: ['v1.0.0'],
deprecated: ['v2.0.0'], deprecated: ['v2.0.0'],
changes: [] changes: [],
}, },
desc: '<p>Describe <code>Deprecated thingy</code> in more ' + desc: '<p>Describe <code>Deprecated thingy</code> in more ' +
'detail here. fg(1p)</p>', 'detail here. fg(1p)</p>',
type: 'module', type: 'module',
displayName: 'Deprecated thingy' displayName: 'Deprecated thingy',
}, },
{ {
textRaw: 'Something', textRaw: 'Something',
@ -139,14 +139,14 @@ const testData = [
desc: '<!-- This is not a metadata comment -->\n<p>' + desc: '<!-- This is not a metadata comment -->\n<p>' +
'Describe <code>Something</code> in more detail here.</p>', 'Describe <code>Something</code> in more detail here.</p>',
type: 'module', type: 'module',
displayName: 'Something' displayName: 'Something',
}, },
], ],
type: 'module', type: 'module',
displayName: 'Sample Markdown with YAML info' displayName: 'Sample Markdown with YAML info',
}, },
] ],
} },
}, },
{ {
file: fixtures.path('doc_with_backticks_in_headings.md'), file: fixtures.path('doc_with_backticks_in_headings.md'),
@ -160,7 +160,7 @@ const testData = [
properties: [ properties: [
{ {
name: 'fullName', name: 'fullName',
textRaw: '`Fqhqwhgads.fullName`' textRaw: '`Fqhqwhgads.fullName`',
}, },
], ],
classMethods: [ classMethods: [
@ -168,18 +168,18 @@ const testData = [
name: 'again', name: 'again',
signatures: [ signatures: [
{ {
params: [] params: [],
}, },
], ],
textRaw: 'Static method: `Fhqwhgads.again()`', textRaw: 'Static method: `Fhqwhgads.again()`',
type: 'classMethod' type: 'classMethod',
}, },
], ],
classes: [ classes: [
{ {
textRaw: 'Class: `ComeOn`', textRaw: 'Class: `ComeOn`',
type: 'class', type: 'class',
name: 'ComeOn' name: 'ComeOn',
}, },
], ],
ctors: [ ctors: [
@ -187,11 +187,11 @@ const testData = [
name: 'Fhqwhgads', name: 'Fhqwhgads',
signatures: [ signatures: [
{ {
params: [] params: [],
}, },
], ],
textRaw: 'Constructor: `new Fhqwhgads()`', textRaw: 'Constructor: `new Fhqwhgads()`',
type: 'ctor' type: 'ctor',
}, },
], ],
methods: [ methods: [
@ -199,7 +199,7 @@ const testData = [
textRaw: '`everybody.to(limit)`', textRaw: '`everybody.to(limit)`',
type: 'method', type: 'method',
name: 'to', name: 'to',
signatures: [{ params: [] }] signatures: [{ params: [] }],
}, },
], ],
events: [ events: [
@ -207,14 +207,14 @@ const testData = [
textRaw: "Event: `'FHQWHfest'`", textRaw: "Event: `'FHQWHfest'`",
type: 'event', type: 'event',
name: 'FHQWHfest', name: 'FHQWHfest',
params: [] params: [],
}, },
], ],
type: 'module', type: 'module',
displayName: 'Fhqwhgads' displayName: 'Fhqwhgads',
}, },
] ],
} },
}, },
]; ];

View File

@ -21,7 +21,7 @@ const actualDocs = allDocs.filter(
(name) => { (name) => {
const extension = path.extname(name); const extension = path.extname(name);
return extension === '.html' || extension === '.json'; return extension === '.html' || extension === '.json';
} },
); );
for (const name of actualDocs) { for (const name of actualDocs) {
@ -29,7 +29,7 @@ for (const name of actualDocs) {
assert.ok( assert.ok(
allMD.includes(name.replace(/\.\w+$/, '.md')), allMD.includes(name.replace(/\.\w+$/, '.md')),
`Unexpected output: out/doc/api/${name}, remove and rerun.` `Unexpected output: out/doc/api/${name}, remove and rerun.`,
); );
} }
@ -66,6 +66,6 @@ for (const actualDoc of actualDocs) {
assert.notStrictEqual( assert.notStrictEqual(
fs.statSync(new URL(`./${actualDoc}`, apiURL)).size, fs.statSync(new URL(`./${actualDoc}`, apiURL)).size,
0, 0,
`${actualDoc} is empty` `${actualDoc} is empty`,
); );
} }

View File

@ -76,13 +76,13 @@ if (!common.isWindows) {
process.report.signal = 'foo'; process.report.signal = 'foo';
}, { }, {
code: 'ERR_UNKNOWN_SIGNAL', code: 'ERR_UNKNOWN_SIGNAL',
message: 'Unknown signal: foo' message: 'Unknown signal: foo',
}); });
assert.throws(() => { assert.throws(() => {
process.report.signal = 'sigusr1'; process.report.signal = 'sigusr1';
}, { }, {
code: 'ERR_UNKNOWN_SIGNAL', code: 'ERR_UNKNOWN_SIGNAL',
message: 'Unknown signal: sigusr1 (signals must use all capital letters)' message: 'Unknown signal: sigusr1 (signals must use all capital letters)',
}); });
assert.strictEqual(process.report.signal, 'SIGUSR2'); assert.strictEqual(process.report.signal, 'SIGUSR2');
process.report.signal = 'SIGUSR1'; process.report.signal = 'SIGUSR1';

View File

@ -17,7 +17,7 @@ const child = childProcess.spawn(process.execPath, [
__filename, __filename,
'child', 'child',
], { ], {
cwd: tmpdir.path cwd: tmpdir.path,
}); });
child.on('exit', common.mustCall((code) => { child.on('exit', common.mustCall((code) => {
assert.strictEqual(code, 1); assert.strictEqual(code, 1);

View File

@ -14,5 +14,5 @@ base.runTest({
this.ts = Date.now(); this.ts = Date.now();
setImmediate(function() { new f(); }); setImmediate(function() { new f(); });
}; };
f();` f();`,
}); });

View File

@ -14,5 +14,5 @@ base.runTest({
require('vm').createContext({}); require('vm').createContext({});
setImmediate(function() { f(); }); setImmediate(function() { f(); });
}; };
f();` f();`,
}); });

View File

@ -36,7 +36,7 @@ const proc = spawn(process.execPath, [
'--prof', '--prof',
'-pe', code, '-pe', code,
], { ], {
stdio: ['ignore', 'pipe', 'inherit'] stdio: ['ignore', 'pipe', 'inherit'],
}); });
let ticks = ''; let ticks = '';

View File

@ -15,5 +15,5 @@ base.runTest({
setImmediate(function() { f(); }); setImmediate(function() { f(); });
}; };
f();`, f();`,
profProcessFlags: ['--preprocess'] profProcessFlags: ['--preprocess'],
}); });

View File

@ -21,5 +21,5 @@ base.runTest({
} }
setImmediate(function() { f(); }); setImmediate(function() { f(); });
}; };
f();` f();`,
}); });

View File

@ -17,7 +17,7 @@ function runTest(test) {
'--prof', '--prof',
'-pe', test.code, '-pe', test.code,
], { ], {
stdio: [ 'ignore', 'pipe', 'inherit' ] stdio: [ 'ignore', 'pipe', 'inherit' ],
}); });
let ticks = ''; let ticks = '';
@ -39,7 +39,7 @@ function match(pattern, parent, ticks, flags = []) {
...flags, ...flags,
LOG_FILE, LOG_FILE,
], { ], {
stdio: [ 'ignore', 'pipe', 'inherit' ] stdio: [ 'ignore', 'pipe', 'inherit' ],
}); });
let out = ''; let out = '';

View File

@ -6,7 +6,7 @@ const {
isSunOS, isSunOS,
isAIX, isAIX,
isLinuxPPCBE, isLinuxPPCBE,
isFreeBSD isFreeBSD,
} = require('../common'); } = require('../common');
module.exports = { module.exports = {
@ -14,5 +14,5 @@ module.exports = {
isSunOS || isSunOS ||
isAIX || isAIX ||
isLinuxPPCBE || isLinuxPPCBE ||
isFreeBSD isFreeBSD,
}; };

View File

@ -18,8 +18,8 @@ const bufferSource = fixtures.readSync('simple.wasm');
() => { wasi.initialize(); }, () => { wasi.initialize(); },
{ {
code: 'ERR_INVALID_ARG_TYPE', code: 'ERR_INVALID_ARG_TYPE',
message: /"instance" argument must be of type object/ message: /"instance" argument must be of type object/,
} },
); );
} }
@ -34,8 +34,8 @@ const bufferSource = fixtures.readSync('simple.wasm');
() => { wasi.initialize(instance); }, () => { wasi.initialize(instance); },
{ {
code: 'ERR_INVALID_ARG_TYPE', code: 'ERR_INVALID_ARG_TYPE',
message: /"instance\.exports" property must be of type object/ message: /"instance\.exports" property must be of type object/,
} },
); );
} }
@ -57,8 +57,8 @@ const bufferSource = fixtures.readSync('simple.wasm');
() => { wasi.initialize(instance); }, () => { wasi.initialize(instance); },
{ {
code: 'ERR_INVALID_ARG_TYPE', code: 'ERR_INVALID_ARG_TYPE',
message: /"instance\.exports\._initialize" property must be of type function/ message: /"instance\.exports\._initialize" property must be of type function/,
} },
); );
} }
@ -75,7 +75,7 @@ const bufferSource = fixtures.readSync('simple.wasm');
_initialize() {}, _initialize() {},
memory: new WebAssembly.Memory({ initial: 1 }), memory: new WebAssembly.Memory({ initial: 1 }),
}; };
} },
}); });
assert.throws( assert.throws(
() => { wasi.initialize(instance); }, () => { wasi.initialize(instance); },
@ -83,7 +83,7 @@ const bufferSource = fixtures.readSync('simple.wasm');
code: 'ERR_INVALID_ARG_TYPE', code: 'ERR_INVALID_ARG_TYPE',
message: 'The "instance.exports._start" property must be' + message: 'The "instance.exports._start" property must be' +
' undefined. Received function _start', ' undefined. Received function _start',
} },
); );
} }
@ -94,14 +94,14 @@ const bufferSource = fixtures.readSync('simple.wasm');
const instance = await WebAssembly.instantiate(wasm); const instance = await WebAssembly.instantiate(wasm);
Object.defineProperty(instance, 'exports', { Object.defineProperty(instance, 'exports', {
get() { return { _initialize() {} }; } get() { return { _initialize() {} }; },
}); });
assert.throws( assert.throws(
() => { wasi.initialize(instance); }, () => { wasi.initialize(instance); },
{ {
code: 'ERR_INVALID_ARG_TYPE', code: 'ERR_INVALID_ARG_TYPE',
message: /"instance\.exports\.memory" property must be a WebAssembly\.Memory object/ message: /"instance\.exports\.memory" property must be a WebAssembly\.Memory object/,
} },
); );
} }
@ -139,17 +139,17 @@ const bufferSource = fixtures.readSync('simple.wasm');
get() { get() {
return { return {
_initialize() {}, _initialize() {},
memory: new WebAssembly.Memory({ initial: 1 }) memory: new WebAssembly.Memory({ initial: 1 }),
}; };
} },
}); });
wasi.initialize(instance); wasi.initialize(instance);
assert.throws( assert.throws(
() => { wasi.initialize(instance); }, () => { wasi.initialize(instance); },
{ {
code: 'ERR_WASI_ALREADY_STARTED', code: 'ERR_WASI_ALREADY_STARTED',
message: /^WASI instance has already started$/ message: /^WASI instance has already started$/,
} },
); );
} }
})().then(common.mustCall()); })().then(common.mustCall());

View File

@ -8,7 +8,7 @@ if (process.argv[2] === 'wasi-child') {
const { WASI } = require('wasi'); const { WASI } = require('wasi');
const wasi = new WASI({ const wasi = new WASI({
args: ['foo', '-bar', '--baz=value'] args: ['foo', '-bar', '--baz=value'],
}); });
const importObject = { wasi_snapshot_preview1: wasi.wasiImport }; const importObject = { wasi_snapshot_preview1: wasi.wasiImport };
@ -21,7 +21,7 @@ if (process.argv[2] === 'wasi-child') {
}, { }, {
name: 'Error', name: 'Error',
code: 'ERR_WASI_NOT_STARTED', code: 'ERR_WASI_NOT_STARTED',
message: 'wasi.start() has not been called' message: 'wasi.start() has not been called',
}); });
} else { } else {
const assert = require('assert'); const assert = require('assert');
@ -32,7 +32,7 @@ if (process.argv[2] === 'wasi-child') {
__filename, __filename,
'wasi-child', 'wasi-child',
], { ], {
env: { ...process.env, NODE_DEBUG_NATIVE: 'wasi' } env: { ...process.env, NODE_DEBUG_NATIVE: 'wasi' },
}); });
assert.strictEqual(child.signal, null); assert.strictEqual(child.signal, null);
assert.strictEqual(child.status, 0); assert.strictEqual(child.status, 0);

View File

@ -18,8 +18,8 @@ const bufferSource = fixtures.readSync('simple.wasm');
() => { wasi.start(); }, () => { wasi.start(); },
{ {
code: 'ERR_INVALID_ARG_TYPE', code: 'ERR_INVALID_ARG_TYPE',
message: /"instance" argument must be of type object/ message: /"instance" argument must be of type object/,
} },
); );
} }
@ -34,8 +34,8 @@ const bufferSource = fixtures.readSync('simple.wasm');
() => { wasi.start(instance); }, () => { wasi.start(instance); },
{ {
code: 'ERR_INVALID_ARG_TYPE', code: 'ERR_INVALID_ARG_TYPE',
message: /"instance\.exports" property must be of type object/ message: /"instance\.exports" property must be of type object/,
} },
); );
} }
@ -54,8 +54,8 @@ const bufferSource = fixtures.readSync('simple.wasm');
() => { wasi.start(instance); }, () => { wasi.start(instance); },
{ {
code: 'ERR_INVALID_ARG_TYPE', code: 'ERR_INVALID_ARG_TYPE',
message: /"instance\.exports\._start" property must be of type function/ message: /"instance\.exports\._start" property must be of type function/,
} },
); );
} }
@ -72,7 +72,7 @@ const bufferSource = fixtures.readSync('simple.wasm');
_initialize() {}, _initialize() {},
memory: new WebAssembly.Memory({ initial: 1 }), memory: new WebAssembly.Memory({ initial: 1 }),
}; };
} },
}); });
assert.throws( assert.throws(
() => { wasi.start(instance); }, () => { wasi.start(instance); },
@ -80,7 +80,7 @@ const bufferSource = fixtures.readSync('simple.wasm');
code: 'ERR_INVALID_ARG_TYPE', code: 'ERR_INVALID_ARG_TYPE',
message: 'The "instance.exports._initialize" property must be' + message: 'The "instance.exports._initialize" property must be' +
' undefined. Received function _initialize', ' undefined. Received function _initialize',
} },
); );
} }
@ -91,14 +91,14 @@ const bufferSource = fixtures.readSync('simple.wasm');
const instance = await WebAssembly.instantiate(wasm); const instance = await WebAssembly.instantiate(wasm);
Object.defineProperty(instance, 'exports', { Object.defineProperty(instance, 'exports', {
get() { return { _start() {} }; } get() { return { _start() {} }; },
}); });
assert.throws( assert.throws(
() => { wasi.start(instance); }, () => { wasi.start(instance); },
{ {
code: 'ERR_INVALID_ARG_TYPE', code: 'ERR_INVALID_ARG_TYPE',
message: /"instance\.exports\.memory" property must be a WebAssembly\.Memory object/ message: /"instance\.exports\.memory" property must be a WebAssembly\.Memory object/,
} },
); );
} }
@ -136,17 +136,17 @@ const bufferSource = fixtures.readSync('simple.wasm');
get() { get() {
return { return {
_start() {}, _start() {},
memory: new WebAssembly.Memory({ initial: 1 }) memory: new WebAssembly.Memory({ initial: 1 }),
}; };
} },
}); });
wasi.start(instance); wasi.start(instance);
assert.throws( assert.throws(
() => { wasi.start(instance); }, () => { wasi.start(instance); },
{ {
code: 'ERR_WASI_ALREADY_STARTED', code: 'ERR_WASI_ALREADY_STARTED',
message: /^WASI instance has already started$/ message: /^WASI instance has already started$/,
} },
); );
} }
})().then(common.mustCall()); })().then(common.mustCall());

View File

@ -14,8 +14,8 @@ if (process.argv[2] === 'wasi-child') {
env: process.env, env: process.env,
preopens: { preopens: {
'/sandbox': process.argv[4], '/sandbox': process.argv[4],
'/tmp': process.argv[5] '/tmp': process.argv[5],
} },
}); });
const importObject = { wasi_snapshot_preview1: wasi.wasiImport }; const importObject = { wasi_snapshot_preview1: wasi.wasiImport };
const modulePath = path.join(wasmDir, `${process.argv[3]}.wasm`); const modulePath = path.join(wasmDir, `${process.argv[3]}.wasm`);

View File

@ -18,8 +18,8 @@ if (process.argv[2] === 'wasi-child') {
env: process.env, env: process.env,
preopens: { preopens: {
'/sandbox': fixtures.path('wasi'), '/sandbox': fixtures.path('wasi'),
'/tmp': tmpdir.path '/tmp': tmpdir.path,
} },
}); });
const importObject = { wasi_snapshot_preview1: wasi.wasiImport }; const importObject = { wasi_snapshot_preview1: wasi.wasiImport };
const modulePath = path.join(wasmDir, `${process.argv[3]}.wasm`); const modulePath = path.join(wasmDir, `${process.argv[3]}.wasm`);
@ -41,8 +41,8 @@ if (process.argv[2] === 'wasi-child') {
env: { env: {
...process.env, ...process.env,
NODE_DEBUG_NATIVE: 'wasi', NODE_DEBUG_NATIVE: 'wasi',
NODE_PLATFORM: process.platform NODE_PLATFORM: process.platform,
} },
}; };
if (options.stdin !== undefined) if (options.stdin !== undefined)
@ -89,7 +89,7 @@ if (process.argv[2] === 'wasi-child') {
runWASI({ test: 'read_file', stdout: `hello from input.txt${checkoutEOL}` }); runWASI({ test: 'read_file', stdout: `hello from input.txt${checkoutEOL}` });
runWASI({ runWASI({
test: 'read_file_twice', test: 'read_file_twice',
stdout: `hello from input.txt${checkoutEOL}hello from input.txt${checkoutEOL}` stdout: `hello from input.txt${checkoutEOL}hello from input.txt${checkoutEOL}`,
}); });
runWASI({ test: 'stat' }); runWASI({ test: 'stat' });
runWASI({ test: 'write_file' }); runWASI({ test: 'write_file' });