From cca253503ebf13c3c04399026ae9310ce5cd8914 Mon Sep 17 00:00:00 2001 From: poorvitusam Date: Tue, 27 Sep 2022 09:52:30 -0700 Subject: [PATCH] test: use async/await in test-debugger-preserve-breaks PR-URL: https://github.com/nodejs/node/pull/44696 Reviewed-By: Stephen Belanger Reviewed-By: Rich Trott --- .../test-debugger-preserve-breaks.js | 79 ++++++++----------- 1 file changed, 32 insertions(+), 47 deletions(-) diff --git a/test/sequential/test-debugger-preserve-breaks.js b/test/sequential/test-debugger-preserve-breaks.js index fbc463af96a1e6..bb0eba961432ec 100644 --- a/test/sequential/test-debugger-preserve-breaks.js +++ b/test/sequential/test-debugger-preserve-breaks.js @@ -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();