From 1819974ea762737e52f7c88e934af4cfc4501a72 Mon Sep 17 00:00:00 2001 From: poorvitusam Date: Fri, 16 Sep 2022 15:20:57 -0700 Subject: [PATCH] update promise to async/await --- .../test-debugger-preserve-breaks.js | 76 ++++++++----------- 1 file changed, 32 insertions(+), 44 deletions(-) diff --git a/test/sequential/test-debugger-preserve-breaks.js b/test/sequential/test-debugger-preserve-breaks.js index fbc463af96a1e6..d76fd4d38a9fa5 100644 --- a/test/sequential/test-debugger-preserve-breaks.js +++ b/test/sequential/test-debugger-preserve-breaks.js @@ -9,54 +9,42 @@ 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]); + 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); - function onFatal(error) { + await cli.quit(); + } catch (error) { cli.quit(); throw error; } +}; - 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();