MCPcopy
hub / github.com/vitest-dev/vitest / setupInspect

Function setupInspect

packages/vitest/src/runtime/inspector.ts:14–58  ·  view source on GitHub ↗
(ctx: ContextRPC)

Source from the content-addressed store, hash-verified

12 * Should be called as early as possible when worker/process has been set up.
13 */
14export function setupInspect(ctx: ContextRPC) {
15 const config = ctx.config
16 const isEnabled = config.inspector.enabled
17
18 if (isEnabled) {
19 inspector = __require('node:inspector')
20 // Inspector may be open already if "isolate: false" is used
21 const isOpen = inspector.url() !== undefined
22
23 if (!isOpen) {
24 inspector.open(
25 config.inspector.port,
26 config.inspector.host,
27 config.inspector.waitForDebugger,
28 )
29
30 if (config.inspectBrk) {
31 const firstTestFile = typeof ctx.files[0] === 'string'
32 ? ctx.files[0]
33 : ctx.files[0].filepath
34
35 // Stop at first test file
36 if (firstTestFile) {
37 session = new inspector.Session()
38 session.connect()
39
40 session.post('Debugger.enable')
41 session.post('Debugger.setBreakpointByUrl', {
42 lineNumber: 0,
43 url: pathToFileURL(firstTestFile),
44 })
45 }
46 }
47 }
48 }
49
50 const keepOpen = shouldKeepOpen(config)
51
52 return function cleanup(): void {
53 if (isEnabled && !keepOpen && inspector) {
54 inspector.close()
55 session?.disconnect()
56 }
57 }
58}
59
60export function closeInspector(config: SerializedConfig): void {
61 const keepOpen = shouldKeepOpen(config)

Callers 1

executeFunction · 0.90

Calls 3

shouldKeepOpenFunction · 0.85
openMethod · 0.80
closeMethod · 0.45

Tested by

no test coverage detected