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:
Madhuri 2022-10-14 23:20:32 +05:30 committed by GitHub
parent bda460df94
commit fe520f80c9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -9,123 +9,102 @@ 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 script = path.relative(process.cwd(), scriptFullPath);
const scriptFullPath = fixtures.path('debugger', 'break.js'); const cli = startCLI([script]);
const script = path.relative(process.cwd(), scriptFullPath);
const cli = startCLI([script]);
function onFatal(error) { (async () => {
cli.quit(); await cli.waitForInitialBreak();
throw error; await cli.waitForPrompt();
} assert.deepStrictEqual(
cli.breakInfo,
{ filename: script, line: 1 },
);
assert.match(
cli.output,
/> 1 (?:\(function \([^)]+\) \{ )?const x = 10;/,
'shows the source and marks the current line');
cli.waitForInitialBreak() await cli.stepCommand('n');
.then(() => cli.waitForPrompt()) assert.ok(
.then(() => { cli.output.includes(`break in ${script}:2`),
assert.deepStrictEqual( 'pauses in next line of the script');
cli.breakInfo, assert.match(
{ filename: script, line: 1 }, cli.output,
); /> 2 let name = 'World';/,
assert.match( 'marks the 2nd line');
cli.output,
/> 1 (?:\(function \([^)]+\) \{ )?const x = 10;/,
'shows the source and marks the current line');
})
.then(() => cli.stepCommand('n'))
.then(() => {
assert.ok(
cli.output.includes(`break in ${script}:2`),
'pauses in next line of the script');
assert.match(
cli.output,
/> 2 let name = 'World';/,
'marks the 2nd line');
})
.then(() => cli.stepCommand('next'))
.then(() => {
assert.ok(
cli.output.includes(`break in ${script}:3`),
'pauses in next line of the script');
assert.match(
cli.output,
/> 3 name = 'Robin';/,
'marks the 3nd line');
})
.then(() => cli.stepCommand('cont'))
.then(() => {
assert.ok(
cli.output.includes(`break in ${script}:10`),
'pauses on the next breakpoint');
assert.match(
cli.output,
/>10 debugger;/,
'marks the debugger line');
})
// Prepare additional breakpoints await cli.stepCommand('next');
.then(() => cli.command('sb("break.js", 6)')) assert.ok(
.then(() => assert.doesNotMatch(cli.output, /Could not resolve breakpoint/)) cli.output.includes(`break in ${script}:3`),
.then(() => cli.command('sb("otherFunction()")')) 'pauses in next line of the script');
.then(() => cli.command('sb(16)')) assert.match(
.then(() => assert.doesNotMatch(cli.output, /Could not resolve breakpoint/)) cli.output,
.then(() => cli.command('breakpoints')) /> 3 name = 'Robin';/,
.then(() => { 'marks the 3nd line');
assert.ok(cli.output.includes(`#0 ${script}:6`));
assert.ok(cli.output.includes(`#1 ${script}:16`));
})
.then(() => cli.command('list()')) await cli.stepCommand('cont');
.then(() => { assert.ok(
assert.match( cli.output.includes(`break in ${script}:10`),
cli.output, 'pauses on the next breakpoint');
/>10 debugger;/, assert.match(
'prints and marks current line' cli.output,
); />10 debugger;/,
assert.deepStrictEqual( 'marks the debugger line');
cli.parseSourceLines(),
[5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],
);
})
.then(() => cli.command('list(2)'))
.then(() => {
assert.match(
cli.output,
/>10 debugger;/,
'prints and marks current line'
);
assert.deepStrictEqual(
cli.parseSourceLines(),
[8, 9, 10, 11, 12],
);
})
.then(() => cli.stepCommand('s')) await cli.command('sb("break.js", 6)');
.then(() => cli.stepCommand('')) assert.doesNotMatch(cli.output, /Could not resolve breakpoint/);
.then(() => {
assert.match( await cli.command('sb("otherFunction()")');
cli.output, await cli.command('sb(16)');
/break in node:timers/, assert.doesNotMatch(cli.output, /Could not resolve breakpoint/);
'entered timers.js');
}) await cli.command('breakpoints');
.then(() => cli.stepCommand('cont')) assert.ok(cli.output.includes(`#0 ${script}:6`));
.then(() => { assert.ok(cli.output.includes(`#1 ${script}:16`));
assert.ok(
cli.output.includes(`break in ${script}:16`), await cli.command('list()');
'found breakpoint we set above w/ line number only'); assert.match(
}) cli.output,
.then(() => cli.stepCommand('cont')) />10 debugger;/,
.then(() => { 'prints and marks current line'
assert.ok( );
cli.output.includes(`break in ${script}:6`), assert.deepStrictEqual(
'found breakpoint we set above w/ line number & script'); cli.parseSourceLines(),
}) [5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],
.then(() => cli.stepCommand('')) );
.then(() => {
assert.ok( await cli.command('list(2)');
cli.output.includes(`debugCommand in ${script}:14`), assert.match(
'found function breakpoint we set above'); cli.output,
}) />10 debugger;/,
.then(() => cli.quit()) 'prints and marks current line'
.then(null, onFatal); );
} assert.deepStrictEqual(
cli.parseSourceLines(),
[8, 9, 10, 11, 12],
);
await cli.stepCommand('s');
await cli.stepCommand('');
assert.match(
cli.output,
/break in node:timers/,
'entered timers.js');
await cli.stepCommand('cont');
assert.ok(
cli.output.includes(`break in ${script}:16`),
'found breakpoint we set above w/ line number only');
await cli.stepCommand('cont');
assert.ok(
cli.output.includes(`break in ${script}:6`),
'found breakpoint we set above w/ line number & script');
await cli.stepCommand('');
assert.ok(
cli.output.includes(`debugCommand in ${script}:14`),
'found function breakpoint we set above');
})().finally(() => cli.quit())
.then(common.mustCall());