/
test-repl-built-in-modules.js
48 lines (43 loc) · 1.37 KB
/
test-repl-built-in-modules.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
'use strict';
require('../common');
const assert = require('assert');
const cp = require('child_process');
function runREPLWithAdditionalFlags(flags) {
// Use -i to force node into interactive mode, despite stdout not being a TTY
const args = ['-i'].concat(flags);
const ret = cp.execFileSync(process.execPath, args, {
input: 'require(\'events\');\nrequire(\'wasi\');',
encoding: 'utf8',
});
return ret;
}
// Run REPL in normal mode.
let stdout = runREPLWithAdditionalFlags([]);
assert.match(stdout, /\[Function: EventEmitter\] {/);
assert.match(
stdout,
/Uncaught Error: Cannot find module 'wasi'[\w\W]+- <repl>\n/);
// Run REPL with '--experimental-wasi-unstable-preview1'
stdout = runREPLWithAdditionalFlags([
'--experimental-wasi-unstable-preview1',
]);
assert.match(stdout, /\[Function: EventEmitter\] {/);
assert.doesNotMatch(
stdout,
/Uncaught Error: Cannot find module 'wasi'[\w\W]+- <repl>\n/);
assert.match(stdout, /{ WASI: \[class WASI\] }/);
{
const res = cp.execFileSync(process.execPath, ['-i'], {
input: "'wasi' in global",
encoding: 'utf8',
});
// `wasi` shouldn't be defined on global when the flag is not set
assert.match(res, /false\n/);
}
{
const res = cp.execFileSync(process.execPath, ['-i', '--experimental-wasi-unstable-preview1'], {
input: "'wasi' in global",
encoding: 'utf8',
});
assert.match(res, /true\n/);
}