@@ -4,53 +4,48 @@ import path from "path";
44const pathToExtension = path . resolve ( ".output/chrome-mv3" ) ;
55
66type Fixtures = {
7- context : BrowserContext ;
8- extensionId : string ;
7+ context : BrowserContext ;
8+ extensionId : string ;
99} ;
1010
1111export const test = base . extend < Fixtures > ( {
12- context : async ( { } , use ) => {
13- const context = await chromium . launchPersistentContext ( "" , {
14- headless : true ,
15- timeout : 60000 ,
16- args : [
17- `--disable-extensions-except=${ pathToExtension } ` ,
18- `--load-extension=${ pathToExtension } ` ,
19- ] ,
20- } ) ;
21- await use ( context ) ;
22- await Promise . all ( context . pages ( ) . map ( p => p . close ( ) . catch ( ( ) => { } ) ) ) ;
23- await Promise . race ( [
24- context . close ( ) ,
25- new Promise < void > ( resolve => setTimeout ( resolve , 5000 ) ) ,
26- ] ) ;
27- } ,
28- extensionId : async ( { context } , use ) => {
29- let background : { url ( ) : string } ;
30- if ( pathToExtension . endsWith ( "-mv3" ) ) {
31- const swPromise = context . waitForEvent ( "serviceworker" , { timeout : 120000 } ) ;
32- const serviceWorkers = context . serviceWorkers ( ) ;
33- if ( serviceWorkers . length > 0 ) {
34- background = serviceWorkers [ 0 ] ;
35- } else {
36- try {
37- background = await swPromise ;
38- } catch ( error ) {
39- throw new Error (
40- `Failed to load extension service worker within 60s. ` +
41- `Ensure extension is built (wxt build) and output exists at ${ pathToExtension } . ${ error } `
42- ) ;
43- }
44- }
45- } else {
46- [ background ] = context . backgroundPages ( ) ;
47- if ( ! background )
48- background = await context . waitForEvent ( "backgroundpage" ) ;
12+ context : async ( { } , use ) => {
13+ const context = await chromium . launchPersistentContext ( "" , {
14+ headless : true ,
15+ timeout : 60000 ,
16+ args : [
17+ `--disable-extensions-except=${ pathToExtension } ` ,
18+ `--load-extension=${ pathToExtension } ` ,
19+ ] ,
20+ } ) ;
21+ await use ( context ) ;
22+ } ,
23+ extensionId : async ( { context } , use ) => {
24+ let background : { url ( ) : string } ;
25+ if ( pathToExtension . endsWith ( "-mv3" ) ) {
26+ const swPromise = context . waitForEvent ( "serviceworker" , { timeout : 120000 } ) ;
27+ const serviceWorkers = context . serviceWorkers ( ) ;
28+ if ( serviceWorkers . length > 0 ) {
29+ background = serviceWorkers [ 0 ] ;
30+ } else {
31+ try {
32+ background = await swPromise ;
33+ } catch ( error ) {
34+ throw new Error (
35+ `Failed to load extension service worker within 60s. ` +
36+ `Ensure extension is built (wxt build) and output exists at ${ pathToExtension } . ${ error } `
37+ ) ;
4938 }
39+ }
40+ } else {
41+ [ background ] = context . backgroundPages ( ) ;
42+ if ( ! background )
43+ background = await context . waitForEvent ( "backgroundpage" ) ;
44+ }
5045
51- const extensionId = background . url ( ) . split ( "/" ) [ 2 ] ;
52- await use ( extensionId ) ;
53- } ,
46+ const extensionId = background . url ( ) . split ( "/" ) [ 2 ] ;
47+ await use ( extensionId ) ;
48+ } ,
5449} ) ;
5550
56- export const { Given, When, Then } = createBdd ( test ) ;
51+ export const { Given, When, Then } = createBdd ( test ) ;
0 commit comments