Skip to content

Commit

Permalink
Fix addPersistedStorageV1 and clearPersistedStorage in extension tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lukaw3d committed Nov 29, 2023
1 parent 3478198 commit e07e958
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
1 change: 1 addition & 0 deletions .changelog/1780.internal.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Improve e2e tests
4 changes: 4 additions & 0 deletions playwright/utils/extensionTestExtend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export const test = base.extend<{
context: BrowserContext
extensionId: string
extensionPopupURL: `chrome-extension://${string}`
extensionManifestURL: `chrome-extension://${string}/manifest.json`
}>({
// eslint-disable-next-line no-empty-pattern
context: async ({}, use) => {
Expand All @@ -38,4 +39,7 @@ export const test = base.extend<{
extensionPopupURL: async ({ extensionId }, use) => {
await use(`chrome-extension://${extensionId}/${popupFile}#`)
},
extensionManifestURL: async ({ extensionId }, use) => {
await use(`chrome-extension://${extensionId}/manifest.json`)
},
})
11 changes: 8 additions & 3 deletions playwright/utils/storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,21 @@ import { privateKeyPersistedState } from '../../src/utils/__fixtures__/test-inpu

export async function clearPersistedStorage(
page: Page,
url: '/app.webmanifest' | `chrome-extension://${string}`,
url: '/app.webmanifest' | `chrome-extension://${string}/manifest.json`,
) {
// Move to the right domain, but don't needlessly load HTML and JS.
await page.goto(url)
await page.evaluate(() => window.localStorage.clear())
await page.evaluate(() => {
window.localStorage.clear()

const chrome = (window as any).chrome
chrome?.extension?.getBackgroundPage?.().location.reload()
})
}

export async function addPersistedStorageV1(
page: Page,
url: '/app.webmanifest' | `chrome-extension://${string}`,
url: '/app.webmanifest' | `chrome-extension://${string}/manifest.json`,
) {
// Move to the right domain, but don't needlessly load HTML and JS.
await page.goto(url)
Expand Down

0 comments on commit e07e958

Please sign in to comment.