Skip to content

Commit bac72d3

Browse files
committed
feat: Initial test case for repl errors
1 parent e06c75c commit bac72d3

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

test/test-repl-error.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
'use strict';
2+
3+
const assert = require('assert');
4+
const REPL = require('../src/repl');
5+
const { Duplex } = require('stream');
6+
7+
global.require = require;
8+
global.module = module;
9+
global.REPL = {
10+
time: (fn) => {
11+
},
12+
last: undefined,
13+
lastError: undefined,
14+
};
15+
16+
let output = '';
17+
const inoutStream = new Duplex({
18+
write(chunk, encoding, callback) {
19+
output += chunk;
20+
callback();
21+
},
22+
23+
read() {
24+
this.push("var b = 'invalid\n");
25+
this.push(null);
26+
},
27+
});
28+
29+
new REPL(inoutStream, inoutStream);
30+
31+
// Matching only on a minimal piece of the error message because V8 throws
32+
// the error `SyntaxError: Invalid or unexpected token`, where as
33+
// ChakraCore throws the error `SyntaxError: Unterminated string constant`.
34+
const errorMessage = 'SyntaxError:';
35+
process.on('exit', () => {
36+
assert.ok(output.includes(errorMessage),'should throw syntax error');
37+
});

0 commit comments

Comments
 (0)