• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1'use strict';
2const common = require('../common');
3
4common.skipIfInspectorDisabled();
5
6const fixtures = require('../common/fixtures');
7const startCLI = require('../common/debugger');
8const tmpdir = require('../common/tmpdir');
9const path = require('path');
10
11tmpdir.refresh();
12
13const { readFileSync } = require('fs');
14
15const filename = path.join(tmpdir.path, 'node.heapsnapshot');
16
17// Heap profiler take snapshot.
18{
19  const opts = { cwd: tmpdir.path };
20  const cli = startCLI([fixtures.path('debugger/empty.js')], [], opts);
21
22  function onFatal(error) {
23    cli.quit();
24    throw error;
25  }
26
27  // 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}
39