File tree Expand file tree Collapse file tree 1 file changed +54
-0
lines changed
Expand file tree Collapse file tree 1 file changed +54
-0
lines changed Original file line number Diff line number Diff line change 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 ( ) ;
You can’t perform that action at this time.
0 commit comments