-
Notifications
You must be signed in to change notification settings - Fork 30.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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: #44489 Reviewed-By: Moshe Atlow <moshe@atlow.co.il> Reviewed-By: Anna Henningsen <anna@addaleax.net>
- Loading branch information
1 parent
20a76a6
commit 0c987d1
Showing
4 changed files
with
37 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
'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); | ||
})); |