node/test/parallel/test-debugger-invalid-json.mjs
Dario Piotrowicz 29626f8fb8
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>
2025-07-20 17:37:28 +00:00

46 lines
1 KiB
JavaScript

import { skipIfInspectorDisabled, mustCall } from '../common/index.mjs';
skipIfInspectorDisabled();
import startCLI from '../common/debugger.js';
import assert from 'assert';
import http from 'http';
const host = '127.0.0.1';
{
const server = http.createServer((req, res) => {
res.statusCode = 400;
res.end('Bad Request');
});
server.listen(0, mustCall(async () => {
const port = server.address().port;
const cli = startCLI([`${host}:${port}`], [], {}, { randomPort: false });
try {
const code = await cli.quit();
assert.strictEqual(code, 1);
} finally {
server.close();
}
}));
}
{
const server = http.createServer((req, res) => {
res.statusCode = 200;
res.end('some data that is invalid json');
});
server.listen(0, host, mustCall(async () => {
const port = server.address().port;
const cli = startCLI([`${host}:${port}`], [], {}, { randomPort: false });
try {
const code = await cli.quit();
assert.strictEqual(code, 1);
} finally {
server.close();
}
}));
}