Skip to content

Commit

Permalink
fix: set breakpoint before page navigation
Browse files Browse the repository at this point in the history
  • Loading branch information
AriPerkkio committed Sep 7, 2024
1 parent 79839e8 commit a7aa3ef
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
5 changes: 2 additions & 3 deletions packages/browser/src/node/pool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export function createBrowserPool(ctx: Vitest): ProcessPool {
const session = await provider.getCDPSession(contextId)
await session.send('Debugger.enable', {})
await session.send('Debugger.setBreakpointByUrl', {
lineNumber: 0, // TODO: Need to make sure test files have source map location on first line
lineNumber: 0,
urlRegex: escapePathToRegexp(file),
})
}
Expand Down Expand Up @@ -100,8 +100,7 @@ export function createBrowserPool(ctx: Vitest): ProcessPool {
const url = new URL('/', origin)
url.searchParams.set('contextId', contextId)
const page = provider
.openPage(contextId, url.toString())
.then(() => setBreakpoint(contextId, files[0]))
.openPage(contextId, url.toString(), () => setBreakpoint(contextId, files[0]))
.then(() => waitPromise)
promises.push(page)
}
Expand Down
3 changes: 2 additions & 1 deletion packages/browser/src/node/providers/playwright.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,9 @@ export class PlaywrightBrowserProvider implements BrowserProvider {
return page
}

async openPage(contextId: string, url: string) {
async openPage(contextId: string, url: string, beforeNavigate?: () => Promise<void>) {
const browserPage = await this.openBrowserPage(contextId)
await beforeNavigate?.()
await browserPage.goto(url)
}

Expand Down
2 changes: 1 addition & 1 deletion packages/vitest/src/node/types/browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export interface BrowserProvider {
beforeCommand?: (command: string, args: unknown[]) => Awaitable<void>
afterCommand?: (command: string, args: unknown[]) => Awaitable<void>
getCommandsContext: (contextId: string) => Record<string, unknown>
openPage: (contextId: string, url: string) => Promise<void>
openPage: (contextId: string, url: string, beforeNavigate?: () => Promise<void>) => Promise<void>
getCDPSession?: (contextId: string) => Promise<CDPSession>
close: () => Awaitable<void>
// eslint-disable-next-line ts/method-signature-style -- we want to allow extended options
Expand Down

0 comments on commit a7aa3ef

Please sign in to comment.