Skip to content

Commit

Permalink
test: convert test-debugger-pid to async/await
Browse files Browse the repository at this point in the history
PR-URL: #45179
Reviewed-By: Moshe Atlow <[email protected]>
Reviewed-By: Juan José Arboleda <[email protected]>
Reviewed-By: Rich Trott <[email protected]>
  • Loading branch information
lukekarrys authored and RafaelGSS committed Nov 10, 2022
1 parent a866e8c commit 7428651
Showing 1 changed file with 21 additions and 38 deletions.
59 changes: 21 additions & 38 deletions test/sequential/test-debugger-pid.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,44 +9,27 @@ const startCLI = require('../common/debugger');
const assert = require('assert');
const { spawn } = require('child_process');


function launchTarget(...args) {
const childProc = spawn(process.execPath, args);
return Promise.resolve(childProc);
}

{
const script = fixtures.path('debugger', 'alive.js');
let cli = null;
let target = null;

function cleanup(error) {
if (cli) {
cli.quit();
cli = null;
}
if (target) {
target.kill();
target = null;
}
const script = fixtures.path('debugger', 'alive.js');

const runTest = async () => {
const target = spawn(process.execPath, [script]);
const cli = startCLI(['-p', `${target.pid}`]);

try {
await cli.waitForPrompt();
await cli.command('sb("alive.js", 3)');
await cli.waitFor(/break/);
await cli.waitForPrompt();
assert.match(
cli.output,
/> 3 {3}\+\+x;/,
'marks the 3rd line');
} catch (error) {
assert.ifError(error);
} finally {
await cli.quit();
target.kill();
}
};

return launchTarget(script)
.then((childProc) => {
target = childProc;
cli = startCLI(['-p', `${target.pid}`]);
return cli.waitForPrompt();
})
.then(() => cli.command('sb("alive.js", 3)'))
.then(() => cli.waitFor(/break/))
.then(() => cli.waitForPrompt())
.then(() => {
assert.match(
cli.output,
/> 3 {3}\+\+x;/,
'marks the 3rd line');
})
.then(() => cleanup())
.then(null, cleanup);
}
runTest().then(common.mustCall());

0 comments on commit 7428651

Please sign in to comment.