Skip to content

Commit

Permalink
test: use async/await in test-debugger-preserve-breaks
Browse files Browse the repository at this point in the history
PR-URL: #44696
Reviewed-By: Stephen Belanger <admin@stephenbelanger.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
  • Loading branch information
poorvitusam authored and danielleadams committed Oct 5, 2022
1 parent 0b2e8b1 commit cca2535
Showing 1 changed file with 32 additions and 47 deletions.
79 changes: 32 additions & 47 deletions test/sequential/test-debugger-preserve-breaks.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,54 +9,39 @@ const startCLI = require('../common/debugger');
const assert = require('assert');
const path = require('path');

const scriptFullPath = fixtures.path('debugger', 'three-lines.js');
const script = path.relative(process.cwd(), scriptFullPath);

// Run after quit.
{
const scriptFullPath = fixtures.path('debugger', 'three-lines.js');
const script = path.relative(process.cwd(), scriptFullPath);
const runTest = async () => {
const cli = startCLI([script]);

function onFatal(error) {
cli.quit();
throw error;
try {
await cli.waitForInitialBreak();
await cli.waitForPrompt();
await cli.command('breakpoints');
assert.match(cli.output, /No breakpoints yet/);
await cli.command('sb(2)');
await cli.command('sb(3)');
await cli.command('breakpoints');
assert.ok(cli.output.includes(`#0 ${script}:2`));
assert.ok(cli.output.includes(`#1 ${script}:3`));
await cli.stepCommand('c'); // hit line 2
await cli.stepCommand('c'); // hit line 3
assert.deepStrictEqual(cli.breakInfo, { filename: script, line: 3 });
await cli.command('restart');
await cli.waitForInitialBreak();
assert.deepStrictEqual(cli.breakInfo, { filename: script, line: 1 });
await cli.stepCommand('c');
assert.deepStrictEqual(cli.breakInfo, { filename: script, line: 2 });
await cli.stepCommand('c');
assert.deepStrictEqual(cli.breakInfo, { filename: script, line: 3 });
await cli.command('breakpoints');
const msg = `SCRIPT: ${script}, OUTPUT: ${cli.output}`;
assert.ok(cli.output.includes(`#0 ${script}:2`), msg);
assert.ok(cli.output.includes(`#1 ${script}:3`), msg);
} finally {
await cli.quit();
}
};

return cli.waitForInitialBreak()
.then(() => cli.waitForPrompt())
.then(() => cli.command('breakpoints'))
.then(() => {
assert.match(cli.output, /No breakpoints yet/);
})
.then(() => cli.command('sb(2)'))
.then(() => cli.command('sb(3)'))
.then(() => cli.command('breakpoints'))
.then(() => {
assert.ok(cli.output.includes(`#0 ${script}:2`));
assert.ok(cli.output.includes(`#1 ${script}:3`));
})
.then(() => cli.stepCommand('c')) // hit line 2
.then(() => cli.stepCommand('c')) // hit line 3
.then(() => {
assert.deepStrictEqual(cli.breakInfo, { filename: script, line: 3 });
})
.then(() => cli.command('restart'))
.then(() => cli.waitForInitialBreak())
.then(() => {
assert.deepStrictEqual(cli.breakInfo, { filename: script, line: 1 });
})
.then(() => cli.stepCommand('c'))
.then(() => {
assert.deepStrictEqual(cli.breakInfo, { filename: script, line: 2 });
})
.then(() => cli.stepCommand('c'))
.then(() => {
assert.deepStrictEqual(cli.breakInfo, { filename: script, line: 3 });
})
.then(() => cli.command('breakpoints'))
.then(() => {
const msg = `SCRIPT: ${script}, OUTPUT: ${cli.output}`;
assert.ok(cli.output.includes(`#0 ${script}:2`), msg);
assert.ok(cli.output.includes(`#1 ${script}:3`), msg);
})
.then(() => cli.quit())
.then(null, onFatal);
}
runTest();

0 comments on commit cca2535

Please sign in to comment.