0
0
mirror of https://github.com/nodejs/node.git synced 2024-12-01 16:10:02 +01:00
nodejs/test/parallel/test-inspector-heapdump.js
Sam Roberts a445244a0c doc: add inspector API example for heapdump
PR-URL: https://github.com/nodejs/node/pull/26498
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
Reviewed-By: Eugene Ostroukhov <eostroukhov@google.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: James M Snell <jasnell@gmail.com>
2019-03-11 06:19:11 +01:00

31 lines
768 B
JavaScript

'use strict';
const common = require('../common');
common.skipIfInspectorDisabled();
// Test that example code in doc/api/inspector.md continues to work with the V8
// experimental API.
const assert = require('assert');
const inspector = require('inspector');
const session = new inspector.Session();
session.connect();
const chunks = [];
session.on('HeapProfiler.addHeapSnapshotChunk', (m) => {
chunks.push(m.params.chunk);
});
session.post('HeapProfiler.takeHeapSnapshot', null, common.mustCall((e, r) => {
assert.ifError(e);
assert.deepStrictEqual(r, {});
session.disconnect();
const profile = JSON.parse(chunks.join(''));
assert(profile.snapshot.meta);
assert(profile.snapshot.node_count > 0);
assert(profile.snapshot.edge_count > 0);
}));