summaryrefslogtreecommitdiff
path: root/deps/node/deps/node-inspect/test/cli/heap-profiler.test.js
blob: ebd734e03cb06d1a0bebd40d2c58801c6f0c10bc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
'use strict';
const { test } = require('tap');
const { readFileSync, unlinkSync } = require('fs');

const startCLI = require('./start-cli');
const filename = 'node.heapsnapshot';

function cleanup() {
  try {
    unlinkSync(filename);
  } catch (_) {
    // Ignore.
  }
}

cleanup();

test('Heap profiler take snapshot', (t) => {
  const cli = startCLI(['examples/empty.js']);

  function onFatal(error) {
    cli.quit();
    throw error;
  }

  // Check that the snapshot is valid JSON.
  return cli.waitForInitialBreak()
    .then(() => cli.waitForPrompt())
    .then(() => cli.command('takeHeapSnapshot()'))
    .then(() => JSON.parse(readFileSync(filename, 'utf8')))
    .then(() => cleanup())
    .then(() => cli.quit())
    .then(null, onFatal);
});