forked from oasisprotocol/wallet
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request oasisprotocol#1768 from oasisprotocol/lw/refactor-…
…ext-tests Refactor extension tests
- Loading branch information
Showing
7 changed files
with
81 additions
and
68 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 @@ | ||
Refactor extension tests |
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
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
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,41 @@ | ||
import { test as base, BrowserContext, chromium } from '@playwright/test' | ||
import path from 'path' | ||
|
||
// Test dev build by default, but also allow testing production | ||
const extensionPath = path.join(__dirname, '..', process.env.EXTENSION_PATH ?? '../build-dev/') | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-var-requires | ||
const extensionManifest = require(path.join(extensionPath, '/manifest.json')) | ||
const popupFile = extensionManifest.browser_action.default_popup | ||
|
||
// From https://playwright.dev/docs/chrome-extensions | ||
export const test = base.extend<{ | ||
context: BrowserContext | ||
extensionId: string | ||
extensionPopupURL: `chrome-extension://${string}` | ||
}>({ | ||
// eslint-disable-next-line no-empty-pattern | ||
context: async ({}, use) => { | ||
const context = await chromium.launchPersistentContext('', { | ||
headless: false, | ||
args: [`--disable-extensions-except=${extensionPath}`, `--load-extension=${extensionPath}`], | ||
}) | ||
await use(context) | ||
await context.close() | ||
}, | ||
extensionId: async ({ context }, use) => { | ||
// for manifest v2: | ||
let [background] = context.backgroundPages() | ||
if (!background) background = await context.waitForEvent('backgroundpage') | ||
|
||
// for manifest v3: | ||
// let [background] = context.serviceWorkers() | ||
// if (!background) background = await context.waitForEvent('serviceworker') | ||
|
||
const extensionId = background.url().split('/')[2] | ||
await use(extensionId) | ||
}, | ||
extensionPopupURL: async ({ extensionId }, use) => { | ||
await use(`chrome-extension://${extensionId}/${popupFile}#`) | ||
}, | ||
}) |
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