-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix:
--inspect-brk
to pause before execution (#5355)
- Loading branch information
1 parent
d627e20
commit e77c553
Showing
10 changed files
with
162 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,5 @@ | ||
import { expect, test } from "vitest"; | ||
|
||
test("sum", () => { | ||
expect(1 + 1).toBe(2) | ||
}) |
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,8 @@ | ||
import { defineConfig } from 'vitest/config' | ||
|
||
export default defineConfig({ | ||
test: { | ||
include: ['./**.test.ts'], | ||
watch: false, | ||
}, | ||
}) |
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,13 @@ | ||
{ | ||
"name": "@vitest/test-inspect", | ||
"type": "module", | ||
"private": true, | ||
"scripts": { | ||
"test": "vitest" | ||
}, | ||
"devDependencies": { | ||
"vite": "latest", | ||
"vitest": "workspace:*", | ||
"ws": "^8.14.2" | ||
} | ||
} |
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,86 @@ | ||
import type { InspectorNotification } from 'node:inspector' | ||
import { expect, test } from 'vitest' | ||
import WebSocket from 'ws' | ||
|
||
import { isWindows } from '../../../packages/vite-node/src/utils' | ||
import { runVitestCli } from '../../test-utils' | ||
|
||
type Message = Partial<InspectorNotification<any>> | ||
|
||
test.skipIf(isWindows)('--inspect-brk stops at test file', async () => { | ||
const vitest = await runVitestCli('--root', 'fixtures', '--inspect-brk', '--no-file-parallelism') | ||
|
||
await vitest.waitForStderr('Debugger listening on ') | ||
const url = vitest.stderr.split('\n')[0].replace('Debugger listening on ', '') | ||
|
||
const { receive, send } = await createChannel(url) | ||
|
||
send({ method: 'Debugger.enable' }) | ||
send({ method: 'Runtime.enable' }) | ||
await receive('Runtime.executionContextCreated') | ||
|
||
const paused = receive('Debugger.paused') | ||
send({ method: 'Runtime.runIfWaitingForDebugger' }) | ||
|
||
const { params } = await paused | ||
const scriptId = params.callFrames[0].functionLocation.scriptId | ||
|
||
// Verify that debugger paused on test file | ||
const response = receive() | ||
send({ method: 'Debugger.getScriptSource', params: { scriptId } }) | ||
const { result } = await response as any | ||
|
||
expect(result.scriptSource).toContain('test("sum", () => {') | ||
expect(result.scriptSource).toContain('expect(1 + 1).toBe(2)') | ||
|
||
send({ method: 'Debugger.resume' }) | ||
|
||
await vitest.waitForStdout('Test Files 1 passed (1)') | ||
await vitest.isDone | ||
}) | ||
|
||
async function createChannel(url: string) { | ||
const ws = new WebSocket(url) | ||
|
||
let id = 1 | ||
let receiver = defer() | ||
|
||
ws.onerror = receiver.reject | ||
ws.onmessage = (message) => { | ||
const response = JSON.parse(message.data.toString()) | ||
receiver.resolve(response) | ||
} | ||
|
||
async function receive(filter?: string) { | ||
const message = await receiver.promise | ||
receiver = defer() | ||
|
||
if (filter && message.method !== filter) | ||
return receive(filter) | ||
|
||
return message | ||
} | ||
|
||
function send(message: Message) { | ||
ws.send(JSON.stringify({ ...message, id: id++ })) | ||
} | ||
|
||
await new Promise(r => ws.on('open', r)) | ||
|
||
return { receive, send } | ||
} | ||
|
||
function defer(): { | ||
promise: Promise<Message> | ||
resolve: (response: Message) => void | ||
reject: (error: unknown) => void | ||
} { | ||
const pr = {} as ReturnType<typeof defer> | ||
|
||
pr.promise = new Promise((resolve, reject) => { | ||
pr.resolve = resolve | ||
pr.reject = reject | ||
}) | ||
|
||
return pr | ||
} |
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,7 @@ | ||
import { defineConfig } from 'vitest/config' | ||
|
||
export default defineConfig({ | ||
test: { | ||
include: ['./test/**'], | ||
}, | ||
}) |
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