Skip to content

Commit 807ba4e

Browse files
committed
chore(e2e): add fixtures.ts, update playwright config and e2e skill
1 parent 81153a0 commit 807ba4e

9 files changed

Lines changed: 54 additions & 41 deletions

File tree

.cursor/skills/e2e-playwright-extension/SKILL.md

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,19 @@ description: Adds or updates extension E2E tests using the project Playwright se
55

66
# E2E with Playwright (extension)
77

8+
Aligned with [WXT’s Playwright E2E example](https://github.com/wxt-dev/examples/tree/main/examples/playwright-e2e-testing): Chromium only, extension loaded from `dist/chrome-mv3`.
9+
810
## Layout
911

1012
- Tests in [e2e/tests/](e2e/tests/)
11-
- Shared fixture in [e2e/fixutes.ts](e2e/fixutes.ts) (note: filename typo in repo)
13+
- Shared fixture in [e2e/fixtures.ts](e2e/fixtures.ts)
1214
- Page helpers in [e2e/pages/](e2e/pages/) (e.g. [e2e/pages/popup.ts](e2e/pages/popup.ts))
1315

1416
## Fixture
1517

1618
The fixture extends Playwright with:
1719

18-
- **context:** Firefox persistent context that loads the unpacked extension from `dist/firefox-mv3`
20+
- **context:** Chromium persistent context that loads the unpacked extension from `dist/chrome-mv3`
1921
- **extensionId:** Resolved from the service worker (MV3) or background page otherwise
2022

2123
Use `context` and `extensionId` in tests. Import the extended `test` and `expect` from the fixture.
@@ -26,9 +28,10 @@ Navigate to `chrome-extension://${extensionId}/popup.html`. Use helpers like `op
2628

2729
## Run
2830

29-
- `pnpm test:e2e`
30-
- Build the extension first so `dist/` exists: `pnpm build:firefox` or `pnpm build`
31+
- First-time: `pnpm exec playwright install chromium` (installs Chromium and headless shell; do not use `--no-shell` or default tests will fail).
32+
- Build the extension: `pnpm build` so `dist/chrome-mv3` exists.
33+
- Run tests: `pnpm test:e2e`
3134

3235
## Note
3336

34-
`playwright-webextext` is in devDependencies for potential future use; current tests use the custom fixture in `fixutes.ts`.
37+
`playwright-webextext` is in devDependencies for potential future use; current tests use the custom fixture in `fixtures.ts`.

.github/workflows/playwright.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ jobs:
1616
- name: Install dependencies
1717
run: npm install -g pnpm && pnpm install
1818
- name: Install Playwright Browsers
19-
run: pnpm exec playwright install --with-deps
19+
run: pnpm exec playwright install chromium --with-deps
2020
- name: Run Playwright tests
21-
run: pnpm exec playwright test
21+
run: pnpm test:e2e
2222
- uses: actions/upload-artifact@v4
2323
if: ${{ !cancelled() }}
2424
with:

.nvimlog

Lines changed: 0 additions & 1 deletion
This file was deleted.

e2e/fixtures.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import {
2+
test as base,
3+
chromium,
4+
type BrowserContext,
5+
} from "@playwright/test";
6+
import path from "path";
7+
8+
const pathToExtension = path.resolve("dist/chrome-mv3");
9+
10+
export const test = base.extend<{
11+
context: BrowserContext;
12+
extensionId: string;
13+
}>({
14+
context: async ({}, use) => {
15+
const context = await chromium.launchPersistentContext("", {
16+
headless: !!process.env.CI,
17+
args: [
18+
`--disable-extensions-except=${pathToExtension}`,
19+
`--load-extension=${pathToExtension}`,
20+
],
21+
});
22+
await use(context);
23+
await context.close();
24+
},
25+
extensionId: async ({ context }, use) => {
26+
let [background] = context.serviceWorkers();
27+
if (!background) {
28+
background = await context.waitForEvent("serviceworker");
29+
}
30+
const extensionId = background.url().split("/")[2];
31+
await use(extensionId);
32+
},
33+
});
34+
export const expect = test.expect;

e2e/pages/popup.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { Page } from "@playwright/test";
33
export async function openPopup(page: Page, extensionId: string) {
44
await page.goto(`chrome-extension://${extensionId}/popup.html`);
55

6-
await page.waitForSelector("#counter");
6+
await page.waitForSelector("#active");
77

88
const popup = {
99
getCounter: () => page.waitForSelector("#active"),

e2e/tests/popup-counter.spec.ts

Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,7 @@
1-
// import { createFixture, withExtension } from "playwright-webextext";
1+
import { test, expect } from "../fixtures";
2+
import { openPopup } from "../pages/popup";
23

3-
import path from "node:path";
4-
// import { firefox } from "playwright";
5-
// import { expect } from "playwright/test";
6-
7-
let extensionPath = path.resolve("dist/firefox-mv3");
8-
console.log("🚀 ~ extensionPath:", extensionPath);
9-
10-
// const browser = await withExtension(firefox, extensionPath).launch({
11-
// headless: false,
12-
// });
13-
14-
// const { test, expect } = createFixture(extensionPath);
15-
16-
// test("Popup counter increments when clicked", async ({ page, }) => {
17-
18-
// });
19-
20-
// (async () => {
21-
// const page = await browser.newPage();
22-
// await page.goto("https://example.com/");
23-
// })();
4+
test("popup opens and shows active element", async ({ page, extensionId }) => {
5+
const popup = await openPopup(page, extensionId);
6+
await expect(page.locator("#active")).toBeVisible();
7+
});

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"fmt:check": "oxfmt --check",
1919
"lint": "oxlint",
2020
"postinstall": "wxt prepare",
21-
"test:e2e": "playwright test",
21+
"test:e2e": "pnpm build && playwright test",
2222
"wxt": "wxt",
2323
"zip": "wxt zip",
2424
"zip:all": "pnpm zip && pnpm zip:firefox",

playwright.config.ts

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,17 +31,11 @@ export default defineConfig({
3131
/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
3232
trace: "on-first-retry",
3333
},
34-
/* Configure projects for major browsers */
3534
projects: [
3635
{
3736
name: "chromium",
3837
use: { ...devices["Desktop Chrome"] },
3938
},
40-
41-
{
42-
name: "firefox",
43-
use: { ...devices["Desktop Firefox"] },
44-
},
4539
/* Test against mobile viewports. */
4640
// {
4741
// name: 'Mobile Chrome',
@@ -62,10 +56,9 @@ export default defineConfig({
6256
// use: { ...devices['Desktop Chrome'], channel: 'chrome' },
6357
// },
6458
],
65-
timeout: 5 * 60 * 1000,
6659
/* Run your local dev server before starting the tests */
6760
// webServer: {
68-
// command: 'npm run start',
61+
// command: 'pnpm dev',
6962
// url: 'http://localhost:3000',
7063
// reuseExistingServer: !process.env.CI,
7164
// },

src/lib/modules/ExtenstionSettings/App.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
status: "complete",
3232
});
3333
34-
if (tab.url) {
34+
if (tab?.url) {
3535
const url = new URL(tab.url);
3636
domain = url.host;
3737

0 commit comments

Comments
 (0)