-
-
Notifications
You must be signed in to change notification settings - Fork 203
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: add Playwright offline tests (#624)
* chore: add Svelte ecosystem-ci script * chore: remove script
- Loading branch information
Showing
10 changed files
with
180 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { expect, test } from '@playwright/test' | ||
|
||
const injectManifest = process.env.SW === 'true' | ||
const swName = `${injectManifest ? 'claims-sw.js' : 'sw.js'}` | ||
|
||
test('Preact: Test offline', async ({ browser }) => { | ||
// test offline + trailing slashes routes | ||
const context = await browser.newContext() | ||
const offlinePage = await context.newPage() | ||
await offlinePage.goto('/') | ||
const offlineSwURL = await offlinePage.evaluate(async () => { | ||
const registration = await Promise.race([ | ||
navigator.serviceWorker.ready, | ||
new Promise((_, reject) => setTimeout(() => reject(new Error('Service worker registration failed: time out')), 10000)), | ||
]) | ||
// @ts-expect-error registration is of type any | ||
return registration.active?.scriptURL | ||
}) | ||
expect(offlineSwURL).toBe(`http://localhost:4173/${swName}`) | ||
await context.setOffline(true) | ||
const aboutAnchor = offlinePage.getByRole('link', { name: 'About' }) | ||
expect(await aboutAnchor.getAttribute('href')).toBe('/about') | ||
await aboutAnchor.click({ noWaitAfter: false }) | ||
const url = await offlinePage.evaluate(async () => { | ||
await new Promise(resolve => setTimeout(resolve, 3000)) | ||
return location.href | ||
}) | ||
expect(url).toBe('http://localhost:4173/about') | ||
expect(offlinePage.locator('a').getByText('Go Home')).toBeTruthy() | ||
await offlinePage.reload({ waitUntil: 'load' }) | ||
expect(offlinePage.url()).toBe('http://localhost:4173/about') | ||
expect(offlinePage.locator('a').getByText('Go Home')).toBeTruthy() | ||
// Dispose context once it's no longer needed. | ||
await context.close() | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { expect, test } from '@playwright/test' | ||
|
||
const injectManifest = process.env.SW === 'true' | ||
const swName = `${injectManifest ? 'claims-sw.js' : 'sw.js'}` | ||
|
||
test('React: Test offline', async ({ browser }) => { | ||
// test offline + trailing slashes routes | ||
const context = await browser.newContext() | ||
const offlinePage = await context.newPage() | ||
await offlinePage.goto('/') | ||
const offlineSwURL = await offlinePage.evaluate(async () => { | ||
const registration = await Promise.race([ | ||
navigator.serviceWorker.ready, | ||
new Promise((_, reject) => setTimeout(() => reject(new Error('Service worker registration failed: time out')), 10000)), | ||
]) | ||
// @ts-expect-error registration is of type any | ||
return registration.active?.scriptURL | ||
}) | ||
expect(offlineSwURL).toBe(`http://localhost:4173/${swName}`) | ||
await context.setOffline(true) | ||
const aboutAnchor = offlinePage.getByRole('link', { name: 'About' }) | ||
expect(await aboutAnchor.getAttribute('href')).toBe('/about') | ||
await aboutAnchor.click({ noWaitAfter: false }) | ||
const url = await offlinePage.evaluate(async () => { | ||
await new Promise(resolve => setTimeout(resolve, 3000)) | ||
return location.href | ||
}) | ||
expect(url).toBe('http://localhost:4173/about') | ||
expect(offlinePage.locator('a').getByText('Go Home')).toBeTruthy() | ||
await offlinePage.reload({ waitUntil: 'load' }) | ||
expect(offlinePage.url()).toBe('http://localhost:4173/about') | ||
expect(offlinePage.locator('a').getByText('Go Home')).toBeTruthy() | ||
// Dispose context once it's no longer needed. | ||
await context.close() | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { expect, test } from '@playwright/test' | ||
|
||
const injectManifest = process.env.SW === 'true' | ||
const swName = `${injectManifest ? 'claims-sw.js' : 'sw.js'}` | ||
|
||
test('Solid: Test offline', async ({ browser }) => { | ||
// test offline + trailing slashes routes | ||
const context = await browser.newContext() | ||
const offlinePage = await context.newPage() | ||
await offlinePage.goto('/') | ||
const offlineSwURL = await offlinePage.evaluate(async () => { | ||
const registration = await Promise.race([ | ||
navigator.serviceWorker.ready, | ||
new Promise((_, reject) => setTimeout(() => reject(new Error('Service worker registration failed: time out')), 10000)), | ||
]) | ||
// @ts-expect-error registration is of type any | ||
return registration.active?.scriptURL | ||
}) | ||
expect(offlineSwURL).toBe(`http://localhost:4173/${swName}`) | ||
await context.setOffline(true) | ||
const aboutAnchor = offlinePage.getByRole('link', { name: 'About' }) | ||
expect(await aboutAnchor.getAttribute('href')).toBe('/about') | ||
await aboutAnchor.click({ noWaitAfter: false }) | ||
const url = await offlinePage.evaluate(async () => { | ||
await new Promise(resolve => setTimeout(resolve, 3000)) | ||
return location.href | ||
}) | ||
expect(url).toBe('http://localhost:4173/about') | ||
expect(offlinePage.locator('a').getByText('Go Home')).toBeTruthy() | ||
await offlinePage.reload({ waitUntil: 'load' }) | ||
expect(offlinePage.url()).toBe('http://localhost:4173/about') | ||
expect(offlinePage.locator('a').getByText('Go Home')).toBeTruthy() | ||
// Dispose context once it's no longer needed. | ||
await context.close() | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { expect, test } from '@playwright/test' | ||
|
||
const injectManifest = process.env.SW === 'true' | ||
const swName = `${injectManifest ? 'claims-sw.js' : 'sw.js'}` | ||
|
||
test('Svelte: Test offline', async ({ browser }) => { | ||
// test offline + trailing slashes routes | ||
const context = await browser.newContext() | ||
const offlinePage = await context.newPage() | ||
await offlinePage.goto('/') | ||
const offlineSwURL = await offlinePage.evaluate(async () => { | ||
const registration = await Promise.race([ | ||
navigator.serviceWorker.ready, | ||
new Promise((_, reject) => setTimeout(() => reject(new Error('Service worker registration failed: time out')), 10000)), | ||
]) | ||
// @ts-expect-error registration is of type any | ||
return registration.active?.scriptURL | ||
}) | ||
expect(offlineSwURL).toBe(`http://localhost:4173/${swName}`) | ||
await context.setOffline(true) | ||
const aboutAnchor = offlinePage.getByRole('link', { name: 'About' }) | ||
expect(await aboutAnchor.getAttribute('href')).toBe('/about') | ||
await aboutAnchor.click({ noWaitAfter: false }) | ||
const url = await offlinePage.evaluate(async () => { | ||
await new Promise(resolve => setTimeout(resolve, 3000)) | ||
return location.href | ||
}) | ||
expect(url).toBe('http://localhost:4173/about') | ||
expect(offlinePage.locator('a').getByText('Go Home')).toBeTruthy() | ||
await offlinePage.reload({ waitUntil: 'load' }) | ||
expect(offlinePage.url()).toBe('http://localhost:4173/about') | ||
expect(offlinePage.locator('a').getByText('Go Home')).toBeTruthy() | ||
// Dispose context once it's no longer needed. | ||
await context.close() | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { expect, test } from '@playwright/test' | ||
|
||
const injectManifest = process.env.SW === 'true' | ||
const swName = `${injectManifest ? 'claims-sw.js' : 'sw.js'}` | ||
|
||
test('Vue3: Test offline', async ({ browser }) => { | ||
// test offline + trailing slashes routes | ||
const context = await browser.newContext() | ||
const offlinePage = await context.newPage() | ||
await offlinePage.goto('/') | ||
const offlineSwURL = await offlinePage.evaluate(async () => { | ||
const registration = await Promise.race([ | ||
navigator.serviceWorker.ready, | ||
new Promise((_, reject) => setTimeout(() => reject(new Error('Service worker registration failed: time out')), 10000)), | ||
]) | ||
// @ts-expect-error registration is of type any | ||
return registration.active?.scriptURL | ||
}) | ||
expect(offlineSwURL).toBe(`http://localhost:4173/${swName}`) | ||
await context.setOffline(true) | ||
const aboutAnchor = offlinePage.getByRole('button', { name: 'About' }) | ||
expect(await aboutAnchor.getAttribute('type')).toBe('button') | ||
await aboutAnchor.click({ noWaitAfter: false }) | ||
const url = await offlinePage.evaluate(async () => { | ||
await new Promise(resolve => setTimeout(resolve, 3000)) | ||
return location.href | ||
}) | ||
expect(url).toBe('http://localhost:4173/about') | ||
expect(offlinePage.locator('button').getByText('Home')).toBeTruthy() | ||
await offlinePage.reload({ waitUntil: 'load' }) | ||
expect(offlinePage.url()).toBe('http://localhost:4173/about') | ||
expect(offlinePage.locator('button').getByText('Home')).toBeTruthy() | ||
// Dispose context once it's no longer needed. | ||
await context.close() | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters