Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: add IIFE test for REPL #41047

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -452,8 +452,6 @@ For information about the governance of the Node.js project, see
**Mohammed Keyvanzadeh** <<[email protected]>> (he/him)
* [watilde](https://github.com/watilde) -
**Daijiro Wachi** <<[email protected]>> (he/him)
* [watson](https://github.com/watson) -
**Thomas Watson** <<[email protected]>>
* [XadillaX](https://github.com/XadillaX) -
**Khaidi Chu** <<[email protected]>> (he/him)
* [yashLadha](https://github.com/yashLadha) -
Expand Down Expand Up @@ -620,6 +618,8 @@ For information about the governance of the Node.js project, see
**Vladimir Kurchatkin** <<[email protected]>>
* [vsemozhetbyt](https://github.com/vsemozhetbyt) -
**Vse Mozhet Byt** <<[email protected]>> (he/him)
* [watson](https://github.com/watson) -
**Thomas Watson** <<[email protected]>>
* [whitlockjc](https://github.com/whitlockjc) -
**Jeremy Whitlock** <<[email protected]>>
* [yhwang](https://github.com/yhwang) -
Expand Down
50 changes: 50 additions & 0 deletions test/parallel/test-repl-IIFE.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
'use strict';

// REPL regression test for IIFE https://github.com/nodejs/node/issues/38685

require('../common');
const util = require('util');
const assert = require('assert');
const ArrayStream = require('../common/arraystream');
const repl = require('repl');

// Create a dummy stream that does nothing
const stream = new ArrayStream();
let output = '';

function testNormalIIFE() {
const server = runRepl();

stream.run(['(() => true)()']);
assert.strictEqual(output, '> true\n> ');
output = '';
server.close();
testAsyncIIEF();
}

function testAsyncIIEF() {
const server = runRepl();
const asyncFn = '(async() => true)();';

stream.run([asyncFn]);
// promise output twice
output = util.inspect(output).split('\\n> ')[1];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we using util.inspect here?

assert.strictEqual(output, 'Promise { <pending> }');
output = '';
server.close();
}

// run repl
function runRepl() {
stream.write = function(d) {
output += d;
};

return repl.start({
input: stream,
output: stream
});
}

// start
testNormalIIFE();