@@ -18,6 +18,7 @@ import {
1818 ContentScriptEntrypoint ,
1919 Entrypoint ,
2020 OutputAsset ,
21+ TargetManifestVersion ,
2122} from '../../../types' ;
2223import { wxt } from '../../wxt' ;
2324import { mock } from 'vitest-mock-extended' ;
@@ -198,6 +199,74 @@ describe('Manifest Utils', () => {
198199 expect ( ( actual . action as any ) . theme_icons ) . toEqual ( themeIcons ) ;
199200 } ) ;
200201
202+ describe ( 'default_state' , ( ) => {
203+ it . each < {
204+ browser : string ;
205+ manifestVersion : TargetManifestVersion ;
206+ type : 'browser_action' | 'action' | 'page_action' ;
207+ shouldExist : boolean ;
208+ } > ( [
209+ {
210+ browser : 'chrome' ,
211+ manifestVersion : 2 ,
212+ type : 'browser_action' ,
213+ shouldExist : false ,
214+ } ,
215+ {
216+ browser : 'chrome' ,
217+ manifestVersion : 3 ,
218+ type : 'action' ,
219+ shouldExist : true ,
220+ } ,
221+ {
222+ browser : 'firefox' ,
223+ manifestVersion : 2 ,
224+ type : 'browser_action' ,
225+ shouldExist : false ,
226+ } ,
227+ {
228+ browser : 'firefox' ,
229+ manifestVersion : 3 ,
230+ type : 'action' ,
231+ shouldExist : true ,
232+ } ,
233+ ] ) (
234+ 'should configure default_state: $defaultState based on the $browser and mv$manifestVersion' ,
235+ async ( { browser, manifestVersion, type, shouldExist } ) => {
236+ const popup = fakePopupEntrypoint ( {
237+ options : {
238+ // @ts -expect-error: Force this to be undefined when null
239+ actionType : manifestVersion === 3 ? null : type ,
240+ defaultState : 'enabled' ,
241+ } ,
242+ outputDir : outDir ,
243+ skipped : false ,
244+ } ) ;
245+ const buildOutput = fakeBuildOutput ( ) ;
246+ setFakeWxt ( {
247+ config : {
248+ browser,
249+ manifestVersion,
250+ outDir,
251+ } ,
252+ } ) ;
253+
254+ const { manifest : actual } = await generateManifest (
255+ [ popup ] ,
256+ buildOutput ,
257+ ) ;
258+
259+ if ( shouldExist ) {
260+ expect ( actual [ type ] ) . toMatchObject ( {
261+ default_state : 'enabled' ,
262+ } ) ;
263+ } else {
264+ expect ( actual [ type ] . default_state ) . toBeUndefined ( ) ;
265+ }
266+ } ,
267+ ) ;
268+ } ) ;
269+
201270 it ( 'should include default_area for Firefox in mv2' , async ( ) => {
202271 const popup = fakePopupEntrypoint ( {
203272 options : {
0 commit comments