Skip to content

Commit fb8f6e4

Browse files
authored
fix(e2e): isolate markdown-viewer checks from a deleted fixture and WebKit's cancelled RSC fetches (#10373)
* fix(e2e): isolate markdown-viewer checks from a deleted fixture and WebKit's cancelled RSC fetches * fix(e2e): match cancelled RSC fetches by parsed origin and keep a failed paste proof's page
1 parent 5bef3d8 commit fb8f6e4

1 file changed

Lines changed: 45 additions & 5 deletions

File tree

‎apps/sim/scripts/test-markdown-viewer-e2e.ts‎

Lines changed: 45 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,25 @@ async function check(name: string, run: () => Promise<void>, page?: Page) {
187187
}
188188
}
189189

190+
const CANCELLED_FETCH = / due to access control checks\.$/
191+
192+
/**
193+
* WebKit rejects a fetch the page cancels by navigating away, such as a Next.js RSC prefetch, with
194+
* "<request> due to access control checks.", and the router leaves that rejection unhandled. For a
195+
* same-origin RSC request that is a cancellation, never an access failure.
196+
*/
197+
function isCancelledRscFetch(message: string): boolean {
198+
if (!CANCELLED_FETCH.test(message)) return false
199+
// WebKit names the request as `/host:port/path?query`, without its scheme.
200+
const target = message.replace(CANCELLED_FETCH, '').split(' ').pop() ?? ''
201+
try {
202+
const url = new URL(target.startsWith('/') ? `${base.protocol}/${target}` : target)
203+
return url.origin === base.origin && url.searchParams.has('_rsc')
204+
} catch {
205+
return false
206+
}
207+
}
208+
190209
async function wideTableProof(page: Page) {
191210
const table = page.locator('.rich-markdown-prose table').filter({ hasText: 'Option Alpha' })
192211
await expect(table).toBeVisible({ timeout: 120_000 })
@@ -392,11 +411,24 @@ async function editLastCell(page: Page, marker: string) {
392411
await expect(page.locator('.rich-markdown-prose[contenteditable="true"]')).toBeFocused()
393412
await page.keyboard.press('ArrowLeft')
394413
await page.keyboard.press('Shift+ArrowRight')
395-
await expect
396-
.poll(() => page.evaluate(() => getSelection()?.toString().trim() ?? ''), {
397-
message: 'Keyboard selection did not select text',
414+
try {
415+
await expect
416+
.poll(() => page.evaluate(() => getSelection()?.toString().trim() ?? ''))
417+
.not.toBe('')
418+
} catch {
419+
// Rare in WebKit and not reproduced yet: name where the caret and focus ended up.
420+
const state = await page.evaluate(() => {
421+
const selection = getSelection()
422+
return {
423+
anchorText: selection?.anchorNode?.textContent?.slice(0, 40) ?? null,
424+
anchorOffset: selection?.anchorOffset ?? null,
425+
focusOffset: selection?.focusOffset ?? null,
426+
rangeCount: selection?.rangeCount ?? 0,
427+
activeElement: document.activeElement?.className ?? null,
428+
}
398429
})
399-
.not.toBe('')
430+
throw new Error(`Keyboard selection did not select text: ${JSON.stringify(state)}`)
431+
}
400432
await proveToolbar(page, page.getByRole('toolbar', { name: 'Text formatting' }))
401433
await page.keyboard.press('ArrowRight')
402434
}
@@ -419,6 +451,7 @@ async function provePastePersistence(page: Page, browserName: string) {
419451
const pastedShareToken = generateShortId()
420452
const readPasteSource = async () =>
421453
(await request(`/api/files/public/${pastedShareToken}/content`)).text()
454+
let proved = false
422455
try {
423456
await sql`insert into public_share (id, resource_type, resource_id, entity_type, entity_id, workspace_id, created_by, token) values (${pastedShareId}, 'file', ${pastedFileId}, 'workspace', ${workspaceId}, ${workspaceId}, ${userId}, ${pastedShareToken})`
424457
await page.goto(new URL(`/workspace/${workspaceId}/files/${pastedFileId}`, base).href, {
@@ -563,8 +596,12 @@ async function provePastePersistence(page: Page, browserName: string) {
563596
afterLocalEdit.includes(`${marker} measure<br>`),
564597
'External update lost the pasted table'
565598
)
599+
proved = true
566600
} finally {
567601
try {
602+
// Leave the file before deleting it, or the open editor refetches it and the next check on
603+
// this page records that 404 as its own. A failed proof keeps the page for its screenshot.
604+
if (proved) await page.goto('about:blank')
568605
await request(`/api/workspaces/${workspaceId}/files/${pastedFileId}`, undefined, 'DELETE')
569606
} finally {
570607
await sql`delete from public_share where id=${pastedShareId}`
@@ -972,7 +1009,10 @@ try {
9721009
{ name: 'better-auth.session_token', value: cookie, url: base.origin },
9731010
])
9741011
const page = await context.newPage()
975-
page.on('pageerror', (error) => errors.push(`${browserName}: ${error.message}`))
1012+
page.on('pageerror', (error) => {
1013+
if (browserName === 'webkit' && isCancelledRscFetch(error.message)) return
1014+
errors.push(`${browserName}: ${error.message}`)
1015+
})
9761016
for (const width of widths) {
9771017
await page.setViewportSize({ width, height: 1000 })
9781018
await page.goto(new URL(`/f/${shareToken}`, base).href, {

0 commit comments

Comments
 (0)