test: refactor promises to async/await
PR-URL: https://github.com/nodejs/node/pull/44980 Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Danielle Adams <adamzdanielle@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Anto Aravinth <anto.aravinth.cse@gmail.com>
This commit is contained in:
parent
bda460df94
commit
fe520f80c9
@ -9,20 +9,13 @@ const startCLI = require('../common/debugger');
|
|||||||
const assert = require('assert');
|
const assert = require('assert');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
|
|
||||||
// Stepping through breakpoints.
|
|
||||||
{
|
|
||||||
const scriptFullPath = fixtures.path('debugger', 'break.js');
|
const scriptFullPath = fixtures.path('debugger', 'break.js');
|
||||||
const script = path.relative(process.cwd(), scriptFullPath);
|
const script = path.relative(process.cwd(), scriptFullPath);
|
||||||
const cli = startCLI([script]);
|
const cli = startCLI([script]);
|
||||||
|
|
||||||
function onFatal(error) {
|
(async () => {
|
||||||
cli.quit();
|
await cli.waitForInitialBreak();
|
||||||
throw error;
|
await cli.waitForPrompt();
|
||||||
}
|
|
||||||
|
|
||||||
cli.waitForInitialBreak()
|
|
||||||
.then(() => cli.waitForPrompt())
|
|
||||||
.then(() => {
|
|
||||||
assert.deepStrictEqual(
|
assert.deepStrictEqual(
|
||||||
cli.breakInfo,
|
cli.breakInfo,
|
||||||
{ filename: script, line: 1 },
|
{ filename: script, line: 1 },
|
||||||
@ -31,9 +24,8 @@ const path = require('path');
|
|||||||
cli.output,
|
cli.output,
|
||||||
/> 1 (?:\(function \([^)]+\) \{ )?const x = 10;/,
|
/> 1 (?:\(function \([^)]+\) \{ )?const x = 10;/,
|
||||||
'shows the source and marks the current line');
|
'shows the source and marks the current line');
|
||||||
})
|
|
||||||
.then(() => cli.stepCommand('n'))
|
await cli.stepCommand('n');
|
||||||
.then(() => {
|
|
||||||
assert.ok(
|
assert.ok(
|
||||||
cli.output.includes(`break in ${script}:2`),
|
cli.output.includes(`break in ${script}:2`),
|
||||||
'pauses in next line of the script');
|
'pauses in next line of the script');
|
||||||
@ -41,9 +33,8 @@ const path = require('path');
|
|||||||
cli.output,
|
cli.output,
|
||||||
/> 2 let name = 'World';/,
|
/> 2 let name = 'World';/,
|
||||||
'marks the 2nd line');
|
'marks the 2nd line');
|
||||||
})
|
|
||||||
.then(() => cli.stepCommand('next'))
|
await cli.stepCommand('next');
|
||||||
.then(() => {
|
|
||||||
assert.ok(
|
assert.ok(
|
||||||
cli.output.includes(`break in ${script}:3`),
|
cli.output.includes(`break in ${script}:3`),
|
||||||
'pauses in next line of the script');
|
'pauses in next line of the script');
|
||||||
@ -51,9 +42,8 @@ const path = require('path');
|
|||||||
cli.output,
|
cli.output,
|
||||||
/> 3 name = 'Robin';/,
|
/> 3 name = 'Robin';/,
|
||||||
'marks the 3nd line');
|
'marks the 3nd line');
|
||||||
})
|
|
||||||
.then(() => cli.stepCommand('cont'))
|
await cli.stepCommand('cont');
|
||||||
.then(() => {
|
|
||||||
assert.ok(
|
assert.ok(
|
||||||
cli.output.includes(`break in ${script}:10`),
|
cli.output.includes(`break in ${script}:10`),
|
||||||
'pauses on the next breakpoint');
|
'pauses on the next breakpoint');
|
||||||
@ -61,22 +51,19 @@ const path = require('path');
|
|||||||
cli.output,
|
cli.output,
|
||||||
/>10 debugger;/,
|
/>10 debugger;/,
|
||||||
'marks the debugger line');
|
'marks the debugger line');
|
||||||
})
|
|
||||||
|
|
||||||
// Prepare additional breakpoints
|
await cli.command('sb("break.js", 6)');
|
||||||
.then(() => cli.command('sb("break.js", 6)'))
|
assert.doesNotMatch(cli.output, /Could not resolve breakpoint/);
|
||||||
.then(() => assert.doesNotMatch(cli.output, /Could not resolve breakpoint/))
|
|
||||||
.then(() => cli.command('sb("otherFunction()")'))
|
await cli.command('sb("otherFunction()")');
|
||||||
.then(() => cli.command('sb(16)'))
|
await cli.command('sb(16)');
|
||||||
.then(() => assert.doesNotMatch(cli.output, /Could not resolve breakpoint/))
|
assert.doesNotMatch(cli.output, /Could not resolve breakpoint/);
|
||||||
.then(() => cli.command('breakpoints'))
|
|
||||||
.then(() => {
|
await cli.command('breakpoints');
|
||||||
assert.ok(cli.output.includes(`#0 ${script}:6`));
|
assert.ok(cli.output.includes(`#0 ${script}:6`));
|
||||||
assert.ok(cli.output.includes(`#1 ${script}:16`));
|
assert.ok(cli.output.includes(`#1 ${script}:16`));
|
||||||
})
|
|
||||||
|
|
||||||
.then(() => cli.command('list()'))
|
await cli.command('list()');
|
||||||
.then(() => {
|
|
||||||
assert.match(
|
assert.match(
|
||||||
cli.output,
|
cli.output,
|
||||||
/>10 debugger;/,
|
/>10 debugger;/,
|
||||||
@ -86,9 +73,8 @@ const path = require('path');
|
|||||||
cli.parseSourceLines(),
|
cli.parseSourceLines(),
|
||||||
[5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],
|
[5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],
|
||||||
);
|
);
|
||||||
})
|
|
||||||
.then(() => cli.command('list(2)'))
|
await cli.command('list(2)');
|
||||||
.then(() => {
|
|
||||||
assert.match(
|
assert.match(
|
||||||
cli.output,
|
cli.output,
|
||||||
/>10 debugger;/,
|
/>10 debugger;/,
|
||||||
@ -98,34 +84,27 @@ const path = require('path');
|
|||||||
cli.parseSourceLines(),
|
cli.parseSourceLines(),
|
||||||
[8, 9, 10, 11, 12],
|
[8, 9, 10, 11, 12],
|
||||||
);
|
);
|
||||||
})
|
|
||||||
|
|
||||||
.then(() => cli.stepCommand('s'))
|
await cli.stepCommand('s');
|
||||||
.then(() => cli.stepCommand(''))
|
await cli.stepCommand('');
|
||||||
.then(() => {
|
|
||||||
assert.match(
|
assert.match(
|
||||||
cli.output,
|
cli.output,
|
||||||
/break in node:timers/,
|
/break in node:timers/,
|
||||||
'entered timers.js');
|
'entered timers.js');
|
||||||
})
|
|
||||||
.then(() => cli.stepCommand('cont'))
|
await cli.stepCommand('cont');
|
||||||
.then(() => {
|
|
||||||
assert.ok(
|
assert.ok(
|
||||||
cli.output.includes(`break in ${script}:16`),
|
cli.output.includes(`break in ${script}:16`),
|
||||||
'found breakpoint we set above w/ line number only');
|
'found breakpoint we set above w/ line number only');
|
||||||
})
|
|
||||||
.then(() => cli.stepCommand('cont'))
|
await cli.stepCommand('cont');
|
||||||
.then(() => {
|
|
||||||
assert.ok(
|
assert.ok(
|
||||||
cli.output.includes(`break in ${script}:6`),
|
cli.output.includes(`break in ${script}:6`),
|
||||||
'found breakpoint we set above w/ line number & script');
|
'found breakpoint we set above w/ line number & script');
|
||||||
})
|
|
||||||
.then(() => cli.stepCommand(''))
|
await cli.stepCommand('');
|
||||||
.then(() => {
|
|
||||||
assert.ok(
|
assert.ok(
|
||||||
cli.output.includes(`debugCommand in ${script}:14`),
|
cli.output.includes(`debugCommand in ${script}:14`),
|
||||||
'found function breakpoint we set above');
|
'found function breakpoint we set above');
|
||||||
})
|
})().finally(() => cli.quit())
|
||||||
.then(() => cli.quit())
|
.then(common.mustCall());
|
||||||
.then(null, onFatal);
|
|
||||||
}
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user