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

Commit fec399b

Browse files
authored
Merge pull request #80 from dolsem/master
feat: auto-resume on start breakpoint
2 parents 426ed80 + 12530bf commit fec399b

3 files changed

Lines changed: 30 additions & 2 deletions

File tree

lib/internal/inspect_repl.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -782,6 +782,14 @@ function createRepl(inspector) {
782782
}
783783

784784
Debugger.on('paused', ({ callFrames, reason /* , hitBreakpoints */ }) => {
785+
if (process.env.NODE_INSPECT_RESUME_ON_START === '1' &&
786+
reason === 'Break on start') {
787+
debuglog('Paused on start, but NODE_INSPECT_RESUME_ON_START' +
788+
' environment variable is set to 1, resuming');
789+
inspector.client.callMethod('Debugger.resume');
790+
return;
791+
}
792+
785793
// Save execution context's data
786794
currentBacktrace = Backtrace.from(callFrames);
787795
selectedFrame = currentBacktrace[0];

test/cli/launch.test.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,3 +174,23 @@ test('run after quit / restart', (t) => {
174174
.then(() => cli.quit())
175175
.then(null, onFatal);
176176
});
177+
178+
test('auto-resume on start if the environment variable is defined', (t) => {
179+
const script = Path.join('examples', 'break.js');
180+
181+
const cli = startCLI([script], [], {
182+
env: { NODE_INSPECT_RESUME_ON_START: '1' }
183+
});
184+
185+
return cli.waitForInitialBreak()
186+
.then(() => {
187+
t.match(
188+
cli.breakInfo,
189+
{ filename: script, line: 10 },
190+
'skips to the first breakpoint');
191+
})
192+
.then(() => cli.quit())
193+
.then((code) => {
194+
t.equal(code, 0, 'exits with success');
195+
});
196+
});

test/cli/start-cli.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ function isPreBreak(output) {
2020
return /Break on start/.test(output) && /1 \(function \(exports/.test(output);
2121
}
2222

23-
function startCLI(args, flags = []) {
24-
const child = spawn(process.execPath, [...flags, CLI, ...args]);
23+
function startCLI(args, flags = [], spawnOpts = {}) {
24+
const child = spawn(process.execPath, [...flags, CLI, ...args], spawnOpts);
2525
let isFirstStdoutChunk = true;
2626

2727
const outputBuffer = [];

0 commit comments

Comments
 (0)