test: convert test-debugger-pid to async/await

PR-URL: https://github.com/nodejs/node/pull/45179
Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
Reviewed-By: Juan José Arboleda <soyjuanarbol@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
This commit is contained in:
Luke Karrys 2022-10-31 22:45:47 -07:00 committed by GitHub
parent 6ccb069c4e
commit 590cf569fe
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -9,44 +9,27 @@ const startCLI = require('../common/debugger');
const assert = require('assert');
const { spawn } = require('child_process');
const script = fixtures.path('debugger', 'alive.js');
function launchTarget(...args) {
const childProc = spawn(process.execPath, args);
return Promise.resolve(childProc);
}
const runTest = async () => {
const target = spawn(process.execPath, [script]);
const cli = startCLI(['-p', `${target.pid}`]);
{
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;
}
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());