|
1 | 1 | /** |
2 | | - * Playwright fixture for loading the Harbor extension in Firefox. |
3 | | - * |
4 | | - * Firefox extension loading is complex. This fixture provides: |
5 | | - * 1. A basic browser context (no extensions) for simple page tests |
6 | | - * 2. Extension-aware context using web-ext for full integration tests |
| 2 | + * Playwright fixture for a plain Firefox browser context. |
| 3 | + * |
| 4 | + * This context has no extensions. Playwright can't load Harbor into a Firefox |
| 5 | + * it drives, so tests that need Harbor itself use the launch-and-RDP scripts |
| 6 | + * in tests/e2e (`npm run test:browser`, `npm run test:demo-pages` and the |
| 7 | + * other `test-*.mjs`). |
7 | 8 | */ |
8 | 9 |
|
9 | | -import { test as base, firefox, type BrowserContext, type Page } from '@playwright/test'; |
10 | | -import path from 'path'; |
11 | | -import fs from 'fs/promises'; |
12 | | -import os from 'os'; |
13 | | -import { fileURLToPath } from 'url'; |
14 | | -import { spawn, type ChildProcess, execSync } from 'child_process'; |
15 | | - |
16 | | -const __dirname = path.dirname(fileURLToPath(import.meta.url)); |
17 | | - |
18 | | -// Path relative to the test fixtures directory |
19 | | -const EXTENSION_PATH = path.resolve(__dirname, '../../../extension/dist'); |
| 10 | +import { test as base, firefox, type BrowserContext } from '@playwright/test'; |
20 | 11 |
|
21 | 12 | export type ExtensionFixtures = { |
22 | 13 | /** Basic browser context without extensions - for simple page tests */ |
23 | 14 | browserContext: BrowserContext; |
24 | | - /** Browser context with the extension loaded via web-ext */ |
25 | | - extensionContext: BrowserContext; |
26 | | - extensionId: string; |
27 | | - sidebarPage: Page; |
28 | 15 | }; |
29 | 16 |
|
30 | | -/** |
31 | | - * Check if web-ext is available |
32 | | - */ |
33 | | -function hasWebExt(): boolean { |
34 | | - try { |
35 | | - execSync('npx web-ext --version', { stdio: 'ignore' }); |
36 | | - return true; |
37 | | - } catch { |
38 | | - return false; |
39 | | - } |
40 | | -} |
41 | | - |
42 | 17 | export const test = base.extend<ExtensionFixtures>({ |
43 | | - /** |
44 | | - * Basic browser context without extensions. |
45 | | - * Use this for tests that just need to load web pages. |
46 | | - */ |
47 | 18 | browserContext: async ({}, use) => { |
48 | | - const context = await firefox.launch({ |
| 19 | + const browser = await firefox.launch({ |
49 | 20 | headless: false, |
50 | 21 | firefoxUserPrefs: { |
51 | 22 | 'devtools.chrome.enabled': true, |
52 | 23 | }, |
53 | 24 | }); |
54 | | - |
55 | | - const browserContext = await context.newContext(); |
| 25 | + |
| 26 | + const browserContext = await browser.newContext(); |
56 | 27 | await use(browserContext); |
57 | 28 | await browserContext.close(); |
58 | | - await context.close(); |
59 | | - }, |
60 | | - |
61 | | - /** |
62 | | - * Browser context with extensions. |
63 | | - * |
64 | | - * This uses a persistent context with extensions installed via profile. |
65 | | - * For full extension testing, web-ext is recommended but adds complexity. |
66 | | - */ |
67 | | - extensionContext: async ({}, use) => { |
68 | | - // Create a temporary profile directory |
69 | | - const profileDir = await fs.mkdtemp(path.join(os.tmpdir(), 'harbor-test-')); |
70 | | - |
71 | | - // Write Firefox preferences to enable extension loading |
72 | | - const prefsContent = [ |
73 | | - 'user_pref("xpinstall.signatures.required", false);', |
74 | | - 'user_pref("extensions.autoDisableScopes", 0);', |
75 | | - 'user_pref("extensions.enabledScopes", 15);', |
76 | | - 'user_pref("devtools.chrome.enabled", true);', |
77 | | - 'user_pref("app.update.enabled", false);', |
78 | | - 'user_pref("browser.shell.checkDefaultBrowser", false);', |
79 | | - 'user_pref("datareporting.policy.dataSubmissionEnabled", false);', |
80 | | - 'user_pref("toolkit.telemetry.reportingpolicy.firstRun", false);', |
81 | | - ].join('\n'); |
82 | | - |
83 | | - await fs.writeFile(path.join(profileDir, 'user.js'), prefsContent); |
84 | | - |
85 | | - // Launch Firefox with the profile |
86 | | - const context = await firefox.launchPersistentContext(profileDir, { |
87 | | - headless: false, |
88 | | - firefoxUserPrefs: { |
89 | | - 'xpinstall.signatures.required': false, |
90 | | - 'extensions.autoDisableScopes': 0, |
91 | | - 'extensions.enabledScopes': 15, |
92 | | - }, |
93 | | - }); |
94 | | - |
95 | | - await use(context); |
96 | | - |
97 | | - // Cleanup |
98 | | - await context.close(); |
99 | | - try { |
100 | | - await fs.rm(profileDir, { recursive: true, force: true }); |
101 | | - } catch { |
102 | | - // Ignore cleanup errors |
103 | | - } |
104 | | - }, |
105 | | - |
106 | | - /** |
107 | | - * Harbor extension UUID - placeholder for now |
108 | | - */ |
109 | | - extensionId: async ({}, use) => { |
110 | | - // Extension UUID is assigned dynamically by Firefox |
111 | | - // For tests that need this, they should load via about:debugging |
112 | | - await use('extension-not-loaded'); |
113 | | - }, |
114 | | - |
115 | | - /** |
116 | | - * Harbor sidebar page - requires extension to be loaded |
117 | | - */ |
118 | | - sidebarPage: async ({ extensionContext }, use) => { |
119 | | - const page = await extensionContext.newPage(); |
120 | | - // Can't navigate to extension page without UUID |
121 | | - // Tests using this will need to handle the case |
122 | | - await use(page); |
| 29 | + await browser.close(); |
123 | 30 | }, |
124 | 31 | }); |
125 | 32 |
|
|
0 commit comments