From ddf029725b986362651dfe41723eb8d93ff04fa8 Mon Sep 17 00:00:00 2001 From: Brinda Ashar Date: Fri, 16 Sep 2022 17:47:04 -0400 Subject: [PATCH] test: use async/await in test-debugger-heap-profiler PR-URL: https://github.com/nodejs/node/pull/44693 Reviewed-By: Rich Trott --- .../sequential/test-debugger-heap-profiler.js | 27 ++++++++++--------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/test/sequential/test-debugger-heap-profiler.js b/test/sequential/test-debugger-heap-profiler.js index 86eb9d9d0d232f..dfec0fe10d5a36 100644 --- a/test/sequential/test-debugger-heap-profiler.js +++ b/test/sequential/test-debugger-heap-profiler.js @@ -19,20 +19,21 @@ const filename = path.join(tmpdir.path, 'node.heapsnapshot'); const opts = { cwd: tmpdir.path }; const cli = startCLI([fixtures.path('debugger/empty.js')], [], opts); - function onFatal(error) { - cli.quit(); - throw error; + async function waitInitialBreak() { + try { + await cli.waitForInitialBreak(); + await cli.waitForPrompt(); + await cli.command('takeHeapSnapshot()'); + JSON.parse(readFileSync(filename, 'utf8')); + // Check that two simultaneous snapshots don't step all over each other. + // Refs: https://github.com/nodejs/node/issues/39555 + await cli.command('takeHeapSnapshot(); takeHeapSnapshot()'); + JSON.parse(readFileSync(filename, 'utf8')); + } finally { + await cli.quit(); + } } // Check that the snapshot is valid JSON. - return cli.waitForInitialBreak() - .then(() => cli.waitForPrompt()) - .then(() => cli.command('takeHeapSnapshot()')) - .then(() => JSON.parse(readFileSync(filename, 'utf8'))) - // Check that two simultaneous snapshots don't step all over each other. - // Refs: https://github.com/nodejs/node/issues/39555 - .then(() => cli.command('takeHeapSnapshot(); takeHeapSnapshot()')) - .then(() => JSON.parse(readFileSync(filename, 'utf8'))) - .then(() => cli.quit()) - .then(null, onFatal); + waitInitialBreak().then(common.mustCall()); }