mirror of
https://github.com/nodejs/node.git
synced 2024-11-21 21:19:50 +01:00
050a1451e9
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>
35 lines
983 B
JavaScript
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);
|
|
}));
|