Skip to content

Commit 90451a6

Browse files
committed
test: minimal repl eval option test
Fixes: #3544 PR-URL: #5192 Reviewed-By: Jeremiah Senkpiel <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent ffbc05a commit 90451a6

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

test/parallel/test-repl-eval.js

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
'use strict';
2+
const common = require('../common');
3+
const assert = require('assert');
4+
const repl = require('repl');
5+
6+
{
7+
let evalCalledWithExpectedArgs = false;
8+
9+
const options = {
10+
eval: common.mustCall((cmd, context) => {
11+
// Assertions here will not cause the test to exit with an error code
12+
// so set a boolean that is checked in process.on('exit',...) instead.
13+
evalCalledWithExpectedArgs = (cmd === 'foo\n' && context.foo === 'bar');
14+
})
15+
};
16+
17+
const r = repl.start(options);
18+
r.context = {foo: 'bar'};
19+
20+
try {
21+
r.write('foo\n');
22+
} finally {
23+
r.write('.exit\n');
24+
}
25+
26+
process.on('exit', () => {
27+
assert(evalCalledWithExpectedArgs);
28+
});
29+
}

0 commit comments

Comments
 (0)