diff --git a/src/node.js b/src/node.js index 6e25edd8a057c6..8e513a71c7c066 100644 --- a/src/node.js +++ b/src/node.js @@ -140,6 +140,7 @@ } } else { + startup.preloadModules(); // If -i or --interactive were passed, or stdin is a TTY. if (process._forceRepl || NativeModule.require('tty').isatty(0)) { // REPL diff --git a/test/fixtures/define-global.js b/test/fixtures/define-global.js new file mode 100644 index 00000000000000..82b6a5a72cc99b --- /dev/null +++ b/test/fixtures/define-global.js @@ -0,0 +1 @@ +global.a = 'test'; diff --git a/test/parallel/test-preload.js b/test/parallel/test-preload.js index f94a7eae942493..e7d89d124c798c 100644 --- a/test/parallel/test-preload.js +++ b/test/parallel/test-preload.js @@ -1,5 +1,5 @@ 'use strict'; -require('../common'); +const common = require('../common'); const assert = require('assert'); const path = require('path'); const child_process = require('child_process'); @@ -21,6 +21,7 @@ var fixture = function(name) { var fixtureA = fixture('printA.js'); var fixtureB = fixture('printB.js'); var fixtureC = fixture('printC.js'); +const fixtureD = fixture('define-global.js'); var fixtureThrows = fixture('throws_error4.js'); // test preloading a single module works @@ -73,6 +74,18 @@ child_process.exec(nodeBinary + ' ' assert.equal(stdout, 'A\nB\nhello\n'); }); +// test that preload works with -i +const interactive = child_process.exec(nodeBinary + ' ' + + preloadOption([fixtureD]) + + '-i', + common.mustCall(function(err, stdout, stderr) { + assert.ifError(err); + assert.strictEqual(stdout, `> 'test'\n> `); + })); + +interactive.stdin.write('a\n'); +interactive.stdin.write('process.exit()\n'); + child_process.exec(nodeBinary + ' ' + '--require ' + fixture('cluster-preload.js') + ' ' + fixture('cluster-preload-test.js'),