@@ -383,6 +383,69 @@ describe('Output Directory Structure', () => {
383
383
` ) ;
384
384
} ) ;
385
385
386
+ it ( 'should support a custom IIFE name' , async ( ) => {
387
+ const project = new TestProject ( ) ;
388
+ project . addFile (
389
+ 'entrypoints/background.js' ,
390
+ `export default defineBackground(() => {});` ,
391
+ ) ;
392
+
393
+ await project . build ( {
394
+ iifeName : ( entryPointName ) => `custom_iife_name_${ entryPointName } ` ,
395
+ vite : ( ) => ( {
396
+ build : {
397
+ // Make output for snapshot readable
398
+ minify : false ,
399
+ } ,
400
+ } ) ,
401
+ } ) ;
402
+
403
+ const contents = await project . serializeFile (
404
+ '.output/chrome-mv3/background.js' ,
405
+ ) ;
406
+ expect ( contents ) . toMatchInlineSnapshot ( `
407
+ ".output/chrome-mv3/background.js
408
+ ----------------------------------------
409
+ var custom_iife_name_background = (function() {
410
+ "use strict";
411
+ function defineBackground(arg) {
412
+ if (arg == null || typeof arg === "function") return { main: arg };
413
+ return arg;
414
+ }
415
+ const definition = defineBackground(() => {
416
+ });
417
+ function initPlugins() {
418
+ }
419
+ globalThis.browser?.runtime?.id ? globalThis.browser : globalThis.chrome;
420
+ function print(method, ...args) {
421
+ return;
422
+ }
423
+ const logger = {
424
+ debug: (...args) => print(console.debug, ...args),
425
+ log: (...args) => print(console.log, ...args),
426
+ warn: (...args) => print(console.warn, ...args),
427
+ error: (...args) => print(console.error, ...args)
428
+ };
429
+ let result;
430
+ try {
431
+ initPlugins();
432
+ result = definition.main();
433
+ if (result instanceof Promise) {
434
+ console.warn(
435
+ "The background's main() function return a promise, but it must be synchronous"
436
+ );
437
+ }
438
+ } catch (err) {
439
+ logger.error("The background crashed on startup!");
440
+ throw err;
441
+ }
442
+ const result$1 = result;
443
+ return result$1;
444
+ })();
445
+ "
446
+ ` ) ;
447
+ } ) ;
448
+
386
449
it ( 'should generate IIFE background script when type=undefined' , async ( ) => {
387
450
const project = new TestProject ( ) ;
388
451
project . addFile (
0 commit comments