Skip to content

test: update startCLI to set --port=0 by default #59042

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions test/common/debugger.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-debugger-address.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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/);
Expand Down
4 changes: 1 addition & 3 deletions test/parallel/test-debugger-auto-resume.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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, {
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-debugger-backtrace.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-debugger-break.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-debugger-breakpoint-exists.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-debugger-clear-breakpoints.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-debugger-exceptions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-debugger-exec-scope.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-debugger-exec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-debugger-extract-function-name.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-debugger-heap-profiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-debugger-help.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
4 changes: 2 additions & 2 deletions test/parallel/test-debugger-invalid-json.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-debugger-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-debugger-low-level.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-debugger-object-type-remote-object.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-debugger-preserve-breaks.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-debugger-profile-command.js
Original file line number Diff line number Diff line change
Expand Up @@ -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, '..', '..');

Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-debugger-profile.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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([script]);

(async () => {
await cli.waitForInitialBreak();
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-debugger-random-port.js
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-debugger-restart-message.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-debugger-run-after-quit-restart.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-debugger-sb-before-load.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-debugger-scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-debugger-set-context-line-number.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-debugger-unavailable-port.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-debugger-use-strict.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-debugger-watch-validation.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-debugger-watchers.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion test/sequential/test-debugger-custom-port.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
4 changes: 2 additions & 2 deletions test/sequential/test-debugger-invalid-args.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ 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');
})().then(common.mustCall());

// 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,
Expand Down
2 changes: 1 addition & 1 deletion test/sequential/test-debugger-launch.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion test/sequential/test-debugger-pid.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Loading