Skip to content

Commit

Permalink
fix: extension testing with new chromium headless
Browse files Browse the repository at this point in the history
  • Loading branch information
hugomrdias committed Feb 10, 2025
1 parent 0687f39 commit 88b5559
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
9 changes: 8 additions & 1 deletion src/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,17 @@ export class Runner {
this.server = server

// download playwright if needed
const pw = await getPw(this.options.browser, this.options.debug)
const pw = await getPw(
this.options.browser,
this.options.debug,
this.options.extension
)

/** @type {import('playwright-core').LaunchOptions} */
const pwOptions = {
// optin to new chromium headless for extension testing
// https://github.com/microsoft/playwright/issues/33566
channel: this.options.extension ? this.options.browser : undefined,
headless: !this.options.debug,
devtools: this.options.browser === 'chromium' && this.options.debug,
args: this.options.extension
Expand Down
2 changes: 1 addition & 1 deletion src/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export interface RunnerOptions {
testRunner: TestRunner
cwd: string
extensions: string
browser: 'chromium' | 'firefox' | 'webkit'
browser: 'chromium' | 'firefox' | 'webkit' | 'chromium-headless-shell'
debug: boolean
mode: 'main' | 'worker' | 'node'
incognito: boolean
Expand Down
6 changes: 4 additions & 2 deletions src/utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -293,14 +293,15 @@ export async function redirectConsole(msg) {
* @template {RunnerOptions["browser"]} TBrowser
* @param {TBrowser} browserName
* @param {boolean} debug
* @param {boolean} extension
* @returns {Promise<import('playwright-core').BrowserType<import('../types').PwResult<TBrowser>>>}
*/
export async function getPw(browserName, debug) {
export async function getPw(browserName, debug, extension) {
if (!['chromium', 'firefox', 'webkit'].includes(String(browserName))) {
throw new Error(`Browser not supported: ${browserName}`)
}

if (browserName === 'chromium' && !debug) {
if (browserName === 'chromium' && !debug && !extension) {
// @ts-ignore
browserName = 'chromium-headless-shell'
}
Expand Down Expand Up @@ -328,6 +329,7 @@ export async function getPw(browserName, debug) {
return api.chromium
}

// @ts-ignore
return api[browserName]
}

Expand Down

0 comments on commit 88b5559

Please sign in to comment.