Skip to content
This repository has been archived by the owner on Feb 1, 2022. It is now read-only.

Commit

Permalink
Merge pull request #80 from dolsem/master
Browse files Browse the repository at this point in the history
feat: auto-resume on start breakpoint
  • Loading branch information
jkrems authored Apr 20, 2020
2 parents 426ed80 + 12530bf commit fec399b
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 2 deletions.
8 changes: 8 additions & 0 deletions lib/internal/inspect_repl.js
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down
20 changes: 20 additions & 0 deletions test/cli/launch.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});
});
4 changes: 2 additions & 2 deletions test/cli/start-cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [];
Expand Down

0 comments on commit fec399b

Please sign in to comment.