Skip to content

Commit

Permalink
test: stabilize the inspector-open-dispose test
Browse files Browse the repository at this point in the history
  • Loading branch information
atlowChemi committed Aug 2, 2023
1 parent fb47afc commit 245c42a
Showing 1 changed file with 6 additions and 12 deletions.
18 changes: 6 additions & 12 deletions test/parallel/test-inspector-open-dispose.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,37 +8,31 @@ common.skipIfInspectorDisabled();
if (process.env.BE_CHILD) {
await beChild();
} else {
let firstPort;

const filename = url.fileURLToPath(import.meta.url);
const child = fork(filename, { env: { ...process.env, BE_CHILD: 1 } });

child.once('message', common.mustCall((msg) => {
assert.strictEqual(msg.cmd, 'started');
assert.strictEqual(msg.url, undefined);

child.send({ cmd: 'open', args: [] });
child.send({ cmd: 'open' });
child.once('message', common.mustCall(wasOpenedHandler));
}));

function wasOpenedHandler(msg) {
assert.strictEqual(msg.cmd, 'url');
const port = url.parse(msg.url).port;
const { port } = url.parse(msg.url);
ping(port, common.mustSucceed(() => {
// Inspector is already open, and won't be reopened, so args don't matter.
child.send({ cmd: 'dispose' });
child.once('message', common.mustCall(wasDisposedWhenOpenHandler));
firstPort = port;
}));
}

function wasDisposedWhenOpenHandler(msg) {
async function wasDisposedWhenOpenHandler(msg) {
assert.strictEqual(msg.cmd, 'url');
assert.strictEqual(msg.url, undefined);
ping(firstPort, (err) => {
assert(err);
child.send({ cmd: 'dispose' });
child.once('message', common.mustCall(wasReDisposedHandler));
});
child.send({ cmd: 'dispose' });
child.once('message', common.mustCall(wasReDisposedHandler));
}

function wasReDisposedHandler(msg) {
Expand Down

0 comments on commit 245c42a

Please sign in to comment.