test: move debugger tests with --port=0 to parallel

Before

```
❯ tools/test.py "sequential/test-debugger*"
[00:25|% 100|+  32|-   0]: Done

All tests passed.
❯ tools/test.py -J "parallel/test-debugger*"
[00:05|% 100|+   6|-   0]: Done

All tests passed.
```

After

```
❯ tools/test.py "sequential/test-debugger*"
[00:06|% 100|+   5|-   0]: Done

All tests passed.
❯ tools/test.py -J "parallel/test-debugger*"
[00:05|% 100|+  33|-   0]: Done

All tests passed.
```

PR-URL: https://github.com/nodejs/node/pull/47274
Refs: https://github.com/nodejs/node/issues/47146
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
Joyee Cheung authored and RafaelGSS committed 2023-04-08 15:18:08 -03:00
1 parent 041885ebd0
commit db95ed0b1b
27 files changed

No files matched your search

@@ -1,35 +0,0 @@
import { skipIfInspectorDisabled } from '../common/index.mjs';
skipIfInspectorDisabled();
import { path as _path } from '../common/fixtures.js';
import startCLI from '../common/debugger.js';
import { addLibraryPath } from '../common/shared-lib-util.js';
import { deepStrictEqual, strictEqual } from 'assert';
import { relative } from 'path';
addLibraryPath(process.env);
// Auto-resume on start if the environment variable is defined.
{
const scriptFullPath = _path('debugger', 'break.js');
const script = relative(process.cwd(), scriptFullPath);
const env = {
...process.env,
};
env.NODE_INSPECT_RESUME_ON_START = '1';
const cli = startCLI(['--port=0', script], [], {
env,
});
await cli.waitForInitialBreak();
deepStrictEqual(cli.breakInfo, {
filename: script,
line: 10,
});
const code = await cli.quit();
strictEqual(code, 0);
}
@@ -1,33 +0,0 @@
'use strict';
const common = require('../common');
common.skipIfInspectorDisabled();
const fixtures = require('../common/fixtures');
const startCLI = require('../common/debugger');
const assert = require('assert');
const path = require('path');
// Display and navigate backtrace.
{
const scriptFullPath = fixtures.path('debugger', 'backtrace.js');
const script = path.relative(process.cwd(), scriptFullPath);
const cli = startCLI(['--port=0', script]);
async function runTest() {
try {
await cli.waitForInitialBreak();
await cli.waitForPrompt();
await cli.stepCommand('c');
await cli.command('bt');
assert.ok(cli.output.includes(`#0 topFn ${script}:7:2`));
await cli.command('backtrace');
assert.ok(cli.output.includes(`#0 topFn ${script}:7:2`));
} finally {
await cli.quit();
}
}
runTest();
}
-110
View File
@@ -1,110 +0,0 @@
'use strict';
const common = require('../common');
common.skipIfInspectorDisabled();
const fixtures = require('../common/fixtures');
const startCLI = require('../common/debugger');
const assert = require('assert');
const path = require('path');
const scriptFullPath = fixtures.path('debugger', 'break.js');
const script = path.relative(process.cwd(), scriptFullPath);
const cli = startCLI(['--port=0', script]);
(async () => {
await cli.waitForInitialBreak();
await cli.waitForPrompt();
assert.deepStrictEqual(
cli.breakInfo,
{ filename: script, line: 1 },
);
assert.match(
cli.output,
/> 1 (?:\(function \([^)]+\) \{ )?const x = 10;/,
'shows the source and marks the current line');
await cli.stepCommand('n');
assert.ok(
cli.output.includes(`break in ${script}:2`),
'pauses in next line of the script');
assert.match(
cli.output,
/> 2 let name = 'World';/,
'marks the 2nd line');
await cli.stepCommand('next');
assert.ok(
cli.output.includes(`break in ${script}:3`),
'pauses in next line of the script');
assert.match(
cli.output,
/> 3 name = 'Robin';/,
'marks the 3nd line');
await cli.stepCommand('cont');
assert.ok(
cli.output.includes(`break in ${script}:10`),
'pauses on the next breakpoint');
assert.match(
cli.output,
/>10 debugger;/,
'marks the debugger line');
await cli.command('sb("break.js", 6)');
assert.doesNotMatch(cli.output, /Could not resolve breakpoint/);
await cli.command('sb("otherFunction()")');
await cli.command('sb(16)');
assert.doesNotMatch(cli.output, /Could not resolve breakpoint/);
await cli.command('breakpoints');
assert.ok(cli.output.includes(`#0 ${script}:6`));
assert.ok(cli.output.includes(`#1 ${script}:16`));
await cli.command('list()');
assert.match(
cli.output,
/>10 debugger;/,
'prints and marks current line'
);
assert.deepStrictEqual(
cli.parseSourceLines(),
[5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],
);
await cli.command('list(2)');
assert.match(
cli.output,
/>10 debugger;/,
'prints and marks current line'
);
assert.deepStrictEqual(
cli.parseSourceLines(),
[8, 9, 10, 11, 12],
);
await cli.stepCommand('s');
await cli.stepCommand('');
assert.match(
cli.output,
/break in node:timers/,
'entered timers.js');
await cli.stepCommand('cont');
assert.ok(
cli.output.includes(`break in ${script}:16`),
'found breakpoint we set above w/ line number only');
await cli.stepCommand('cont');
assert.ok(
cli.output.includes(`break in ${script}:6`),
'found breakpoint we set above w/ line number & script');
await cli.stepCommand('');
assert.ok(
cli.output.includes(`debugCommand in ${script}:14`),
'found function breakpoint we set above');
})().finally(() => cli.quit())
.then(common.mustCall());
@@ -1,24 +0,0 @@
'use strict';
const common = require('../common');
common.skipIfInspectorDisabled();
const fixtures = require('../common/fixtures');
const startCLI = require('../common/debugger');
// Test for "Breakpoint at specified location already exists" error.
const script = fixtures.path('debugger', 'three-lines.js');
const cli = startCLI(['--port=0', script]);
(async () => {
try {
await cli.waitForInitialBreak();
await cli.waitForPrompt();
await cli.command('setBreakpoint(1)');
await cli.command('setBreakpoint(1)');
await cli.waitFor(/Breakpoint at specified location already exists/);
} finally {
await cli.quit();
}
})().then(common.mustCall());
@@ -1,53 +0,0 @@
'use strict';
const common = require('../common');
common.skipIfInspectorDisabled();
const fixtures = require('../common/fixtures');
const startCLI = require('../common/debugger');
const assert = require('assert');
const path = require('path');
// clearBreakpoint
{
const scriptFullPath = fixtures.path('debugger', 'break.js');
const script = path.relative(process.cwd(), scriptFullPath);
const cli = startCLI(['--port=0', script]);
function onFatal(error) {
cli.quit();
throw error;
}
return cli.waitForInitialBreak()
.then(() => cli.waitForPrompt())
.then(() => cli.command('sb("break.js", 3)'))
.then(() => cli.command('sb("break.js", 9)'))
.then(() => cli.command('breakpoints'))
.then(() => {
assert.ok(cli.output.includes(`#0 ${script}:3`));
assert.ok(cli.output.includes(`#1 ${script}:9`));
})
.then(() => cli.command('clearBreakpoint("break.js", 4)'))
.then(() => {
assert.match(cli.output, /Could not find breakpoint/);
})
.then(() => cli.command('clearBreakpoint("not-such-script.js", 3)'))
.then(() => {
assert.match(cli.output, /Could not find breakpoint/);
})
.then(() => cli.command('clearBreakpoint("break.js", 3)'))
.then(() => cli.command('breakpoints'))
.then(() => {
assert.ok(cli.output.includes(`#0 ${script}:9`));
})
.then(() => cli.stepCommand('cont'))
.then(() => {
assert.ok(
cli.output.includes(`break in ${script}:9`),
'hits the 2nd breakpoint because the 1st was cleared');
})
.then(() => cli.quit())
.then(null, onFatal);
}
@@ -1,58 +0,0 @@
'use strict';
const common = require('../common');
common.skipIfInspectorDisabled();
const fixtures = require('../common/fixtures');
const startCLI = require('../common/debugger');
const assert = require('assert');
const path = require('path');
// Break on (uncaught) exceptions.
{
const scriptFullPath = fixtures.path('debugger', 'exceptions.js');
const script = path.relative(process.cwd(), scriptFullPath);
const cli = startCLI(['--port=0', script]);
(async () => {
try {
await cli.waitForInitialBreak();
await cli.waitForPrompt();
await cli.waitForPrompt();
assert.deepStrictEqual(cli.breakInfo, { filename: script, line: 1 });
// Making sure it will die by default:
await cli.command('c');
await cli.waitFor(/disconnect/);
// Next run: With `breakOnException` it pauses in both places.
await cli.stepCommand('r');
await cli.waitForInitialBreak();
assert.deepStrictEqual(cli.breakInfo, { filename: script, line: 1 });
await cli.command('breakOnException');
await cli.stepCommand('c');
assert.ok(cli.output.includes(`exception in ${script}:3`));
await cli.stepCommand('c');
assert.ok(cli.output.includes(`exception in ${script}:9`));
// Next run: With `breakOnUncaught` it only pauses on the 2nd exception.
await cli.command('breakOnUncaught');
await cli.stepCommand('r'); // Also, the setting survives the restart.
await cli.waitForInitialBreak();
assert.deepStrictEqual(cli.breakInfo, { filename: script, line: 1 });
await cli.stepCommand('c');
assert.ok(cli.output.includes(`exception in ${script}:9`));
// Next run: Back to the initial state! It should die again.
await cli.command('breakOnNone');
await cli.stepCommand('r');
await cli.waitForInitialBreak();
assert.deepStrictEqual(cli.breakInfo, { filename: script, line: 1 });
await cli.command('c');
await cli.waitFor(/disconnect/);
} finally {
cli.quit();
}
})().then(common.mustCall());
}
@@ -1,23 +0,0 @@
import { skipIfInspectorDisabled } from '../common/index.mjs';
skipIfInspectorDisabled();
import { path } from '../common/fixtures.mjs';
import startCLI from '../common/debugger.js';
import assert from 'assert';
const cli = startCLI(['--port=0', path('debugger/backtrace.js')]);
try {
await cli.waitForInitialBreak();
await cli.waitForPrompt();
await cli.stepCommand('c');
await cli.command('exec .scope');
assert.match(cli.output, /'moduleScoped'/, 'displays closure from module body');
assert.match(cli.output, /'a'/, 'displays local / function arg');
assert.match(cli.output, /'l1'/, 'displays local scope');
assert.doesNotMatch(cli.output, /'encodeURIComponent'/, 'omits global scope');
} finally {
await cli.quit();
}
-68
View File
@@ -1,68 +0,0 @@
'use strict';
const common = require('../common');
common.skipIfInspectorDisabled();
const fixtures = require('../common/fixtures');
const startCLI = require('../common/debugger');
const assert = require('assert');
const cli = startCLI(['--port=0', fixtures.path('debugger/alive.js')]);
async function waitInitialBreak() {
try {
await cli.waitForInitialBreak();
await cli.waitForPrompt();
await cli.command('exec [typeof heartbeat, typeof process.exit]');
assert.match(cli.output, /\[ 'function', 'function' \]/, 'works w/o paren');
await cli.command('p [typeof heartbeat, typeof process.exit]');
assert.match(
cli.output,
/\[ 'function', 'function' \]/,
'works w/o paren, short'
);
await cli.command('repl');
assert.match(
cli.output,
/Press Ctrl\+C to leave debug repl\n+> /,
'shows hint for how to leave repl'
);
assert.doesNotMatch(cli.output, /debug>/, 'changes the repl style');
await cli.command('[typeof heartbeat, typeof process.exit]');
await cli.waitFor(/function/);
await cli.waitForPrompt();
assert.match(
cli.output,
/\[ 'function', 'function' \]/,
'can evaluate in the repl'
);
assert.match(cli.output, /> $/);
await cli.ctrlC();
await cli.waitFor(/debug> $/);
await cli.command('exec("[typeof heartbeat, typeof process.exit]")');
assert.match(cli.output, /\[ 'function', 'function' \]/, 'works w/ paren');
await cli.command('p("[typeof heartbeat, typeof process.exit]")');
assert.match(
cli.output,
/\[ 'function', 'function' \]/,
'works w/ paren, short'
);
await cli.command('cont');
await cli.command('exec [typeof heartbeat, typeof process.exit]');
assert.match(
cli.output,
/\[ 'undefined', 'function' \]/,
'non-paused exec can see global but not module-scope values'
);
} finally {
await cli.quit();
}
}
waitInitialBreak();
@@ -1,39 +0,0 @@
'use strict';
const common = require('../common');
common.skipIfInspectorDisabled();
const fixtures = require('../common/fixtures');
const startCLI = require('../common/debugger');
const tmpdir = require('../common/tmpdir');
const path = require('path');
tmpdir.refresh();
const { readFileSync } = require('fs');
const filename = path.join(tmpdir.path, 'node.heapsnapshot');
// Heap profiler take snapshot.
{
const opts = { cwd: tmpdir.path };
const cli = startCLI(['--port=0', fixtures.path('debugger/empty.js')], [], opts);
async function waitInitialBreak() {
try {
await cli.waitForInitialBreak();
await cli.waitForPrompt();
await cli.command('takeHeapSnapshot()');
JSON.parse(readFileSync(filename, 'utf8'));
// Check that two simultaneous snapshots don't step all over each other.
// Refs: https://github.com/nodejs/node/issues/39555
await cli.command('takeHeapSnapshot(); takeHeapSnapshot()');
JSON.parse(readFileSync(filename, 'utf8'));
} finally {
await cli.quit();
}
}
// Check that the snapshot is valid JSON.
waitInitialBreak().then(common.mustCall());
}
-19
View File
@@ -1,19 +0,0 @@
import { skipIfInspectorDisabled } from '../common/index.mjs';
skipIfInspectorDisabled();
import { path } from '../common/fixtures.mjs';
import startCLI from '../common/debugger.js';
import assert from 'assert';
const cli = startCLI(['--port=0', path('debugger', 'empty.js')]);
try {
await cli.waitForInitialBreak();
await cli.waitForPrompt();
await cli.command('help');
assert.match(cli.output, /run, restart, r\s+/m);
} finally {
cli.quit();
}
-30
View File
@@ -1,30 +0,0 @@
'use strict';
const common = require('../common');
common.skipIfInspectorDisabled();
const fixtures = require('../common/fixtures');
const startCLI = require('../common/debugger');
const assert = require('assert');
const cli = startCLI(['--port=0', fixtures.path('debugger/three-lines.js')]);
(async () => {
await cli.waitForInitialBreak();
await cli.waitForPrompt();
await cli.command('list(0)');
assert.match(cli.output, /> 1 let x = 1;/);
await cli.command('list(1)');
assert.match(cli.output, /> 1 let x = 1;\r?\n {2}2 x = x \+ 1;/);
await cli.command('list(10)');
assert.match(cli.output, /> 1 let x = 1;\r?\n {2}2 x = x \+ 1;\r?\n {2}3 module\.exports = x;\r?\n {2}4 /);
await cli.command('c');
await cli.waitFor(/disconnect/);
await cli.waitFor(/debug> $/);
await cli.command('list()');
await cli.waitFor(/ERR_DEBUGGER_ERROR/);
assert.match(cli.output, /Uncaught Error \[ERR_DEBUGGER_ERROR\]: Requires execution to be paused/);
})()
.finally(() => cli.quit())
.then(common.mustCall());
@@ -1,35 +0,0 @@
'use strict';
const common = require('../common');
common.skipIfInspectorDisabled();
const fixtures = require('../common/fixtures');
const startCLI = require('../common/debugger');
const assert = require('assert');
// Debugger agent direct access.
{
const cli = startCLI(['--port=0', fixtures.path('debugger/three-lines.js')]);
const scriptPattern = /^\* (\d+): \S+debugger(?:\/|\\)three-lines\.js/m;
async function testDebuggerLowLevel() {
try {
await cli.waitForInitialBreak();
await cli.waitForPrompt();
await cli.command('scripts');
const [, scriptId] = cli.output.match(scriptPattern);
await cli.command(
`Debugger.getScriptSource({ scriptId: '${scriptId}' })`
);
assert.match(
cli.output,
/scriptSource:[ \n]*'(?:\(function \(|let x = 1)/);
assert.match(
cli.output,
/let x = 1;/);
} finally {
await cli.quit();
}
}
testDebuggerLowLevel();
}
@@ -1,42 +0,0 @@
'use strict';
const common = require('../common');
common.skipIfInspectorDisabled();
const fixtures = require('../common/fixtures');
const startCLI = require('../common/debugger');
const assert = require('assert');
const cli = startCLI(['--port=0', fixtures.path('debugger/empty.js')]);
(async () => {
await cli.waitForInitialBreak();
await cli.waitForPrompt();
await cli.command('exec new Date(0)');
assert.match(cli.output, /1970-01-01T00:00:00\.000Z/);
await cli.command('exec null');
assert.match(cli.output, /null/);
await cli.command('exec /regex/g');
assert.match(cli.output, /\/regex\/g/);
await cli.command('exec new Map()');
assert.match(cli.output, /Map\(0\) {}/);
await cli.command('exec new Map([["a",1],["b",2]])');
assert.match(cli.output, /Map\(2\) { a => 1, b => 2 }/);
await cli.command('exec new Set()');
assert.match(cli.output, /Set\(0\) {}/);
await cli.command('exec new Set([1,2])');
assert.match(cli.output, /Set\(2\) { 1, 2 }/);
await cli.command('exec new Set([{a:1},new Set([1])])');
assert.match(cli.output, /Set\(2\) { { a: 1 }, Set\(1\) { \.\.\. } }/);
await cli.command('exec a={}; a');
assert.match(cli.output, /{}/);
await cli.command('exec a={a:1,b:{c:1}}; a');
assert.match(cli.output, /{ a: 1, b: Object }/);
await cli.command('exec a=[]; a');
assert.match(cli.output, /\[\]/);
await cli.command('exec a=[1,2]; a');
assert.match(cli.output, /\[ 1, 2 \]/);
})()
.finally(() => cli.quit())
.then(common.mustCall());
@@ -1,47 +0,0 @@
'use strict';
const common = require('../common');
common.skipIfInspectorDisabled();
const fixtures = require('../common/fixtures');
const startCLI = require('../common/debugger');
const assert = require('assert');
const path = require('path');
const scriptFullPath = fixtures.path('debugger', 'three-lines.js');
const script = path.relative(process.cwd(), scriptFullPath);
// Run after quit.
const runTest = async () => {
const cli = startCLI(['--port=0', script]);
try {
await cli.waitForInitialBreak();
await cli.waitForPrompt();
await cli.command('breakpoints');
assert.match(cli.output, /No breakpoints yet/);
await cli.command('sb(2)');
await cli.command('sb(3)');
await cli.command('breakpoints');
assert.ok(cli.output.includes(`#0 ${script}:2`));
assert.ok(cli.output.includes(`#1 ${script}:3`));
await cli.stepCommand('c'); // hit line 2
await cli.stepCommand('c'); // hit line 3
assert.deepStrictEqual(cli.breakInfo, { filename: script, line: 3 });
await cli.command('restart');
await cli.waitForInitialBreak();
assert.deepStrictEqual(cli.breakInfo, { filename: script, line: 1 });
await cli.stepCommand('c');
assert.deepStrictEqual(cli.breakInfo, { filename: script, line: 2 });
await cli.stepCommand('c');
assert.deepStrictEqual(cli.breakInfo, { filename: script, line: 3 });
await cli.command('breakpoints');
const msg = `SCRIPT: ${script}, OUTPUT: ${cli.output}`;
assert.ok(cli.output.includes(`#0 ${script}:2`), msg);
assert.ok(cli.output.includes(`#1 ${script}:3`), msg);
} finally {
await cli.quit();
}
};
runTest();
@@ -1,35 +0,0 @@
'use strict';
const common = require('../common');
common.skipIfInspectorDisabled();
const fixtures = require('../common/fixtures');
const startCLI = require('../common/debugger');
const assert = require('assert');
const fs = require('fs');
const path = require('path');
const cli = startCLI(['--port=0', fixtures.path('debugger/empty.js')]);
const rootDir = path.resolve(__dirname, '..', '..');
(async () => {
await cli.waitForInitialBreak();
await cli.waitForPrompt();
await cli.command('profile');
await cli.command('profileEnd');
assert.match(cli.output, /\[Profile \d+μs\]/);
await cli.command('profiles');
assert.match(cli.output, /\[ \[Profile \d+μs\] \]/);
await cli.command('profiles[0].save()');
assert.match(cli.output, /Saved profile to .*node\.cpuprofile/);
const cpuprofile = path.resolve(rootDir, 'node.cpuprofile');
const data = JSON.parse(fs.readFileSync(cpuprofile, 'utf8'));
assert.strictEqual(Array.isArray(data.nodes), true);
fs.rmSync(cpuprofile);
})()
.then(common.mustCall())
.finally(() => cli.quit());
-41
View File
@@ -1,41 +0,0 @@
'use strict';
const common = require('../common');
common.skipIfInspectorDisabled();
const fixtures = require('../common/fixtures');
const startCLI = require('../common/debugger');
const assert = require('assert');
function delay(ms) {
return new Promise((resolve) => setTimeout(resolve, ms));
}
// Profiles.
{
const cli = startCLI(['--port=0', fixtures.path('debugger/empty.js')]);
function onFatal(error) {
cli.quit();
throw error;
}
try {
(async () => {
await cli.waitForInitialBreak();
await cli.waitForPrompt();
await cli.command('exec console.profile()');
assert.match(cli.output, /undefined/);
await cli.command('exec console.profileEnd()');
await delay(250);
assert.match(cli.output, /undefined/);
assert.match(cli.output, /Captured new CPU profile\./);
await cli.quit();
})()
.then(common.mustCall());
} catch (error) {
return onFatal(error);
}
}
@@ -1,25 +0,0 @@
'use strict';
const common = require('../common');
common.skipIfInspectorDisabled();
const fixtures = require('../common/fixtures');
const startCLI = require('../common/debugger');
const assert = require('assert');
// Random port with --inspect-port=0.
const script = fixtures.path('debugger', 'three-lines.js');
const cli = startCLI(['--inspect-port=0', script]);
(async () => {
await cli.waitForInitialBreak();
await cli.waitForPrompt();
assert.match(cli.output, /debug>/, 'prints a prompt');
assert.match(
cli.output,
/< Debugger listening on /,
'forwards child output');
const code = await cli.quit();
assert.strictEqual(code, 0);
})().then(common.mustCall());
@@ -1,30 +0,0 @@
'use strict';
const common = require('../common');
common.skipIfInspectorDisabled();
const fixtures = require('../common/fixtures');
const startCLI = require('../common/debugger');
const assert = require('assert');
// Random port.
{
const script = fixtures.path('debugger', 'three-lines.js');
const cli = startCLI(['--port=0', script]);
cli.waitForInitialBreak()
.then(() => cli.waitForPrompt())
.then(() => {
assert.match(cli.output, /debug>/, 'prints a prompt');
assert.match(
cli.output,
/< Debugger listening on /,
'forwards child output');
})
.then(() => cli.quit())
.then((code) => {
assert.strictEqual(code, 0);
});
}
@@ -1,45 +0,0 @@
'use strict';
const common = require('../common');
common.skipIfInspectorDisabled();
const path = require('../common/fixtures').path;
const spawn = require('child_process').spawn;
const assert = require('assert');
const fixture = path('debugger-repeat-last.js');
const args = [
'inspect',
'--port=0',
fixture,
];
const proc = spawn(process.execPath, args, { stdio: 'pipe' });
proc.stdout.setEncoding('utf8');
let stdout = '';
let sentCommand = false;
let sentExit = false;
proc.stdout.on('data', (data) => {
stdout += data;
// Send 'n' as the first step.
if (!sentCommand && stdout.includes('> 1 ')) {
setImmediate(() => { proc.stdin.write('n\n'); });
return sentCommand = true;
}
// Send empty (repeat last command) until we reach line 5.
if (sentCommand && !stdout.includes('> 5')) {
setImmediate(() => { proc.stdin.write('\n'); });
return true;
}
if (!sentExit && stdout.includes('> 5')) {
setTimeout(() => { proc.stdin.write('\n\n\n.exit\n\n\n'); }, 1);
return sentExit = true;
}
});
process.on('exit', (exitCode) => {
assert.strictEqual(exitCode, 0);
console.log(stdout);
});
@@ -1,37 +0,0 @@
'use strict';
const common = require('../common');
common.skipIfInspectorDisabled();
const assert = require('assert');
const RESTARTS = 10;
const fixtures = require('../common/fixtures');
const startCLI = require('../common/debugger');
// Using `restart` should result in only one "Connect/For help" message.
{
const script = fixtures.path('debugger', 'three-lines.js');
const cli = startCLI(['--port=0', script]);
const listeningRegExp = /Debugger listening on/g;
async function onWaitForInitialBreak() {
try {
await cli.waitForInitialBreak();
await cli.waitForPrompt();
assert.strictEqual(cli.output.match(listeningRegExp).length, 1);
for (let i = 0; i < RESTARTS; i++) {
await cli.stepCommand('restart');
assert.strictEqual(cli.output.match(listeningRegExp).length, 1);
}
} finally {
await cli.quit();
}
}
onWaitForInitialBreak();
}
@@ -1,90 +0,0 @@
'use strict';
const common = require('../common');
common.skipIfInspectorDisabled();
const fixtures = require('../common/fixtures');
const startCLI = require('../common/debugger');
const assert = require('assert');
const path = require('path');
// Run after quit/restart.
{
const scriptFullPath = fixtures.path('debugger', 'three-lines.js');
const script = path.relative(process.cwd(), scriptFullPath);
const cli = startCLI(['--port=0', script]);
function onFatal(error) {
cli.quit();
throw error;
}
cli.waitForInitialBreak()
.then(() => cli.waitForPrompt())
.then(() => cli.stepCommand('n'))
.then(() => {
assert.ok(
cli.output.includes(`break in ${script}:2`),
'steps to the 2nd line'
);
})
.then(() => cli.command('cont'))
.then(() => cli.waitFor(/disconnect/))
.then(() => {
assert.match(
cli.output,
/Waiting for the debugger to disconnect/,
'the child was done');
})
.then(() => {
// On windows the socket won't close by itself
return cli.command('kill');
})
.then(() => cli.command('cont'))
.then(() => cli.waitFor(/start the app/))
.then(() => {
assert.match(cli.output, /Use `run` to start the app again/);
})
.then(() => cli.stepCommand('run'))
.then(() => cli.waitForInitialBreak())
.then(() => cli.waitForPrompt())
.then(() => {
assert.deepStrictEqual(
cli.breakInfo,
{ filename: script, line: 1 },
);
})
.then(() => cli.stepCommand('n'))
.then(() => {
assert.deepStrictEqual(
cli.breakInfo,
{ filename: script, line: 2 },
);
})
.then(() => cli.stepCommand('restart'))
.then(() => cli.waitForInitialBreak())
.then(() => {
assert.deepStrictEqual(
cli.breakInfo,
{ filename: script, line: 1 },
);
})
.then(() => cli.command('kill'))
.then(() => cli.command('cont'))
.then(() => cli.waitFor(/start the app/))
.then(() => {
assert.match(cli.output, /Use `run` to start the app again/);
})
.then(() => cli.stepCommand('run'))
.then(() => cli.waitForInitialBreak())
.then(() => cli.waitForPrompt())
.then(() => {
assert.deepStrictEqual(
cli.breakInfo,
{ filename: script, line: 1 },
);
})
.then(() => cli.quit())
.then(null, onFatal);
}
@@ -1,33 +0,0 @@
'use strict';
const common = require('../common');
common.skipIfInspectorDisabled();
const fixtures = require('../common/fixtures');
const startCLI = require('../common/debugger');
const assert = require('assert');
const path = require('path');
// Using sb before loading file.
const scriptFullPath = fixtures.path('debugger', 'cjs', 'index.js');
const script = path.relative(process.cwd(), scriptFullPath);
const otherScriptFullPath = fixtures.path('debugger', 'cjs', 'other.js');
const otherScript = path.relative(process.cwd(), otherScriptFullPath);
const cli = startCLI(['--port=0', script]);
(async () => {
await cli.waitForInitialBreak();
await cli.waitForPrompt();
await cli.command('sb("other.js", 2)');
assert.match(cli.output, /not loaded yet/,
'warns that the script was not loaded yet');
await cli.stepCommand('cont');
assert.ok(cli.output.includes(`break in ${otherScript}:2`),
'found breakpoint in file that was not loaded yet');
})()
.then(common.mustCall())
.finally(() => cli.quit());
-42
View File
@@ -1,42 +0,0 @@
'use strict';
const common = require('../common');
common.skipIfInspectorDisabled();
const fixtures = require('../common/fixtures');
const startCLI = require('../common/debugger');
const assert = require('assert');
// List scripts.
{
const script = fixtures.path('debugger', 'three-lines.js');
const cli = startCLI(['--port=0', script]);
(async () => {
try {
await cli.waitForInitialBreak();
await cli.waitForPrompt();
await cli.command('scripts');
assert.match(
cli.output,
/^\* \d+: \S+debugger(?:\/|\\)three-lines\.js/m,
'lists the user script');
assert.doesNotMatch(
cli.output,
/\d+: node:internal\/buffer/,
'omits node-internal scripts');
await cli.command('scripts(true)');
assert.match(
cli.output,
/\* \d+: \S+debugger(?:\/|\\)three-lines\.js/,
'lists the user script');
assert.match(
cli.output,
/\d+: node:internal\/buffer/,
'includes node-internal scripts');
} finally {
await cli.quit();
}
})().then(common.mustCall());
}
@@ -1,50 +0,0 @@
import { skipIfInspectorDisabled } from '../common/index.mjs';
skipIfInspectorDisabled();
import { path } from '../common/fixtures.mjs';
import startCLI from '../common/debugger.js';
import assert from 'assert';
const script = path('debugger', 'twenty-lines.js');
const cli = startCLI(['--port=0', script]);
function onFatal(error) {
cli.quit();
throw error;
}
function getLastLine(output) {
const splittedByLine = output.split(';');
return splittedByLine[splittedByLine.length - 2];
}
// Stepping through breakpoints.
try {
await cli.waitForInitialBreak();
await cli.waitForPrompt();
await cli.command('setContextLineNumber("1")');
assert.ok(cli.output.includes('argument must be of type number. Received type string'));
await cli.command('setContextLineNumber(0)');
assert.ok(cli.output.includes('It must be >= 1. Received 0'));
// Make sure the initial value is 2.
await cli.stepCommand('n');
assert.ok(getLastLine(cli.output).includes('4 x = 3'));
await cli.command('setContextLineNumber(5)');
await cli.stepCommand('n');
assert.ok(getLastLine(cli.output).includes('8 x = 7'));
await cli.command('setContextLineNumber(3)');
await cli.stepCommand('n');
assert.ok(getLastLine(cli.output).includes('7 x = 6'));
await cli.command('list(3)');
assert.ok(getLastLine(cli.output).includes('7 x = 6'));
await cli.quit();
} catch (error) {
onFatal(error);
}
@@ -1,32 +0,0 @@
'use strict';
const common = require('../common');
common.skipIfInspectorDisabled();
const fixtures = require('../common/fixtures');
const startCLI = require('../common/debugger');
const assert = require('assert');
// Test for files that start with strict directive.
{
const script = fixtures.path('debugger', 'use-strict.js');
const cli = startCLI(['--port=0', script]);
function onFatal(error) {
cli.quit();
throw error;
}
return cli.waitForInitialBreak()
.then(() => cli.waitForPrompt())
.then(() => {
const brk = cli.breakInfo;
assert.match(
`${brk.line}`,
/^(1|2)$/,
'pauses either on strict directive or first "real" line');
})
.then(() => cli.quit())
.then(null, onFatal);
}
@@ -1,20 +0,0 @@
'use strict';
const common = require('../common');
common.skipIfInspectorDisabled();
const fixtures = require('../common/fixtures');
const startCLI = require('../common/debugger');
const assert = require('assert');
const cli = startCLI(['--port=0', fixtures.path('debugger/break.js')]);
(async () => {
await cli.waitForInitialBreak();
await cli.command('watch()');
await cli.waitFor(/ERR_INVALID_ARG_TYPE/);
assert.match(cli.output, /TypeError \[ERR_INVALID_ARG_TYPE\]: The "expression" argument must be of type string\. Received undefined/);
})()
.finally(() => cli.quit())
.then(common.mustCall());
@@ -1,56 +0,0 @@
import { skipIfInspectorDisabled } from '../common/index.mjs';
skipIfInspectorDisabled();
import { path } from '../common/fixtures.mjs';
import startCLI from '../common/debugger.js';
import assert from 'assert';
const script = path('debugger', 'break.js');
const cli = startCLI(['--port=0', script]);
function onFatal(error) {
cli.quit();
throw error;
}
// Stepping through breakpoints.
try {
await cli.waitForInitialBreak();
await cli.waitForPrompt();
await cli.command('watch("x")');
await cli.command('watch("\\"Hello\\"")');
await cli.command('watch("42")');
await cli.command('watch("NaN")');
await cli.command('watch("true")');
await cli.command('watch("[1, 2]")');
await cli.command('watch("process.env")');
await cli.command('watchers');
assert.match(cli.output, /x is not defined/);
assert.match(cli.output, /1: "Hello" = 'Hello'/);
assert.match(cli.output, /2: 42 = 42/);
assert.match(cli.output, /3: NaN = NaN/);
assert.match(cli.output, /4: true = true/);
assert.match(cli.output, /5: \[1, 2\] = \[ 1, 2 \]/);
assert.match(cli.output, /6: process\.env =\n\s+\{[\s\S]+,\n\s+\.\.\. \}/,
'shows "..." for process.env');
await cli.command('unwatch(4)');
await cli.command('unwatch("42")');
await cli.stepCommand('n');
assert.match(cli.output, /0: x = 10/);
assert.match(cli.output, /1: "Hello" = 'Hello'/);
assert.match(cli.output, /2: NaN = NaN/);
assert.match(cli.output, /3: \[1, 2\] = \[ 1, 2 \]/);
assert.match(
cli.output,
/4: process\.env =\n\s+\{[\s\S]+,\n\s+\.\.\. \}/,
'shows "..." for process.env'
);
await cli.quit();
} catch (error) {
onFatal(error);
}