-
Notifications
You must be signed in to change notification settings - Fork 29.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
lib,repl: ignore
canBeRequiredByUsers
built-in
e.g. `wasi` under no `--experimental-wasi-unstable-preview1` flag shouldn't be pre-required.
- Loading branch information
Showing
4 changed files
with
65 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
'use strict'; | ||
|
||
const common = require('../common'); | ||
const tmpdir = require('../common/tmpdir'); | ||
const assert = require('assert'); | ||
const spawn = require('child_process').spawn; | ||
|
||
tmpdir.refresh(); | ||
|
||
function run(wasiPreview) { | ||
let resolve; | ||
const promise = new Promise((_resolve) => { | ||
resolve = _resolve; | ||
}); | ||
|
||
// Use -i to force node into interactive mode, despite stdout not being a TTY | ||
const args = ['-i']; | ||
if (wasiPreview) args.push('--experimental-wasi-unstable-preview1'); | ||
const child = spawn(process.execPath, args); | ||
|
||
const input = 'require(\'events\');\nrequire(\'wasi\');'; | ||
let stdout = ''; | ||
let stderr = ''; | ||
|
||
child.stdout.setEncoding('utf8'); | ||
child.stdout.on('data', (c) => stdout += c); | ||
child.stderr.setEncoding('utf8'); | ||
child.stderr.on('data', (c) => stderr += c); | ||
|
||
child.stdin.end(input); | ||
|
||
child.on('exit', () => { | ||
resolve({ stdout, stderr }); | ||
}); | ||
|
||
return promise; | ||
} | ||
|
||
(async function() { | ||
const ret1 = await run(false); | ||
const ret2 = await run(true); | ||
|
||
assert.match(ret1.stdout, /\[Function: EventEmitter\] {/); | ||
assert.match( | ||
ret1.stdout, | ||
/Uncaught Error: Cannot find module 'wasi'[\w\W]+- <repl>\n/) | ||
|
||
assert.match(ret2.stdout, /\[Function: EventEmitter\] {/); | ||
assert.doesNotMatch( | ||
ret2.stdout, | ||
/Uncaught Error: Cannot find module 'wasi'[\w\W]+- <repl>\n/) | ||
assert.match(ret2.stdout, /{ WASI: \[class WASI\] }/); | ||
})().then(common.mustCall()); |