Skip to content

Commit c4c7620

Browse files
committed
fixup! make tests more reliable
1 parent 2be395a commit c4c7620

File tree

1 file changed

+27
-17
lines changed

1 file changed

+27
-17
lines changed

src/test/node/node-runtime.test.ts

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -119,10 +119,11 @@ describe('node runtime', () => {
119119
'test.js': ['const message = "hello world!";', 'console.log(message);', 'debugger;'],
120120
});
121121
const chakracore = join(testWorkspace, 'chakracore', 'ChakraCore.Debugger.Sample.exe');
122+
const port = await findOpenPort();
122123
const handle = await r.runScript('test.js', {
123124
runtimeExecutable: chakracore,
124-
runtimeArgs: ['--inspect-brk', '--port', '9229'],
125-
attachSimplePort: 9229,
125+
runtimeArgs: ['--inspect-brk', '--port', `${port}`],
126+
attachSimplePort: port,
126127
continueOnAttach: true,
127128
});
128129

@@ -325,9 +326,10 @@ describe('node runtime', () => {
325326
'test.js': ['setInterval(() => { debugger; }, 500)'],
326327
});
327328

328-
child = spawn('node', ['--inspect', join(testFixturesDir, 'test')]);
329+
const port = await findOpenPort();
330+
child = spawn('node', [`--inspect=${port}`, join(testFixturesDir, 'test')]);
329331
await delay(500); // give it a moment to boot
330-
const handle = await r.attachNode(child.pid!);
332+
const handle = await r.attachNode(child.pid!, { port });
331333
await waitForPause(handle);
332334
handle.assertLog({ substring: true });
333335
});
@@ -339,8 +341,9 @@ describe('node runtime', () => {
339341
'test.js': ['console.log("");', 'debugger;'],
340342
});
341343

342-
child = spawn('node', ['--inspect-brk', join(testFixturesDir, 'test')]);
343-
const handle = await r.attachNode(0, { continueOnAttach: true });
344+
const port = await findOpenPort();
345+
child = spawn('node', [`--inspect-brk=${port}`, join(testFixturesDir, 'test')]);
346+
const handle = await r.attachNode(child.pid!, { continueOnAttach: true, port });
344347
await waitForPause(handle); // pauses on 2nd line, not 1st
345348
handle.assertLog({ substring: true });
346349
});
@@ -350,9 +353,10 @@ describe('node runtime', () => {
350353
'test.js': ['setInterval(() => { debugger; }, 500)'],
351354
});
352355

353-
const handleProm = r.attachNode(0, { port: 9229 });
356+
const port = await findOpenPort();
357+
const handleProm = r.attachNode(0, { port });
354358
await delay(500); // give it a moment to start trying to attach
355-
child = spawn('node', ['--inspect', join(testFixturesDir, 'test')]);
359+
child = spawn('node', [`--inspect=${port}`, join(testFixturesDir, 'test')]);
356360
const handle = await handleProm;
357361
await waitForPause(handle);
358362
handle.assertLog({ substring: true });
@@ -367,9 +371,10 @@ describe('node runtime', () => {
367371
'child.js': '(function foo() { debugger; })();',
368372
});
369373

370-
child = spawn('node', ['--inspect', join(testFixturesDir, 'test')]);
374+
const port = await findOpenPort();
375+
child = spawn('node', [`--inspect=${port}`, join(testFixturesDir, 'test')]);
371376
await delay(500); // give it a moment to boot
372-
const handle = await r.attachNode(child.pid!);
377+
const handle = await r.attachNode(child.pid!, { port });
373378
handle.load();
374379

375380
const worker = await r.worker();
@@ -391,9 +396,10 @@ describe('node runtime', () => {
391396
`,
392397
});
393398

394-
child = spawn('node', ['--inspect', join(testFixturesDir, 'test')]);
399+
const port = await findOpenPort();
400+
child = spawn('node', [`--inspect=${port}`, join(testFixturesDir, 'test')]);
395401
await delay(500); // give it a moment to boot
396-
const handle = await r.attachNode(child.pid!);
402+
const handle = await r.attachNode(child.pid!, { port });
397403
handle.load();
398404

399405
const worker = await r.worker();
@@ -408,13 +414,14 @@ describe('node runtime', () => {
408414
'test.js': ['setInterval(() => { debugger; }, 100)'],
409415
});
410416

411-
child = spawn('node', ['--inspect', join(testFixturesDir, 'test')]);
412-
const handle = await r.attachNode(0, { port: 9229, restart: true });
417+
const port = await findOpenPort();
418+
child = spawn('node', [`--inspect=${port}`, join(testFixturesDir, 'test')]);
419+
const handle = await r.attachNode(0, { port, restart: true });
413420

414421
handle.log(await handle.dap.once('stopped'));
415422
await handle.dap.evaluate({ expression: 'process.exit(0)' });
416423

417-
child = spawn('node', ['--inspect', join(testFixturesDir, 'test')]);
424+
child = spawn('node', [`--inspect=${port}`, join(testFixturesDir, 'test')]);
418425
const reconnect = await r.waitForTopLevel();
419426
reconnect.load();
420427

@@ -427,11 +434,14 @@ describe('node runtime', () => {
427434
'test.js': ['setInterval(() => { debugger; }, 100)'],
428435
});
429436

430-
child = spawn('node', ['--inspect', join(testFixturesDir, 'test')], { stdio: 'pipe' });
437+
const port = await findOpenPort();
438+
child = spawn('node', [`--inspect=${port}`, join(testFixturesDir, 'test')], {
439+
stdio: 'pipe',
440+
});
431441
const lines: string[] = [];
432442
child.stderr?.pipe(split()).on('data', line => lines.push(line));
433443

434-
const handle = await r.attachNode(0, { port: 9229, restart: true });
444+
const handle = await r.attachNode(0, { port, restart: true });
435445
await handle.dap.once('stopped');
436446
await r.rootDap().disconnect({});
437447

0 commit comments

Comments
 (0)