File tree 1 file changed +37
-0
lines changed 1 file changed +37
-0
lines changed Original file line number Diff line number Diff line change
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
+ } ) ;
You can’t perform that action at this time.
0 commit comments