@ -31,7 +31,7 @@ const syntaxArgs = [
// no output should be produced
// no output should be produced
assert . strictEqual ( c . stdout , '' , 'stdout produced' ) ;
assert . strictEqual ( c . stdout , '' , 'stdout produced' ) ;
assert . strictEqual ( c . stderr , '' , 'stderr produced' ) ;
assert . strictEqual ( c . stderr , '' , 'stderr produced' ) ;
assert . strictEqual ( c . status , 0 , 'code == ' + c . status ) ;
assert . strictEqual ( c . status , 0 , 'code === ' + c . status ) ;
} ) ;
} ) ;
} ) ;
} ) ;
@ -52,11 +52,14 @@ const syntaxArgs = [
// no stdout should be produced
// no stdout should be produced
assert . strictEqual ( c . stdout , '' , 'stdout produced' ) ;
assert . strictEqual ( c . stdout , '' , 'stdout produced' ) ;
// stderr should include the filename
assert ( c . stderr . startsWith ( file ) , "stderr doesn't start with the filename" ) ;
// stderr should have a syntax error message
// stderr should have a syntax error message
const match = c . stderr . match ( /^SyntaxError: Unexpected identifier$/m ) ;
const match = c . stderr . match ( /^SyntaxError: Unexpected identifier$/m ) ;
assert ( match , 'stderr incorrect' ) ;
assert ( match , 'stderr incorrect' ) ;
assert . strictEqual ( c . status , 1 , 'code == ' + c . status ) ;
assert . strictEqual ( c . status , 1 , 'code === ' + c . status ) ;
} ) ;
} ) ;
} ) ;
} ) ;
@ -79,6 +82,38 @@ const syntaxArgs = [
const match = c . stderr . match ( /^Error: Cannot find module/m ) ;
const match = c . stderr . match ( /^Error: Cannot find module/m ) ;
assert ( match , 'stderr incorrect' ) ;
assert ( match , 'stderr incorrect' ) ;
assert . strictEqual ( c . status , 1 , 'code == ' + c . status ) ;
assert . strictEqual ( c . status , 1 , 'code === ' + c . status ) ;
} ) ;
} ) ;
} ) ;
} ) ;
// should not execute code piped from stdin with --check
// loop each possible option, `-c` or `--check`
syntaxArgs . forEach ( function ( args ) {
const stdin = 'throw new Error("should not get run");' ;
const c = spawnSync ( node , args , { encoding : 'utf8' , input : stdin } ) ;
// no stdout or stderr should be produced
assert . strictEqual ( c . stdout , '' , 'stdout produced' ) ;
assert . strictEqual ( c . stderr , '' , 'stderr produced' ) ;
assert . strictEqual ( c . status , 0 , 'code === ' + c . status ) ;
} ) ;
// should should throw if code piped from stdin with --check has bad syntax
// loop each possible option, `-c` or `--check`
syntaxArgs . forEach ( function ( args ) {
const stdin = 'var foo bar;' ;
const c = spawnSync ( node , args , { encoding : 'utf8' , input : stdin } ) ;
// stderr should include '[stdin]' as the filename
assert ( c . stderr . startsWith ( '[stdin]' ) , "stderr doesn't start with [stdin]" ) ;
// no stdout or stderr should be produced
assert . strictEqual ( c . stdout , '' , 'stdout produced' ) ;
// stderr should have a syntax error message
const match = c . stderr . match ( /^SyntaxError: Unexpected identifier$/m ) ;
assert ( match , 'stderr incorrect' ) ;
assert . strictEqual ( c . status , 1 , 'code === ' + c . status ) ;
} ) ;