forked from nodejs/node-core-test
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test_runner: support using
--inspect
with --test
PR-URL: nodejs/node#44520 Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: Antoine du Hamel <[email protected]> (cherry picked from commit a165193c5c8e4bcfbd12b2c3f6e55a81a251c258)
- Loading branch information
Showing
7 changed files
with
125 additions
and
27 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
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,47 @@ | ||
// https://github.com/nodejs/node/blob/a165193c5c8e4bcfbd12b2c3f6e55a81a251c258/lib/internal/util/inspector.js | ||
const { | ||
ArrayPrototypeSome, | ||
RegExpPrototypeExec | ||
} = require('#internal/per_context/primordials') | ||
|
||
const { validatePort } = require('#internal/validators') | ||
|
||
const kMinPort = 1024 | ||
const kMaxPort = 65535 | ||
const kInspectArgRegex = /--inspect(?:-brk|-port)?|--debug-port/ | ||
const kInspectMsgRegex = /Debugger listening on ws:\/\/\[?(.+?)\]?:(\d+)\/|Debugger attached|Waiting for the debugger to disconnect\.\.\./ | ||
|
||
let _isUsingInspector | ||
function isUsingInspector () { | ||
_isUsingInspector ??= | ||
ArrayPrototypeSome(process.execArgv, (arg) => RegExpPrototypeExec(kInspectArgRegex, arg) !== null) || | ||
RegExpPrototypeExec(kInspectArgRegex, process.env.NODE_OPTIONS) !== null | ||
return _isUsingInspector | ||
} | ||
|
||
let debugPortOffset = 1 | ||
function getInspectPort (inspectPort) { | ||
if (!isUsingInspector()) { | ||
return null | ||
} | ||
if (typeof inspectPort === 'function') { | ||
inspectPort = inspectPort() | ||
} else if (inspectPort == null) { | ||
inspectPort = process.debugPort + debugPortOffset | ||
if (inspectPort > kMaxPort) { inspectPort = inspectPort - kMaxPort + kMinPort - 1 } | ||
debugPortOffset++ | ||
} | ||
validatePort(inspectPort) | ||
|
||
return inspectPort | ||
} | ||
|
||
function isInspectorMessage (string) { | ||
return isUsingInspector() && RegExpPrototypeExec(kInspectMsgRegex, string) !== null | ||
} | ||
|
||
module.exports = { | ||
isUsingInspector, | ||
getInspectPort, | ||
isInspectorMessage | ||
} |
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