mirror of
https://github.com/nodejs/node.git
synced 2024-12-01 16:10:02 +01:00
02b3bbc5e2
Highlights: * Using a random port works (`node inspect --port=0 script.js`) * `takeHeapSnapshot()` creates valid snapshots again PR-URL: https://github.com/nodejs/node/pull/18354 Reviewed-By: Richard Lau <riclau@uk.ibm.com>
35 lines
756 B
JavaScript
35 lines
756 B
JavaScript
'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);
|
|
});
|