Skip to content

Commit 7b2d30c

Browse files
committed
test: add repl test for promise eval
1 parent c9cd561 commit 7b2d30c

File tree

1 file changed

+62
-0
lines changed

1 file changed

+62
-0
lines changed
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
'use strict';
2+
3+
const common = require('../common');
4+
const repl = require('repl');
5+
const ArrayStream = require('../common/arraystream');
6+
const assert = require('assert');
7+
8+
const tests = [
9+
{
10+
send: 'Promise.reject()',
11+
expect: /Promise \{[\s\S]*?Uncaught undefined\n?$/
12+
},
13+
{
14+
send: 'let p = Promise.reject()',
15+
expect: /undefined\nUncaught undefined\n?$/
16+
},
17+
{
18+
send: `Promise.resolve()`,
19+
expect: /Promise \{[\s\S]*?}\n?$/
20+
},
21+
{
22+
send: `Promise.resolve().then(() => {})`,
23+
expect: /Promise \{[\s\S]*?}\n?$/
24+
},
25+
{
26+
send: `async function f() { throw new Error('test'); };f();`,
27+
expect: /Promise \{[\s\S]*?<rejected> Error: test[\s\S]*?Uncaught Error: test[\s\S]*?\n?$/
28+
},
29+
{
30+
send: `async function f() {};f();`,
31+
expect: /Promise \{[\s\S]*?}\n?$/
32+
},
33+
];
34+
35+
(async function() {
36+
await runReplTests(tests);
37+
})().then(common.mustCall());
38+
39+
async function runReplTests(tests) {
40+
for (const { send, expect } of tests) {
41+
const input = new ArrayStream();
42+
const output = new ArrayStream();
43+
let outputText = '';
44+
function write(data) {
45+
outputText += data;
46+
}
47+
output.write = write;
48+
const replServer = repl.start({
49+
prompt: '',
50+
input,
51+
output: output,
52+
});
53+
input.emit('data', `${send}\n`);
54+
await new Promise((resolve) => {
55+
setTimeout(() => {
56+
assert.match(outputText, expect);
57+
replServer.close();
58+
resolve();
59+
}, 10);
60+
});
61+
}
62+
}

0 commit comments

Comments
 (0)