@@ -19,20 +19,21 @@ const filename = path.join(tmpdir.path, 'node.heapsnapshot');
1919 const opts = { cwd: tmpdir.path };
2020 const cli = startCLI([fixtures.path('debugger/empty.js')], [], opts);
2121
22- function onFatal(error) {
23- cli.quit();
24- throw error;
22+ async function waitInitialBreak() {
23+ try {
24+ await cli.waitForInitialBreak();
25+ await cli.waitForPrompt();
26+ await cli.command('takeHeapSnapshot()');
27+ JSON.parse(readFileSync(filename, 'utf8'));
28+ // Check that two simultaneous snapshots don't step all over each other.
29+ // Refs: https://github.com/nodejs/node/issues/39555
30+ await cli.command('takeHeapSnapshot(); takeHeapSnapshot()');
31+ JSON.parse(readFileSync(filename, 'utf8'));
32+ } finally {
33+ await cli.quit();
34+ }
2535 }
2636
2737 // Check that the snapshot is valid JSON.
28- return cli.waitForInitialBreak()
29- .then(() => cli.waitForPrompt())
30- .then(() => cli.command('takeHeapSnapshot()'))
31- .then(() => JSON.parse(readFileSync(filename, 'utf8')))
32- // Check that two simultaneous snapshots don't step all over each other.
33- // Refs: https://github.com/nodejs/node/issues/39555
34- .then(() => cli.command('takeHeapSnapshot(); takeHeapSnapshot()'))
35- .then(() => JSON.parse(readFileSync(filename, 'utf8')))
36- .then(() => cli.quit())
37- .then(null, onFatal);
38+ waitInitialBreak().then(common.mustCall());
3839}
0 commit comments