Skip to content

Commit 510365a

Browse files
poorvitusamjuanarbol
authored andcommitted
test: use async/await in test-debugger-preserve-breaks
PR-URL: #44696 Reviewed-By: Stephen Belanger <[email protected]> Reviewed-By: Rich Trott <[email protected]>
1 parent 2baa3c3 commit 510365a

File tree

1 file changed

+32
-47
lines changed

1 file changed

+32
-47
lines changed

test/sequential/test-debugger-preserve-breaks.js

+32-47
Original file line numberDiff line numberDiff line change
@@ -9,54 +9,39 @@ const startCLI = require('../common/debugger');
99
const assert = require('assert');
1010
const path = require('path');
1111

12+
const scriptFullPath = fixtures.path('debugger', 'three-lines.js');
13+
const script = path.relative(process.cwd(), scriptFullPath);
14+
1215
// Run after quit.
13-
{
14-
const scriptFullPath = fixtures.path('debugger', 'three-lines.js');
15-
const script = path.relative(process.cwd(), scriptFullPath);
16+
const runTest = async () => {
1617
const cli = startCLI([script]);
17-
18-
function onFatal(error) {
19-
cli.quit();
20-
throw error;
18+
try {
19+
await cli.waitForInitialBreak();
20+
await cli.waitForPrompt();
21+
await cli.command('breakpoints');
22+
assert.match(cli.output, /No breakpoints yet/);
23+
await cli.command('sb(2)');
24+
await cli.command('sb(3)');
25+
await cli.command('breakpoints');
26+
assert.ok(cli.output.includes(`#0 ${script}:2`));
27+
assert.ok(cli.output.includes(`#1 ${script}:3`));
28+
await cli.stepCommand('c'); // hit line 2
29+
await cli.stepCommand('c'); // hit line 3
30+
assert.deepStrictEqual(cli.breakInfo, { filename: script, line: 3 });
31+
await cli.command('restart');
32+
await cli.waitForInitialBreak();
33+
assert.deepStrictEqual(cli.breakInfo, { filename: script, line: 1 });
34+
await cli.stepCommand('c');
35+
assert.deepStrictEqual(cli.breakInfo, { filename: script, line: 2 });
36+
await cli.stepCommand('c');
37+
assert.deepStrictEqual(cli.breakInfo, { filename: script, line: 3 });
38+
await cli.command('breakpoints');
39+
const msg = `SCRIPT: ${script}, OUTPUT: ${cli.output}`;
40+
assert.ok(cli.output.includes(`#0 ${script}:2`), msg);
41+
assert.ok(cli.output.includes(`#1 ${script}:3`), msg);
42+
} finally {
43+
await cli.quit();
2144
}
45+
};
2246

23-
return cli.waitForInitialBreak()
24-
.then(() => cli.waitForPrompt())
25-
.then(() => cli.command('breakpoints'))
26-
.then(() => {
27-
assert.match(cli.output, /No breakpoints yet/);
28-
})
29-
.then(() => cli.command('sb(2)'))
30-
.then(() => cli.command('sb(3)'))
31-
.then(() => cli.command('breakpoints'))
32-
.then(() => {
33-
assert.ok(cli.output.includes(`#0 ${script}:2`));
34-
assert.ok(cli.output.includes(`#1 ${script}:3`));
35-
})
36-
.then(() => cli.stepCommand('c')) // hit line 2
37-
.then(() => cli.stepCommand('c')) // hit line 3
38-
.then(() => {
39-
assert.deepStrictEqual(cli.breakInfo, { filename: script, line: 3 });
40-
})
41-
.then(() => cli.command('restart'))
42-
.then(() => cli.waitForInitialBreak())
43-
.then(() => {
44-
assert.deepStrictEqual(cli.breakInfo, { filename: script, line: 1 });
45-
})
46-
.then(() => cli.stepCommand('c'))
47-
.then(() => {
48-
assert.deepStrictEqual(cli.breakInfo, { filename: script, line: 2 });
49-
})
50-
.then(() => cli.stepCommand('c'))
51-
.then(() => {
52-
assert.deepStrictEqual(cli.breakInfo, { filename: script, line: 3 });
53-
})
54-
.then(() => cli.command('breakpoints'))
55-
.then(() => {
56-
const msg = `SCRIPT: ${script}, OUTPUT: ${cli.output}`;
57-
assert.ok(cli.output.includes(`#0 ${script}:2`), msg);
58-
assert.ok(cli.output.includes(`#1 ${script}:3`), msg);
59-
})
60-
.then(() => cli.quit())
61-
.then(null, onFatal);
62-
}
47+
runTest();

0 commit comments

Comments
 (0)