Skip to content

Privacy-first password manager with built-in email aliasing. Fully encrypted and self-hostable.

Update browser extension test commands (#2413)

Leendert de Borst53ef838a74e5
diff --git a/apps/browser-extension/package.json b/apps/browser-extension/package.json
index 1bac3d867..feba66ccb 100644
--- a/apps/browser-extension/package.json
+++ b/apps/browser-extension/package.json
@@ -18,6 +18,7 @@
"test:coverage": "vitest run --coverage",
"test:e2e": "playwright test",
"test:e2e:build": "node scripts/run-e2e.mjs",
+ "test:e2e:headed": "node scripts/run-e2e.mjs --headed --workers=1",
"lint": "eslint src",
"lint:custom": "eslint",
"lint:fix": "eslint src --fix",
diff --git a/apps/browser-extension/playwright.config.ts b/apps/browser-extension/playwright.config.ts
index 2d06c5b0b..47b7e3741 100644
--- a/apps/browser-extension/playwright.config.ts
+++ b/apps/browser-extension/playwright.config.ts
@@ -31,7 +31,7 @@ export default defineConfig({
// Amount of parallel tests to run
// Reduce workers in CI to prevent resource exhaustion when multi-client tests
- // spawn multiple browser contexts under xvfb
+ // spawn multiple browser contexts
workers: process.env.CI ? 1 : 4,
// Reporter configuration
diff --git a/apps/browser-extension/tests/fixtures/TestClient.ts b/apps/browser-extension/tests/fixtures/TestClient.ts
index 7de5bd6f4..12ab171e8 100644
--- a/apps/browser-extension/tests/fixtures/TestClient.ts
+++ b/apps/browser-extension/tests/fixtures/TestClient.ts
@@ -11,11 +11,8 @@
* ```
*/
import type { BrowserContext, Page } from '@playwright/test';
-import { chromium } from '@playwright/test';
-import path from 'path';
-import { fileURLToPath } from 'url';
-import { expect } from './fixtures';
+import { createFreshContext, expect } from './fixtures';
import { completeVaultUpgrade } from './helpers';
import { FieldSelectors, ButtonSelectors } from './selectors';
import {
@@ -30,10 +27,6 @@ import {
Timeouts,
} from './waits';
-const __filename = fileURLToPath(import.meta.url);
-const __dirname = path.dirname(__filename);
-const EXTENSION_PATH = path.join(__dirname, '..', '..', 'dist', 'chrome-mv3');
-
/**
* TestClient provides a fluent API for E2E testing of the browser extension.
*/
@@ -52,22 +45,7 @@ export class TestClient {
* Create a new TestClient with a fresh browser context.
*/
static async create(): Promise<TestClient> {
- const context = await chromium.launchPersistentContext('', {
- headless: false,
- args: [
- `--disable-extensions-except=${EXTENSION_PATH}`,
- `--load-extension=${EXTENSION_PATH}`,
- '--no-first-run',
- '--disable-gpu',
- ],
- });
-
- // Wait for service worker and get extension ID
- let [background] = context.serviceWorkers();
- if (!background) {
- background = await context.waitForEvent('serviceworker');
- }
- const extensionId = background.url().split('/')[2];
+ const { context, extensionId } = await createFreshContext();
// Open popup
const popup = await context.newPage();
diff --git a/apps/browser-extension/tests/fixtures/fixtures.ts b/apps/browser-extension/tests/fixtures/fixtures.ts
index db9629c8e..c84161bda 100644
--- a/apps/browser-extension/tests/fixtures/fixtures.ts
+++ b/apps/browser-extension/tests/fixtures/fixtures.ts
@@ -65,23 +65,8 @@ export const test = base.extend<TestFixtures>({
// Create new context if we don't have one for this file
if (!cachedContext) {
- cachedContext = await chromium.launchPersistentContext('', {
- headless: false, // Extensions require headed mode
- args: [
- `--disable-extensions-except=${EXTENSION_PATH}`,
- `--load-extension=${EXTENSION_PATH}`,
- '--no-first-run',
- '--disable-gpu',
- ],
- });
+ ({ context: cachedContext, extensionId: cachedExtensionId } = await createFreshContext());
contextTestFile = currentTestFile;
-
- // Wait for service worker and get extension ID
- let [background] = cachedContext.serviceWorkers();
- if (!background) {
- background = await cachedContext.waitForEvent('serviceworker');
- }
- cachedExtensionId = background.url().split('/')[2];
}
await use(cachedContext);
@@ -265,7 +250,12 @@ export async function fullLoginFlow(
*/
export async function createFreshContext(): Promise<{ context: BrowserContext; extensionId: string }> {
const context = await chromium.launchPersistentContext('', {
- headless: false, // Extensions require headed mode
+ /*
+ * Headless unless run with `--headed`/`--debug`. The `chromium` channel is the full browser in new headless
+ * mode, which loads extensions; the default headless shell does not.
+ */
+ channel: 'chromium',
+ headless: isHeadless(),
args: [
`--disable-extensions-except=${EXTENSION_PATH}`,
`--load-extension=${EXTENSION_PATH}`,
@@ -283,3 +273,15 @@ export async function createFreshContext(): Promise<{ context: BrowserContext; e
return { context, extensionId };
}
+
+/**
+ * Whether to launch headless: the project's `headless` option, which the `--headed` CLI flag overrides.
+ */
+function isHeadless(): boolean {
+ try {
+ return base.info().project.use.headless ?? true;
+ } catch {
+ // Called outside a running test or hook.
+ return true;
+ }
+}