mirror of
https://github.com/nodejs/node.git
synced 2025-08-15 13:48:44 +02:00
test: update startCLI
to set --port=0
by default
update the `startCLI` debugging testing utility to set by default the port to use to `0` (i.e. a random port) PR-URL: https://github.com/nodejs/node/pull/59042 Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
This commit is contained in:
parent
bf2384f224
commit
29626f8fb8
35 changed files with 43 additions and 41 deletions
|
@ -20,10 +20,14 @@ function isPreBreak(output) {
|
|||
return /Break on start/.test(output) && /1 \(function \(exports/.test(output);
|
||||
}
|
||||
|
||||
function startCLI(args, flags = [], spawnOpts = {}) {
|
||||
function startCLI(args, flags = [], spawnOpts = {}, opts = { randomPort: true }) {
|
||||
let stderrOutput = '';
|
||||
const child =
|
||||
spawn(process.execPath, [...flags, 'inspect', ...args], spawnOpts);
|
||||
const child = spawn(process.execPath, [
|
||||
...flags,
|
||||
'inspect',
|
||||
...(opts.randomPort !== false ? ['--port=0'] : []),
|
||||
...args,
|
||||
], spawnOpts);
|
||||
|
||||
const outputBuffer = [];
|
||||
function bufferOutput(chunk) {
|
||||
|
|
|
@ -55,7 +55,7 @@ function launchTarget(...args) {
|
|||
try {
|
||||
const { childProc, host, port } = await launchTarget('--inspect=0', script);
|
||||
target = childProc;
|
||||
cli = startCLI([`${host || '127.0.0.1'}:${port}`]);
|
||||
cli = startCLI([`${host || '127.0.0.1'}:${port}`], [], {}, { randomPort: false });
|
||||
await cli.waitForPrompt();
|
||||
await cli.command('sb("alive.js", 3)');
|
||||
await cli.waitFor(/break/);
|
||||
|
|
|
@ -21,9 +21,7 @@ addLibraryPath(process.env);
|
|||
};
|
||||
env.NODE_INSPECT_RESUME_ON_START = '1';
|
||||
|
||||
const cli = startCLI(['--port=0', script], [], {
|
||||
env,
|
||||
});
|
||||
const cli = startCLI([script], [], { env });
|
||||
|
||||
await cli.waitForInitialBreak();
|
||||
deepStrictEqual(cli.breakInfo, {
|
||||
|
|
|
@ -13,7 +13,7 @@ const path = require('path');
|
|||
{
|
||||
const scriptFullPath = fixtures.path('debugger', 'backtrace.js');
|
||||
const script = path.relative(process.cwd(), scriptFullPath);
|
||||
const cli = startCLI(['--port=0', script]);
|
||||
const cli = startCLI([script]);
|
||||
|
||||
async function runTest() {
|
||||
try {
|
||||
|
|
|
@ -11,7 +11,7 @@ const path = require('path');
|
|||
|
||||
const scriptFullPath = fixtures.path('debugger', 'break.js');
|
||||
const script = path.relative(process.cwd(), scriptFullPath);
|
||||
const cli = startCLI(['--port=0', script]);
|
||||
const cli = startCLI([script]);
|
||||
|
||||
(async () => {
|
||||
await cli.waitForInitialBreak();
|
||||
|
|
|
@ -9,7 +9,7 @@ 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]);
|
||||
const cli = startCLI([script]);
|
||||
|
||||
(async () => {
|
||||
try {
|
||||
|
|
|
@ -13,7 +13,7 @@ const path = require('path');
|
|||
{
|
||||
const scriptFullPath = fixtures.path('debugger', 'break.js');
|
||||
const script = path.relative(process.cwd(), scriptFullPath);
|
||||
const cli = startCLI(['--port=0', script]);
|
||||
const cli = startCLI([script]);
|
||||
|
||||
function onFatal(error) {
|
||||
cli.quit();
|
||||
|
|
|
@ -13,7 +13,7 @@ const path = require('path');
|
|||
{
|
||||
const scriptFullPath = fixtures.path('debugger', 'exceptions.js');
|
||||
const script = path.relative(process.cwd(), scriptFullPath);
|
||||
const cli = startCLI(['--port=0', script]);
|
||||
const cli = startCLI([script]);
|
||||
|
||||
(async () => {
|
||||
try {
|
||||
|
|
|
@ -7,7 +7,7 @@ import startCLI from '../common/debugger.js';
|
|||
|
||||
import assert from 'assert';
|
||||
|
||||
const cli = startCLI(['--port=0', path('debugger/backtrace.js')]);
|
||||
const cli = startCLI([path('debugger/backtrace.js')]);
|
||||
|
||||
try {
|
||||
await cli.waitForInitialBreak();
|
||||
|
|
|
@ -8,7 +8,7 @@ const startCLI = require('../common/debugger');
|
|||
|
||||
const assert = require('assert');
|
||||
|
||||
const cli = startCLI(['--port=0', fixtures.path('debugger/alive.js')]);
|
||||
const cli = startCLI([fixtures.path('debugger/alive.js')]);
|
||||
|
||||
async function waitInitialBreak() {
|
||||
try {
|
||||
|
|
|
@ -7,7 +7,7 @@ import startCLI from '../common/debugger.js';
|
|||
|
||||
import assert from 'assert';
|
||||
|
||||
const cli = startCLI(['--port=0', path('debugger', 'three-lines.js')]);
|
||||
const cli = startCLI([path('debugger', 'three-lines.js')]);
|
||||
|
||||
try {
|
||||
await cli.waitForInitialBreak();
|
||||
|
|
|
@ -16,7 +16,7 @@ const filename = tmpdir.resolve('node.heapsnapshot');
|
|||
// Heap profiler take snapshot.
|
||||
{
|
||||
const opts = { cwd: tmpdir.path };
|
||||
const cli = startCLI(['--port=0', fixtures.path('debugger/empty.js')], [], opts);
|
||||
const cli = startCLI([fixtures.path('debugger/empty.js')], [], opts);
|
||||
|
||||
async function waitInitialBreak() {
|
||||
try {
|
||||
|
|
|
@ -7,7 +7,7 @@ import startCLI from '../common/debugger.js';
|
|||
|
||||
import assert from 'assert';
|
||||
|
||||
const cli = startCLI(['--port=0', path('debugger', 'empty.js')]);
|
||||
const cli = startCLI([path('debugger', 'empty.js')]);
|
||||
|
||||
try {
|
||||
await cli.waitForInitialBreak();
|
||||
|
|
|
@ -17,7 +17,7 @@ const host = '127.0.0.1';
|
|||
|
||||
server.listen(0, mustCall(async () => {
|
||||
const port = server.address().port;
|
||||
const cli = startCLI([`${host}:${port}`]);
|
||||
const cli = startCLI([`${host}:${port}`], [], {}, { randomPort: false });
|
||||
try {
|
||||
const code = await cli.quit();
|
||||
assert.strictEqual(code, 1);
|
||||
|
@ -35,7 +35,7 @@ const host = '127.0.0.1';
|
|||
|
||||
server.listen(0, host, mustCall(async () => {
|
||||
const port = server.address().port;
|
||||
const cli = startCLI([`${host}:${port}`]);
|
||||
const cli = startCLI([`${host}:${port}`], [], {}, { randomPort: false });
|
||||
try {
|
||||
const code = await cli.quit();
|
||||
assert.strictEqual(code, 1);
|
||||
|
|
|
@ -8,7 +8,7 @@ const startCLI = require('../common/debugger');
|
|||
|
||||
const assert = require('assert');
|
||||
|
||||
const cli = startCLI(['--port=0', fixtures.path('debugger/three-lines.js')]);
|
||||
const cli = startCLI([fixtures.path('debugger/three-lines.js')]);
|
||||
|
||||
(async () => {
|
||||
await cli.waitForInitialBreak();
|
||||
|
|
|
@ -9,7 +9,7 @@ const assert = require('assert');
|
|||
|
||||
// Debugger agent direct access.
|
||||
{
|
||||
const cli = startCLI(['--port=0', fixtures.path('debugger/three-lines.js')]);
|
||||
const cli = startCLI([fixtures.path('debugger/three-lines.js')]);
|
||||
const scriptPattern = /^\* (\d+): \S+debugger(?:\/|\\)three-lines\.js/m;
|
||||
|
||||
async function testDebuggerLowLevel() {
|
||||
|
|
|
@ -8,7 +8,7 @@ const startCLI = require('../common/debugger');
|
|||
|
||||
const assert = require('assert');
|
||||
|
||||
const cli = startCLI(['--port=0', fixtures.path('debugger/empty.js')]);
|
||||
const cli = startCLI([fixtures.path('debugger/empty.js')]);
|
||||
|
||||
(async () => {
|
||||
await cli.waitForInitialBreak();
|
||||
|
|
|
@ -14,7 +14,7 @@ const script = path.relative(process.cwd(), scriptFullPath);
|
|||
|
||||
// Run after quit.
|
||||
const runTest = async () => {
|
||||
const cli = startCLI(['--port=0', script]);
|
||||
const cli = startCLI([script]);
|
||||
try {
|
||||
await cli.waitForInitialBreak();
|
||||
await cli.waitForPrompt();
|
||||
|
|
|
@ -10,7 +10,7 @@ const assert = require('assert');
|
|||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
|
||||
const cli = startCLI(['--port=0', fixtures.path('debugger/empty.js')]);
|
||||
const cli = startCLI([fixtures.path('debugger/empty.js')]);
|
||||
|
||||
const rootDir = path.resolve(__dirname, '..', '..');
|
||||
|
||||
|
|
|
@ -14,7 +14,7 @@ function delay(ms) {
|
|||
|
||||
// Profiles.
|
||||
{
|
||||
const cli = startCLI(['--port=0', fixtures.path('debugger/empty.js')], [], {
|
||||
const cli = startCLI([fixtures.path('debugger/empty.js')], [], {
|
||||
env: {
|
||||
...process.env,
|
||||
// When this test is run with NODE_V8_COVERAGE, it clobbers the inspector
|
||||
|
|
|
@ -10,7 +10,7 @@ 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]);
|
||||
const cli = startCLI(['--inspect-port=0', script], [], {}, { randomPort: false });
|
||||
|
||||
(async () => {
|
||||
await cli.waitForInitialBreak();
|
||||
|
|
|
@ -12,7 +12,7 @@ const assert = require('assert');
|
|||
{
|
||||
const script = fixtures.path('debugger', 'three-lines.js');
|
||||
|
||||
const cli = startCLI(['--port=0', script]);
|
||||
const cli = startCLI([script]);
|
||||
|
||||
cli.waitForInitialBreak()
|
||||
.then(() => cli.waitForPrompt())
|
||||
|
|
|
@ -14,7 +14,7 @@ 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 cli = startCLI([script]);
|
||||
|
||||
const listeningRegExp = /Debugger listening on/g;
|
||||
|
||||
|
|
|
@ -13,7 +13,7 @@ const path = require('path');
|
|||
{
|
||||
const scriptFullPath = fixtures.path('debugger', 'three-lines.js');
|
||||
const script = path.relative(process.cwd(), scriptFullPath);
|
||||
const cli = startCLI(['--port=0', script]);
|
||||
const cli = startCLI([script]);
|
||||
|
||||
function onFatal(error) {
|
||||
cli.quit();
|
||||
|
|
|
@ -17,7 +17,7 @@ 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]);
|
||||
const cli = startCLI([script]);
|
||||
|
||||
(async () => {
|
||||
await cli.waitForInitialBreak();
|
||||
|
|
|
@ -11,7 +11,7 @@ const assert = require('assert');
|
|||
// List scripts.
|
||||
{
|
||||
const script = fixtures.path('debugger', 'three-lines.js');
|
||||
const cli = startCLI(['--port=0', script]);
|
||||
const cli = startCLI([script]);
|
||||
|
||||
(async () => {
|
||||
try {
|
||||
|
|
|
@ -7,7 +7,7 @@ import startCLI from '../common/debugger.js';
|
|||
import assert from 'assert';
|
||||
|
||||
const script = path('debugger', 'twenty-lines.js');
|
||||
const cli = startCLI(['--port=0', script]);
|
||||
const cli = startCLI([script]);
|
||||
|
||||
function onFatal(error) {
|
||||
cli.quit();
|
||||
|
|
|
@ -19,7 +19,7 @@ const { createServer } = require('net');
|
|||
|
||||
try {
|
||||
const script = fixtures.path('debugger', 'three-lines.js');
|
||||
const cli = startCLI([`--port=${port}`, script]);
|
||||
const cli = startCLI([`--port=${port}`, script], [], {}, { randomPort: false });
|
||||
const code = await cli.quit();
|
||||
|
||||
assert.doesNotMatch(
|
||||
|
|
|
@ -11,7 +11,7 @@ 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]);
|
||||
const cli = startCLI([script]);
|
||||
|
||||
function onFatal(error) {
|
||||
cli.quit();
|
||||
|
|
|
@ -8,7 +8,7 @@ const startCLI = require('../common/debugger');
|
|||
|
||||
const assert = require('assert');
|
||||
|
||||
const cli = startCLI(['--port=0', fixtures.path('debugger/break.js')]);
|
||||
const cli = startCLI([fixtures.path('debugger/break.js')]);
|
||||
|
||||
(async () => {
|
||||
await cli.waitForInitialBreak();
|
||||
|
|
|
@ -7,7 +7,7 @@ import startCLI from '../common/debugger.js';
|
|||
import assert from 'assert';
|
||||
|
||||
const script = path('debugger', 'break.js');
|
||||
const cli = startCLI(['--port=0', script]);
|
||||
const cli = startCLI([script]);
|
||||
|
||||
function onFatal(error) {
|
||||
cli.quit();
|
||||
|
|
|
@ -11,7 +11,7 @@ const assert = require('assert');
|
|||
// Custom port.
|
||||
const script = fixtures.path('debugger', 'three-lines.js');
|
||||
|
||||
const cli = startCLI([`--port=${common.PORT}`, script]);
|
||||
const cli = startCLI([`--port=${common.PORT}`, script], [], {}, { randomPort: false });
|
||||
(async function() {
|
||||
try {
|
||||
await cli.waitForInitialBreak();
|
||||
|
|
|
@ -9,7 +9,7 @@ const assert = require('assert');
|
|||
|
||||
// Launch CLI w/o args.
|
||||
(async () => {
|
||||
const cli = startCLI([]);
|
||||
const cli = startCLI([], [], {}, { randomPort: false });
|
||||
const code = await cli.quit();
|
||||
assert.strictEqual(code, 9);
|
||||
assert.match(cli.output, /^Usage:/, 'Prints usage info');
|
||||
|
@ -17,7 +17,7 @@ const assert = require('assert');
|
|||
|
||||
// Launch w/ invalid host:port.
|
||||
(async () => {
|
||||
const cli = startCLI([`localhost:${common.PORT}`]);
|
||||
const cli = startCLI([`localhost:${common.PORT}`], [], {}, { randomPort: false });
|
||||
const code = await cli.quit();
|
||||
assert.match(
|
||||
cli.output,
|
||||
|
|
|
@ -8,7 +8,7 @@ import startCLI from '../common/debugger.js';
|
|||
import assert from 'assert';
|
||||
|
||||
const script = path('debugger', 'three-lines.js');
|
||||
const cli = startCLI([script]);
|
||||
const cli = startCLI([script], [], {}, { randomPort: false });
|
||||
try {
|
||||
await cli.waitForInitialBreak();
|
||||
await cli.waitForPrompt();
|
||||
|
|
|
@ -13,7 +13,7 @@ const script = fixtures.path('debugger', 'alive.js');
|
|||
|
||||
const runTest = async () => {
|
||||
const target = spawn(process.execPath, [script]);
|
||||
const cli = startCLI(['-p', `${target.pid}`]);
|
||||
const cli = startCLI(['-p', `${target.pid}`], [], {}, { randomPort: false });
|
||||
|
||||
try {
|
||||
await cli.waitForPrompt();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue