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

Commit 8817c16

Browse files
committed
feat: auto-resume on start breakpoint
1 parent 426ed80 commit 8817c16

3 files changed

Lines changed: 34 additions & 2 deletions

File tree

lib/_inspect.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,19 @@ class NodeInspector {
170170
this.domainNames.forEach((domain) => {
171171
this[domain] = createAgentProxy(domain, this.client);
172172
});
173+
let startBreakReached = false;
173174
this.handleDebugEvent = (fullName, params) => {
175+
if (!startBreakReached &&
176+
process.env.NODE_INSPECT_RESUME_ON_START === '1' &&
177+
fullName === 'Debugger.paused' &&
178+
params && params.reason === 'Break on start') {
179+
startBreakReached = true;
180+
debuglog('Paused on start, but NODE_INSPECT_RESUME_ON_START' +
181+
' environment variable is set to 1, resuming');
182+
this.client.callMethod('Debugger.resume');
183+
return;
184+
}
185+
174186
const [domain, name] = fullName.split('.');
175187
if (domain in this) {
176188
this[domain].emit(name, params);

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)