@ -32,43 +32,41 @@ const fixtureD = fixture('define-global.js');
const fixtureThrows = fixture ( 'throws_error4.js' ) ;
const fixtureThrows = fixture ( 'throws_error4.js' ) ;
// test preloading a single module works
// test preloading a single module works
childProcess . exec ( nodeBinary + ' ' +
childProcess . exec ( nodeBinary + ' ' + preloadOption ( [ fixtureA ] ) + ' ' + fixtureB ,
preloadOption ( [ fixtureA ] ) + ' ' +
fixtureB ,
function ( err , stdout , stderr ) {
function ( err , stdout , stderr ) {
assert . ifError ( err ) ;
if ( err ) throw err ;
assert . strictEqual ( stdout , 'A\nB\n' ) ;
assert . strictEqual ( stdout , 'A\nB\n' ) ;
} ) ;
} ) ;
// test preloading multiple modules works
// test preloading multiple modules works
childProcess . exec ( nodeBinary + ' ' +
childProcess . exec (
preloadOption ( [ fixtureA , fixtureB ] ) + ' ' +
nodeBinary + ' ' + preloadOption ( [ fixtureA , fixtureB ] ) + ' ' + fixtureC ,
fixtureC ,
function ( err , stdout , stderr ) {
function ( err , stdout , stderr ) {
assert . ifError ( err ) ;
if ( err ) throw err ;
assert . strictEqual ( stdout , 'A\nB\nC\n' ) ;
assert . strictEqual ( stdout , 'A\nB\nC\n' ) ;
} ) ;
}
) ;
// test that preloading a throwing module aborts
// test that preloading a throwing module aborts
childProcess . exec ( nodeBinary + ' ' +
childProcess . exec (
preloadOption ( [ fixtureA , fixtureThrows ] ) + ' ' +
nodeBinary + ' ' + preloadOption ( [ fixtureA , fixtureThrows ] ) + ' ' + fixtureB ,
fixtureB ,
function ( err , stdout , stderr ) {
function ( err , stdout , stderr ) {
if ( err ) {
if ( err ) {
assert . strictEqual ( stdout , 'A\n' ) ;
assert . strictEqual ( stdout , 'A\n' ) ;
} else {
} else {
throw new Error ( 'Preload should have failed' ) ;
throw new Error ( 'Preload should have failed' ) ;
}
}
} ) ;
}
) ;
// test that preload can be used with --eval
// test that preload can be used with --eval
childProcess . exec ( nodeBinary + ' ' +
childProcess . exec (
preloadOption ( [ fixtureA ] ) +
nodeBinary + ' ' + preloadOption ( [ fixtureA ] ) + '-e "console.log(\'hello\');"' ,
'-e "console.log(\'hello\');"' ,
function ( err , stdout , stderr ) {
function ( err , stdout , stderr ) {
assert . ifError ( err ) ;
if ( err ) throw err ;
assert . strictEqual ( stdout , 'A\nhello\n' ) ;
assert . strictEqual ( stdout , 'A\nhello\n' ) ;
} ) ;
}
) ;
// test that preload can be used with stdin
// test that preload can be used with stdin
const stdinProc = childProcess . spawn (
const stdinProc = childProcess . spawn (
@ -108,42 +106,43 @@ replProc.on('close', function(code) {
// test that preload placement at other points in the cmdline
// test that preload placement at other points in the cmdline
// also test that duplicated preload only gets loaded once
// also test that duplicated preload only gets loaded once
childProcess . exec ( nodeBinary + ' ' +
childProcess . exec (
preloadOption ( [ fixtureA ] ) +
nodeBinary + ' ' + preloadOption ( [ fixtureA ] ) +
'-e "console.log(\'hello\');" ' +
'-e "console.log(\'hello\');" ' + preloadOption ( [ fixtureA , fixtureB ] ) ,
preloadOption ( [ fixtureA , fixtureB ] ) ,
function ( err , stdout , stderr ) {
function ( err , stdout , stderr ) {
assert . ifError ( err ) ;
if ( err ) throw err ;
assert . strictEqual ( stdout , 'A\nB\nhello\n' ) ;
assert . strictEqual ( stdout , 'A\nB\nhello\n' ) ;
} ) ;
}
) ;
// test that preload works with -i
// test that preload works with -i
const interactive = childProcess . exec ( nodeBinary + ' ' +
const interactive = childProcess . exec (
preloadOption ( [ fixtureD ] ) +
nodeBinary + ' ' + preloadOption ( [ fixtureD ] ) + '-i' ,
'-i' ,
common . mustCall ( function ( err , stdout , stderr ) {
common . mustCall ( function ( err , stdout , stderr ) {
assert . ifError ( err ) ;
assert . ifError ( err ) ;
assert . strictEqual ( stdout , "> 'test'\n> " ) ;
assert . strictEqual ( stdout , "> 'test'\n> " ) ;
} ) ) ;
} )
) ;
interactive . stdin . write ( 'a\n' ) ;
interactive . stdin . write ( 'a\n' ) ;
interactive . stdin . write ( 'process.exit()\n' ) ;
interactive . stdin . write ( 'process.exit()\n' ) ;
childProcess . exec ( nodeBinary + ' ' +
childProcess . exec (
'--require ' + fixture ( 'cluster-preload.js' ) + ' ' +
nodeBinary + ' ' + '--require ' + fixture ( 'cluster-preload.js' ) + ' ' +
fixture ( 'cluster-preload-test.js' ) ,
fixture ( 'cluster-preload-test.js' ) ,
function ( err , stdout , stderr ) {
function ( err , stdout , stderr ) {
assert . ifError ( err ) ;
if ( err ) throw err ;
assert . ok ( /worker terminated with code 43/ . test ( stdout ) ) ;
assert . ok ( /worker terminated with code 43/ . test ( stdout ) ) ;
} ) ;
}
) ;
// https://github.com/nodejs/node/issues/1691
// https://github.com/nodejs/node/issues/1691
process . chdir ( common . fixturesDir ) ;
process . chdir ( common . fixturesDir ) ;
childProcess . exec ( nodeBinary + ' ' +
childProcess . exec (
'--expose_debug_as=v8debug ' +
nodeBinary + ' ' + '--expose_debug_as=v8debug ' + '--require ' +
'--require ' + fixture ( 'cluster-preload.js' ) + ' ' +
fixture ( 'cluster-preload.js' ) + ' ' + 'cluster-preload-test.js' ,
'cluster-preload-test.js' ,
function ( err , stdout , stderr ) {
function ( err , stdout , stderr ) {
assert . ifError ( err ) ;
if ( err ) throw err ;
assert . ok ( /worker terminated with code 43/ . test ( stdout ) ) ;
assert . ok ( /worker terminated with code 43/ . test ( stdout ) ) ;
} ) ;
}
) ;