Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: move waitForServiceWorker to test fixture #145

Merged
merged 1 commit into from
Mar 22, 2024
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
12 changes: 2 additions & 10 deletions test-e2e/byte-range.test.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,12 @@
import { test, expect } from '@playwright/test'
import { waitForServiceWorker } from './fixtures/wait-for-service-worker.js'

test.describe('byte-ranges', () => {
test('should be able to get a single character', async ({ page }) => {
await page.goto('http://localhost:3000', { waitUntil: 'networkidle' })
// wait for service worker to load
await page.evaluate(async () => {
const registration = await window.navigator.serviceWorker.getRegistration()
await waitForServiceWorker(page)

if (registration?.active?.state === 'activated') {
return
}

await new Promise((resolve, reject) => {
window.navigator.serviceWorker.addEventListener('controllerchange', resolve)
})
})
const partialText = await page.evaluate(async () => {
const response = await fetch('/ipfs/bafkqaddimvwgy3zao5xxe3debi', { headers: { range: 'bytes=1-2' } })
const text = await response.text()
Expand Down
15 changes: 15 additions & 0 deletions test-e2e/fixtures/wait-for-service-worker.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import type { Page } from '@playwright/test'

export async function waitForServiceWorker (page: Page): Promise<void> {
await page.evaluate(async () => {
const registration = await window.navigator.serviceWorker.getRegistration()

if (registration?.active?.state === 'activated') {
return
}

await new Promise((resolve, reject) => {
window.navigator.serviceWorker.addEventListener('controllerchange', resolve)
})
})
}
Loading