Skip to content

Commit f58dee4

Browse files
author
vb
committed
test: add test for REPL IIFE
1 parent e0b3767 commit f58dee4

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed

test/parallel/test-repl-IIFE.js

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
'use strict';
2+
3+
// REPL regression test for IIFE https://github.com/nodejs/node/issues/38685
4+
5+
require('../common');
6+
const util = require('util');
7+
const assert = require('assert');
8+
const ArrayStream = require('../common/arraystream');
9+
const repl = require('repl');
10+
11+
// Create a dummy stream that does nothing
12+
const stream = new ArrayStream();
13+
let output = '';
14+
15+
function testNormalIIFE() {
16+
const server = runRepl();
17+
18+
stream.run(['(() => true)()']);
19+
assert.strictEqual(output, '> true\n> ');
20+
output = '';
21+
server.close();
22+
testAsyncIIEF();
23+
}
24+
25+
function testAsyncIIEF() {
26+
const server = runRepl();
27+
const asyncFn = '(async() => {' +
28+
'await new Promise((resolve, reject) => {' +
29+
'resolve(true)' +
30+
'});' +
31+
'})()';
32+
33+
stream.run([asyncFn]);
34+
// promise output twice
35+
output = util.inspect(output).split('\\n> ')[1];
36+
assert.strictEqual(output, 'Promise { <pending> }');
37+
output = '';
38+
server.close();
39+
}
40+
41+
// run repl
42+
function runRepl() {
43+
stream.write = function(d) {
44+
output += d;
45+
};
46+
47+
return repl.start({
48+
input: stream,
49+
output: stream
50+
});
51+
}
52+
53+
// start
54+
testNormalIIFE();

0 commit comments

Comments
 (0)