Skip to content

feat: Initial test case for repl errors #17

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
37 changes: 37 additions & 0 deletions test/test-repl-error.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
'use strict';

const assert = require('assert');
const REPL = require('../src/repl');
const { Duplex } = require('stream');

global.require = require;
global.module = module;
global.REPL = {
time: (fn) => {
},
last: undefined,
lastError: undefined,
};

let output = '';
const inoutStream = new Duplex({
write(chunk, encoding, callback) {
output += chunk;
callback();
},

read() {
this.push("var b = 'invalid\n");
this.push(null);
},
});

new REPL(inoutStream, inoutStream);

// Matching only on a minimal piece of the error message because V8 throws
// the error `SyntaxError: Invalid or unexpected token`, where as
// ChakraCore throws the error `SyntaxError: Unterminated string constant`.
const errorMessage = 'SyntaxError:';
process.on('exit', () => {
assert.ok(output.includes(errorMessage),'should throw syntax error');
});