Skip to content

Commit 94077e9

Browse files
authored
chore: fix hamt test (#922)
Sometimes this causes firefox to fail as the assertions occur while the page is still loading the service worker.
1 parent 9d0394c commit 94077e9

File tree

2 files changed

+20
-9
lines changed

2 files changed

+20
-9
lines changed

test-e2e/fixtures/load-with-service-worker.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import { QUERY_PARAMS } from '../../src/lib/constants.js'
22
import type { Page, Response } from 'playwright'
33

4+
const ORIGIN_ISOLATION_WARNING = '.e2e-subdomain-warning'
5+
const ACCEPT_ORIGIN_ISOLATION_WARNING = '#accept-warning'
6+
47
export interface LoadWithServiceWorkerOptions {
58
/**
69
* Specify the final URL here, if different to `resource`
@@ -30,6 +33,17 @@ export interface LoadWithServiceWorkerOptions {
3033
export async function loadWithServiceWorker (page: Page, resource: string, options?: LoadWithServiceWorkerOptions): Promise<Response> {
3134
const expected = options?.redirect ?? resource
3235

36+
// accept origin isolation warning if it appears
37+
page.on('load', (page) => {
38+
Promise.resolve()
39+
.then(async () => {
40+
if (await page.isVisible(ORIGIN_ISOLATION_WARNING)) {
41+
await page.click(ACCEPT_ORIGIN_ISOLATION_WARNING)
42+
}
43+
})
44+
.catch(() => {})
45+
})
46+
3347
const [
3448
response
3549
] = await Promise.all([

test-e2e/hamt-dir.test.ts

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,13 @@
1-
import { allowInsecureWebsiteAccess } from './allow-insecure-website-access.js'
21
import { testPathRouting as test, expect } from './fixtures/config-test-fixtures.js'
3-
import { waitForServiceWorker } from './fixtures/wait-for-service-worker.js'
2+
import { loadWithServiceWorker } from './fixtures/load-with-service-worker.js'
43

54
test.describe('hamt-dir', () => {
6-
test.beforeEach(async ({ page, baseURL }) => {
7-
await waitForServiceWorker(page)
8-
await allowInsecureWebsiteAccess(page)
9-
})
5+
test('can open UnixFS file from HAMT-sharded directory', async ({ page, protocol, rootDomain, baseURL }) => {
6+
const cid = 'bafybeidbclfqleg2uojchspzd4bob56dqetqjsj27gy2cq3klkkgxtpn4i'
7+
const path = '685.txt'
108

11-
test('can open UnixFS file from HAMT-sharded directory', async ({ page, baseURL }) => {
12-
const response = await page.goto('http://127.0.0.1:3333/ipfs/bafybeidbclfqleg2uojchspzd4bob56dqetqjsj27gy2cq3klkkgxtpn4i/685.txt', {
13-
waitUntil: 'networkidle'
9+
const response = await loadWithServiceWorker(page, `${protocol}//${rootDomain}/ipfs/${cid}/${path}`, {
10+
redirect: rootDomain.includes('localhost') ? `${protocol}//${cid}.ipfs.${rootDomain}/${path}` : undefined
1411
})
1512

1613
expect(response?.status()).toBe(200)

0 commit comments

Comments
 (0)