From b72b217dec133ce7bbe8d22bb626570b0bb08885 Mon Sep 17 00:00:00 2001 From: Meek Simbule <55823259+meekdenzo@users.noreply.github.com> Date: Sat, 4 Jun 2022 12:55:06 -0400 Subject: [PATCH] test: convert then to async/await MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit PR-URL: https://github.com/nodejs/node/pull/43292 Reviewed-By: Antoine du Hamel Reviewed-By: Michaël Zasso Reviewed-By: Tobias Nießen Reviewed-By: Rich Trott Reviewed-By: Luigi Pinca --- test/parallel/test-debugger-address.js | 25 +++++----- .../test-debugger-extract-function-name.js | 47 +++++++++---------- 2 files changed, 35 insertions(+), 37 deletions(-) diff --git a/test/parallel/test-debugger-address.js b/test/parallel/test-debugger-address.js index bffc28ac916..e8cfd428ebc 100644 --- a/test/parallel/test-debugger-address.js +++ b/test/parallel/test-debugger-address.js @@ -53,21 +53,22 @@ function launchTarget(...args) { assert.ifError(error); } - return launchTarget('--inspect=0', script) - .then(({ childProc, host, port }) => { + (async () => { + try { + const { childProc, host, port } = await launchTarget('--inspect=0', script); target = childProc; cli = startCLI([`${host || '127.0.0.1'}:${port}`]); - return cli.waitForPrompt(); - }) - .then(() => cli.command('sb("alive.js", 3)')) - .then(() => cli.waitFor(/break/)) - .then(() => cli.waitForPrompt()) - .then(() => { + await cli.waitForPrompt(); + await cli.command('sb("alive.js", 3)'); + await cli.waitFor(/break/); + await cli.waitForPrompt(); assert.match( cli.output, /> 3 {3}\+\+x;/, - 'marks the 3rd line'); - }) - .then(() => cleanup()) - .then(null, cleanup); + 'marks the 3rd line' + ); + } finally { + cleanup(); + } + })().then(common.mustCall()); } diff --git a/test/parallel/test-debugger-extract-function-name.js b/test/parallel/test-debugger-extract-function-name.js index aff97ee2954..0f43ae65837 100644 --- a/test/parallel/test-debugger-extract-function-name.js +++ b/test/parallel/test-debugger-extract-function-name.js @@ -10,28 +10,25 @@ const assert = require('assert'); const cli = startCLI([fixtures.path('debugger', 'three-lines.js')]); -function onFatal(error) { - cli.quit(); - throw error; -} - -cli.waitForInitialBreak() - .then(() => cli.waitForPrompt()) - .then(() => cli.command('exec a = function func() {}; a;')) - .then(() => assert.match(cli.output, /\[Function: func\]/)) - .then(() => cli.command('exec a = function func () {}; a;')) - .then(() => assert.match(cli.output, /\[Function\]/)) - .then(() => cli.command('exec a = function() {}; a;')) - .then(() => assert.match(cli.output, /\[Function: function\]/)) - .then(() => cli.command('exec a = () => {}; a;')) - .then(() => assert.match(cli.output, /\[Function\]/)) - .then(() => cli.command('exec a = function* func() {}; a;')) - .then(() => assert.match(cli.output, /\[GeneratorFunction: func\]/)) - .then(() => cli.command('exec a = function *func() {}; a;')) - .then(() => assert.match(cli.output, /\[GeneratorFunction: \*func\]/)) - .then(() => cli.command('exec a = function*func() {}; a;')) - .then(() => assert.match(cli.output, /\[GeneratorFunction: function\*func\]/)) - .then(() => cli.command('exec a = function * func() {}; a;')) - .then(() => assert.match(cli.output, /\[GeneratorFunction\]/)) - .then(() => cli.quit()) - .then(null, onFatal); +(async () => { + await cli.waitForInitialBreak(); + await cli.waitForPrompt(); + await cli.command('exec a = function func() {}; a;'); + assert.match(cli.output, /\[Function: func\]/); + await cli.command('exec a = function func () {}; a;'); + assert.match(cli.output, /\[Function\]/); + await cli.command('exec a = function() {}; a;'); + assert.match(cli.output, /\[Function: function\]/); + await cli.command('exec a = () => {}; a;'); + assert.match(cli.output, /\[Function\]/); + await cli.command('exec a = function* func() {}; a;'); + assert.match(cli.output, /\[GeneratorFunction: func\]/); + await cli.command('exec a = function *func() {}; a;'); + assert.match(cli.output, /\[GeneratorFunction: \*func\]/); + await cli.command('exec a = function*func() {}; a;'); + assert.match(cli.output, /\[GeneratorFunction: function\*func\]/); + await cli.command('exec a = function * func() {}; a;'); + assert.match(cli.output, /\[GeneratorFunction\]/); +})() +.finally(() => cli.quit()) +.then(common.mustCall());