diff --git a/lib/internal/inspect_repl.js b/lib/internal/inspect_repl.js index 7acb3c6..bfbedf6 100644 --- a/lib/internal/inspect_repl.js +++ b/lib/internal/inspect_repl.js @@ -782,6 +782,14 @@ function createRepl(inspector) { } Debugger.on('paused', ({ callFrames, reason /* , hitBreakpoints */ }) => { + if (process.env.NODE_INSPECT_RESUME_ON_START === '1' && + reason === 'Break on start') { + debuglog('Paused on start, but NODE_INSPECT_RESUME_ON_START' + + ' environment variable is set to 1, resuming'); + inspector.client.callMethod('Debugger.resume'); + return; + } + // Save execution context's data currentBacktrace = Backtrace.from(callFrames); selectedFrame = currentBacktrace[0]; diff --git a/test/cli/launch.test.js b/test/cli/launch.test.js index 087a46c..c4ff3d8 100644 --- a/test/cli/launch.test.js +++ b/test/cli/launch.test.js @@ -174,3 +174,23 @@ test('run after quit / restart', (t) => { .then(() => cli.quit()) .then(null, onFatal); }); + +test('auto-resume on start if the environment variable is defined', (t) => { + const script = Path.join('examples', 'break.js'); + + const cli = startCLI([script], [], { + env: { NODE_INSPECT_RESUME_ON_START: '1' } + }); + + return cli.waitForInitialBreak() + .then(() => { + t.match( + cli.breakInfo, + { filename: script, line: 10 }, + 'skips to the first breakpoint'); + }) + .then(() => cli.quit()) + .then((code) => { + t.equal(code, 0, 'exits with success'); + }); +}); diff --git a/test/cli/start-cli.js b/test/cli/start-cli.js index bec4270..32c666c 100644 --- a/test/cli/start-cli.js +++ b/test/cli/start-cli.js @@ -20,8 +20,8 @@ function isPreBreak(output) { return /Break on start/.test(output) && /1 \(function \(exports/.test(output); } -function startCLI(args, flags = []) { - const child = spawn(process.execPath, [...flags, CLI, ...args]); +function startCLI(args, flags = [], spawnOpts = {}) { + const child = spawn(process.execPath, [...flags, CLI, ...args], spawnOpts); let isFirstStdoutChunk = true; const outputBuffer = [];