Service Worker Error
This page requires a service worker to be available. Please ensure that
diff --git a/test-e2e/fixtures/config-test-fixtures.ts b/test-e2e/fixtures/config-test-fixtures.ts
index 983f51de..81c32e03 100644
--- a/test-e2e/fixtures/config-test-fixtures.ts
+++ b/test-e2e/fixtures/config-test-fixtures.ts
@@ -2,6 +2,10 @@ import { test as base, type Page } from '@playwright/test'
import { setConfig, setSubdomainConfig } from './set-sw-config.js'
import { waitForServiceWorker } from './wait-for-service-worker.js'
+function isNoServiceWorkerProject (test: T): boolean {
+ return test.info().project.name === 'no-service-worker'
+}
+
const rootDomain = async ({ baseURL }, use): Promise => {
const url = new URL(baseURL)
await use(url.host)
@@ -13,13 +17,20 @@ const baseURLProtocol = async ({ baseURL }, use): Promise => {
export const test = base.extend<{ rootDomain: string, baseURL: string, protocol: string }>({
rootDomain: [rootDomain, { scope: 'test' }],
- protocol: [baseURLProtocol, { scope: 'test' }]
+ protocol: [baseURLProtocol, { scope: 'test' }],
+ page: async ({ page }, use) => {
+ if (isNoServiceWorkerProject(test)) {
+ test.skip()
+ return
+ }
+ await use(page)
+ }
})
/**
* You should use this fixture instead of the `test` fixture from `@playwright/test` when testing path routing via the service worker.
*/
-export const testPathRouting = base.extend<{ rootDomain: string, baseURL: string, protocol: string }>({
+export const testPathRouting = test.extend<{ rootDomain: string, baseURL: string, protocol: string }>({
rootDomain: [rootDomain, { scope: 'test' }],
protocol: [baseURLProtocol, { scope: 'test' }],
page: async ({ page, rootDomain }, use) => {
@@ -63,7 +74,7 @@ export const testPathRouting = base.extend<{ rootDomain: string, baseURL: string
* })
* ```
*/
-export const testSubdomainRouting = base.extend<{ rootDomain: string, baseURL: string, protocol: string }>({
+export const testSubdomainRouting = test.extend<{ rootDomain: string, baseURL: string, protocol: string }>({
rootDomain: [rootDomain, { scope: 'test' }],
protocol: [baseURLProtocol, { scope: 'test' }],
page: async ({ page, baseURL }, use) => {
@@ -108,4 +119,21 @@ export const testSubdomainRouting = base.extend<{ rootDomain: string, baseURL: s
}
})
+/**
+ * A fixture that skips tests that require the service worker. This is needed in order to test handling of requests where the service worker is not present.
+ *
+ * @see https://github.com/ipfs/service-worker-gateway/issues/272
+ */
+export const testNoServiceWorker = base.extend<{ rootDomain: string, baseURL: string, protocol: string }>({
+ rootDomain: [rootDomain, { scope: 'test' }],
+ protocol: [baseURLProtocol, { scope: 'test' }],
+ page: async ({ page }, use) => {
+ if (!isNoServiceWorkerProject(testNoServiceWorker)) {
+ testNoServiceWorker.skip()
+ return
+ }
+ await use(page)
+ }
+})
+
export { expect } from '@playwright/test'
diff --git a/test-e2e/fixtures/locators.ts b/test-e2e/fixtures/locators.ts
index 41baaca1..c3d49123 100644
--- a/test-e2e/fixtures/locators.ts
+++ b/test-e2e/fixtures/locators.ts
@@ -21,6 +21,8 @@ export const getConfigGatewaysInput: GetLocator = (page) => page.locator('.e2e-c
export const getConfigRoutersInput: GetLocator = (page) => page.locator('.e2e-config-page-input-routers')
export const getConfigAutoReloadInput: GetLocator = (page) => page.locator('.e2e-config-page-input-autoreload')
+export const getNoServiceWorkerError: GetLocator = (page) => page.locator('.e2e-no-service-worker-error')
+
/**
* Iframe page parts
*/
diff --git a/test-e2e/layout.test.ts b/test-e2e/layout.test.ts
index 81510fcb..e549af4f 100644
--- a/test-e2e/layout.test.ts
+++ b/test-e2e/layout.test.ts
@@ -1,4 +1,4 @@
-import { test, expect } from '@playwright/test'
+import { test, expect } from './fixtures/config-test-fixtures.js'
import { getConfigButton, getConfigPage, getConfigPageSaveButton, getConfigPageInput, getHeader, getHeaderTitle } from './fixtures/locators.js'
test.describe('smoketests', () => {
diff --git a/test-e2e/no-service-worker.test.ts b/test-e2e/no-service-worker.test.ts
new file mode 100644
index 00000000..628bb1c3
--- /dev/null
+++ b/test-e2e/no-service-worker.test.ts
@@ -0,0 +1,16 @@
+import { testNoServiceWorker as test, expect } from './fixtures/config-test-fixtures.js'
+import { getNoServiceWorkerError } from './fixtures/locators.js'
+
+test.describe('no-service-worker', () => {
+ test('Error renders on landing page', async ({ page }) => {
+ await page.goto('/')
+
+ await expect(getNoServiceWorkerError(page)).toBeVisible()
+ })
+
+ test('Error renders on subdomain page', async ({ page, rootDomain, protocol }) => {
+ await page.goto(`${protocol ?? 'http'}//bafkqablimvwgy3y.ipfs.${rootDomain}`, { waitUntil: 'networkidle' })
+
+ await expect(getNoServiceWorkerError(page)).toBeVisible()
+ })
+})