• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1'use strict';
2const { test } = require('tap');
3const { readFileSync, unlinkSync } = require('fs');
4
5const startCLI = require('./start-cli');
6const filename = 'node.heapsnapshot';
7
8function cleanup() {
9  try {
10    unlinkSync(filename);
11  } catch (_) {
12    // Ignore.
13  }
14}
15
16cleanup();
17
18test('Heap profiler take snapshot', (t) => {
19  const cli = startCLI(['examples/empty.js']);
20
21  function onFatal(error) {
22    cli.quit();
23    throw error;
24  }
25
26  // Check that the snapshot is valid JSON.
27  return cli.waitForInitialBreak()
28    .then(() => cli.waitForPrompt())
29    .then(() => cli.command('takeHeapSnapshot()'))
30    .then(() => JSON.parse(readFileSync(filename, 'utf8')))
31    .then(() => cleanup())
32    .then(() => cli.quit())
33    .then(null, onFatal);
34});
35