Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 3 commits into from Nov 1, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
59 changes: 21 additions & 38 deletions test/sequential/test-debugger-pid.js
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());