Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions tests/browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,11 @@ export async function openBrowser(): Promise<TestBrowser> {
const page = await context.newPage()
page.setDefaultTimeout(STEP_TIMEOUT_MS)
page.setDefaultNavigationTimeout(NAVIGATION_TIMEOUT_MS)
/* a renderer Chromium lost takes its page with it, and every later wait
on that page only times out: say so once, where the log can be read */
page.on('error', (error) => {
process.stderr.write(`[browser] Chromium lost the tab at ${page.url()}: ${String(error)}\n`)
})
/* files running side by side each have a window in the one browser, and
only one window holds the focus at a time: a page that lost it stops
moving focus between its iframes. Emulated focus keeps every page
Expand Down
34 changes: 27 additions & 7 deletions tests/drawingBrowser.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { afterAll, beforeAll, beforeEach, describe, expect, it } from 'vitest'
import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, it } from 'vitest'
import type { Page } from 'puppeteer-core'
import type { TextFormatCommand } from '../src/lib/richText'
import { findBrowserPath } from '../server/screenshot'
Expand Down Expand Up @@ -34,7 +34,11 @@ declare global {
}
}

describe.skipIf(!findBrowserPath())('drawing on the canvas', { timeout: 30_000 }, () => {
/* a tab Chromium lost on a CI runner is not a failure of the canvas: the test
runs again there on a fresh page, and a real failure fails all three times */
const RETRIES = process.env.CI ? 2 : 0

describe.skipIf(!findBrowserPath())('drawing on the canvas', { timeout: 30_000, retry: RETRIES }, () => {
let browser: TestBrowser
let page: Page
let saved: Frame[] = []
Expand All @@ -43,12 +47,22 @@ describe.skipIf(!findBrowserPath())('drawing on the canvas', { timeout: 30_000 }
/* the anchors sent by PATCH /api/comments/:id/anchor, in order */
let commentMoves: Record<string, unknown>[] = []
const errors: string[] = []
/** why Chromium gave up on this test's tab, when it did */
let crashed: string | null = null

beforeAll(async () => {
browser = await openBrowser()
page = await browser.newPage()
}, 60_000)

/* Every test gets its own page. One page for the whole file meant that a
tab Chromium lost (a renderer that died on a CI runner) took every later
test with it: each one's setup waited 30s on a page that would never
answer. */
async function openPage(): Promise<Page> {
const page = await browser.newPage()
page.setDefaultTimeout(10_000)
page.on('pageerror', (err) => errors.push(String(err)))
page.on('error', (err) => (crashed = String(err)))
/* holds the frames' hit-test answers while a test sets heldMoveHits; it
must listen before the app does, since a window's own listeners run in
the order they were added */
Expand Down Expand Up @@ -89,11 +103,12 @@ describe.skipIf(!findBrowserPath())('drawing on the canvas', { timeout: 30_000 }
await req.respond({ status: 200, contentType: 'application/json', body: '{}' })
} else await req.continue()
})
}, 60_000)
return page
}

beforeEach(async () => {
await page.mouse.reset()
await page.keyboard.up('Shift')
crashed = null
page = await openPage()
saved = []
nextId = 0
patchRequests = 0
Expand All @@ -119,8 +134,13 @@ describe.skipIf(!findBrowserPath())('drawing on the canvas', { timeout: 30_000 }
await page.evaluate(() => window.drawingHarness.viewport({ x: 40, y: 20, zoom: 2 }))
})

afterEach(async () => {
/* a crashed tab can no longer be closed politely; the context closes it */
if (!crashed) await page?.close()
expect(crashed, 'Chromium lost the tab during this test').toBeNull()
})

afterAll(async () => {
await page?.close()
await browser?.close()
expect(errors).toEqual([])
})
Expand Down
Loading