@@ -81,95 +81,105 @@ describe('extension build', () => {
8181 ...ALL_TEMPLATES . filter (
8282 ( t ) => ! t . name . includes ( 'tailwind' ) && ! t . name . includes ( 'custom-font' )
8383 )
84- ] ) ( `builds an extension created via "$name" template` , async ( template ) => {
85- const templatePath = path . resolve ( repoRoot , 'examples' , template . name )
84+ ] ) (
85+ `builds an extension created via "$name" template` ,
86+ async ( template ) => {
87+ const templatePath = path . resolve ( repoRoot , 'examples' , template . name )
8688
87- // Ensure a clean dist before building this template in case of prior runs
88- await removeDir ( path . join ( templatePath , 'dist' ) )
89- await extensionBuild ( templatePath , {
90- browser : SUPPORTED_BROWSERS [ 0 ] as 'chrome'
91- } )
89+ // Ensure a clean dist before building this template in case of prior runs
90+ await removeDir ( path . join ( templatePath , 'dist' ) )
91+ await extensionBuild ( templatePath , {
92+ browser : SUPPORTED_BROWSERS [ 0 ] as 'chrome'
93+ } )
9294
93- {
94- const manifestPath = path . join (
95- templatePath ,
96- 'dist' ,
97- SUPPORTED_BROWSERS [ 0 ] ,
98- 'manifest.json'
99- )
100- // Retry a few times in case of slow FS writes
101- let exists = fs . existsSync ( manifestPath )
102- if ( ! exists ) {
103- for ( let i = 0 ; i < 5 && ! exists ; i ++ ) {
104- await new Promise ( ( r ) => setTimeout ( r , 50 ) )
105- exists = fs . existsSync ( manifestPath )
95+ {
96+ const manifestPath = path . join (
97+ templatePath ,
98+ 'dist' ,
99+ SUPPORTED_BROWSERS [ 0 ] ,
100+ 'manifest.json'
101+ )
102+ // Retry for up to ~10s in case of slow FS writes
103+ let exists = fs . existsSync ( manifestPath )
104+ if ( ! exists ) {
105+ const start = Date . now ( )
106+ while ( ! exists && Date . now ( ) - start < 10000 ) {
107+ await new Promise ( ( r ) => setTimeout ( r , 50 ) )
108+ exists = fs . existsSync ( manifestPath )
109+ }
106110 }
111+ expect ( exists ) . toBeTruthy ( )
107112 }
108- expect ( exists ) . toBeTruthy ( )
109- }
110-
111- const manifestText = fs . readFileSync (
112- path . join ( templatePath , 'dist' , SUPPORTED_BROWSERS [ 0 ] , 'manifest.json' ) ,
113- 'utf-8'
114- )
115113
116- const manifest : Manifest = JSON . parse ( manifestText )
117- expect ( manifest . name ) . toBeTruthy ( )
118- expect ( manifest . version ) . toBeTruthy ( )
119- expect ( manifest . manifest_version ) . toBeTruthy ( )
120-
121- // Validate expected HTML entry points when declared in manifest
122- const distDir = path . join ( templatePath , 'dist' , SUPPORTED_BROWSERS [ 0 ] )
123- const ensureFile = ( relPath : string | undefined ) => {
124- if ( ! relPath ) return
125- const absPath = path . join ( distDir , relPath )
126- expect ( fs . existsSync ( absPath ) ) . toBeTruthy ( )
127- }
128- // action popup
129- ensureFile ( ( manifest as any ) . action ?. default_popup )
130- // options ui (v3) / options page (v2)
131- ensureFile ( ( manifest as any ) . options_ui ?. page )
132- ensureFile ( ( manifest as any ) . options_page )
133- // devtools
134- ensureFile ( ( manifest as any ) . devtools_page )
135- // chrome_url_overrides
136- const overrides = ( manifest as any ) . chrome_url_overrides
137- if ( overrides ) {
138- ensureFile ( overrides . newtab )
139- ensureFile ( overrides . history )
140- ensureFile ( overrides . bookmarks )
141- }
142- // sandbox pages
143- const sandboxPages : string [ ] | undefined = ( manifest as any ) . sandbox
144- ?. pages
145- if ( Array . isArray ( sandboxPages ) && sandboxPages . length > 0 ) {
146- ensureFile ( sandboxPages [ 0 ] )
147- }
148-
149- if ( template . name . includes ( 'content' ) ) {
150- expect ( manifest . content_scripts ! [ 0 ] . js ! [ 0 ] ) . toEqual (
151- 'content_scripts/content-0.js'
114+ const manifestText = fs . readFileSync (
115+ path . join (
116+ templatePath ,
117+ 'dist' ,
118+ SUPPORTED_BROWSERS [ 0 ] ,
119+ 'manifest.json'
120+ ) ,
121+ 'utf-8'
152122 )
153123
154- expect (
155- distFileExists (
156- template . name ,
157- SUPPORTED_BROWSERS [ 0 ] ,
124+ const manifest : Manifest = JSON . parse ( manifestText )
125+ expect ( manifest . name ) . toBeTruthy ( )
126+ expect ( manifest . version ) . toBeTruthy ( )
127+ expect ( manifest . manifest_version ) . toBeTruthy ( )
128+
129+ // Validate expected HTML entry points when declared in manifest
130+ const distDir = path . join ( templatePath , 'dist' , SUPPORTED_BROWSERS [ 0 ] )
131+ const ensureFile = ( relPath : string | undefined ) => {
132+ if ( ! relPath ) return
133+ const absPath = path . join ( distDir , relPath )
134+ expect ( fs . existsSync ( absPath ) ) . toBeTruthy ( )
135+ }
136+ // action popup
137+ ensureFile ( ( manifest as any ) . action ?. default_popup )
138+ // options ui (v3) / options page (v2)
139+ ensureFile ( ( manifest as any ) . options_ui ?. page )
140+ ensureFile ( ( manifest as any ) . options_page )
141+ // devtools
142+ ensureFile ( ( manifest as any ) . devtools_page )
143+ // chrome_url_overrides
144+ const overrides = ( manifest as any ) . chrome_url_overrides
145+ if ( overrides ) {
146+ ensureFile ( overrides . newtab )
147+ ensureFile ( overrides . history )
148+ ensureFile ( overrides . bookmarks )
149+ }
150+ // sandbox pages
151+ const sandboxPages : string [ ] | undefined = ( manifest as any ) . sandbox
152+ ?. pages
153+ if ( Array . isArray ( sandboxPages ) && sandboxPages . length > 0 ) {
154+ ensureFile ( sandboxPages [ 0 ] )
155+ }
156+
157+ if ( template . name . includes ( 'content' ) ) {
158+ expect ( manifest . content_scripts ! [ 0 ] . js ! [ 0 ] ) . toEqual (
158159 'content_scripts/content-0.js'
159160 )
160- ) . toBeTruthy ( )
161- }
162161
163- // Basic asset sanity: icons and optional assets folder when present
164- expect ( fs . existsSync ( path . join ( distDir , 'icons' ) ) ) . toBeTruthy ( )
165- // When assets exist, ensure at least one file is emitted
166- const assetsDir = path . join ( distDir , 'assets' )
167- if ( fs . existsSync ( assetsDir ) ) {
168- const assets = fs . readdirSync ( assetsDir )
169- expect ( Array . isArray ( assets ) ) . toBe ( true )
170- expect ( assets . length ) . toBeGreaterThan ( 0 )
171- }
172- } )
162+ expect (
163+ distFileExists (
164+ template . name ,
165+ SUPPORTED_BROWSERS [ 0 ] ,
166+ 'content_scripts/content-0.js'
167+ )
168+ ) . toBeTruthy ( )
169+ }
170+
171+ // Basic asset sanity: icons and optional assets folder when present
172+ expect ( fs . existsSync ( path . join ( distDir , 'icons' ) ) ) . toBeTruthy ( )
173+ // When assets exist, ensure at least one file is emitted
174+ const assetsDir = path . join ( distDir , 'assets' )
175+ if ( fs . existsSync ( assetsDir ) ) {
176+ const assets = fs . readdirSync ( assetsDir )
177+ expect ( Array . isArray ( assets ) ) . toBe ( true )
178+ expect ( assets . length ) . toBeGreaterThan ( 0 )
179+ }
180+ } ,
181+ 30000
182+ )
173183 } )
174184
175185 afterEach ( async ( ) => {
0 commit comments