node/test/parallel/test-worker-heap-snapshot.js
Erick Wendel ba5b5acaf1
test: improve worker_threads coverage
PR-URL: https://github.com/nodejs/node/pull/41818
Refs: https://coverage.nodejs.org/coverage-7123a00b03a90862/lib/internal/worker.js.html#L412
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
2022-02-11 12:37:40 +01:00

17 lines
502 B
JavaScript

'use strict';
const common = require('../common');
const assert = require('assert');
const { Worker } = require('worker_threads');
const { once } = require('events');
// Ensure that worker.getHeapSnapshot() returns a valid JSON
(async () => {
const worker = new Worker('setInterval(() => {}, 1000);', { eval: true });
await once(worker, 'online');
const stream = await worker.getHeapSnapshot();
assert.ok(JSON.parse(stream.read()));
await worker.terminate();
})().then(common.mustCall());