0
0
mirror of https://github.com/nodejs/node.git synced 2024-11-21 21:19:50 +01:00
nodejs/test/parallel/test-inspector-close-worker.js
Chengzhong Wu 050a1451e9
inspector: expose inspector.close on workers
Workers can open their own inspector agent with `inspector.open`.
They should be able to close their own inspector agent too with
`inspector.close`.

PR-URL: https://github.com/nodejs/node/pull/44489
Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
2022-09-13 09:04:24 +00:00

35 lines
983 B
JavaScript

'use strict';
const common = require('../common');
common.skipIfInspectorDisabled();
const { isMainThread, Worker } = require('worker_threads');
const assert = require('assert');
const inspector = require('inspector');
if (!isMainThread) {
// Verify the inspector api on the worker thread.
assert.strictEqual(inspector.url(), undefined);
inspector.open(0, undefined, false);
const wsUrl = inspector.url();
assert(wsUrl.startsWith('ws://'));
inspector.close();
assert.strictEqual(inspector.url(), undefined);
return;
}
// Open inspector on the main thread first.
inspector.open(0, undefined, false);
const wsUrl = inspector.url();
assert(wsUrl.startsWith('ws://'));
const worker = new Worker(__filename);
worker.on('exit', common.mustCall((code) => {
assert.strictEqual(code, 0);
// Verify inspector on the main thread is still active.
assert.strictEqual(inspector.url(), wsUrl);
inspector.close();
assert.strictEqual(inspector.url(), undefined);
}));