@@ -10,6 +10,7 @@ import {
10
10
fakeOptionsEntrypoint ,
11
11
fakePopupEntrypoint ,
12
12
fakeSidepanelEntrypoint ,
13
+ fakeWxtDevServer ,
13
14
setFakeWxt ,
14
15
} from '../testing/fake-objects' ;
15
16
import { Manifest } from 'webextension-polyfill' ;
@@ -1496,6 +1497,89 @@ describe('Manifest Utils', () => {
1496
1497
expect ( actual . host_permissions ) . toBeUndefined ( ) ;
1497
1498
} ) ;
1498
1499
} ) ;
1500
+
1501
+ describe ( 'Dev mode' , ( ) => {
1502
+ it ( 'should not add any code for production builds' , async ( ) => {
1503
+ setFakeWxt ( {
1504
+ config : {
1505
+ command : 'build' ,
1506
+ } ,
1507
+ server : {
1508
+ hostname : 'localhost' ,
1509
+ port : 3000 ,
1510
+ origin : 'http://localhost:3000' ,
1511
+ } ,
1512
+ } ) ;
1513
+ const output = fakeBuildOutput ( ) ;
1514
+ const entrypoints : Entrypoint [ ] = [ ] ;
1515
+
1516
+ const { manifest : actual } = await generateManifest (
1517
+ entrypoints ,
1518
+ output ,
1519
+ ) ;
1520
+
1521
+ expect ( actual . permissions ) . toBeUndefined ( ) ;
1522
+ expect ( actual . content_security_policy ) . toBeUndefined ( ) ;
1523
+ } ) ;
1524
+
1525
+ it ( 'should add required permissions for dev mode to function for MV2' , async ( ) => {
1526
+ setFakeWxt ( {
1527
+ config : {
1528
+ command : 'serve' ,
1529
+ manifestVersion : 2 ,
1530
+ } ,
1531
+ server : fakeWxtDevServer ( {
1532
+ port : 3000 ,
1533
+ hostname : 'localhost' ,
1534
+ origin : 'http://localhost:3000' ,
1535
+ } ) ,
1536
+ } ) ;
1537
+ const output = fakeBuildOutput ( ) ;
1538
+ const entrypoints : Entrypoint [ ] = [ ] ;
1539
+
1540
+ const { manifest : actual } = await generateManifest (
1541
+ entrypoints ,
1542
+ output ,
1543
+ ) ;
1544
+
1545
+ expect ( actual ) . toMatchObject ( {
1546
+ content_security_policy :
1547
+ "script-src 'self' http://localhost:3000; object-src 'self';" ,
1548
+ permissions : [ 'http://localhost/*' , 'tabs' ] ,
1549
+ } ) ;
1550
+ } ) ;
1551
+
1552
+ it ( 'should add required permissions for dev mode to function for MV3' , async ( ) => {
1553
+ setFakeWxt ( {
1554
+ config : {
1555
+ command : 'serve' ,
1556
+ manifestVersion : 3 ,
1557
+ browser : 'chrome' ,
1558
+ } ,
1559
+ server : fakeWxtDevServer ( {
1560
+ hostname : 'localhost' ,
1561
+ port : 3000 ,
1562
+ origin : 'http://localhost:3000' ,
1563
+ } ) ,
1564
+ } ) ;
1565
+ const output = fakeBuildOutput ( ) ;
1566
+ const entrypoints : Entrypoint [ ] = [ ] ;
1567
+
1568
+ const { manifest : actual } = await generateManifest (
1569
+ entrypoints ,
1570
+ output ,
1571
+ ) ;
1572
+
1573
+ expect ( actual ) . toMatchObject ( {
1574
+ content_security_policy : {
1575
+ extension_pages :
1576
+ "script-src 'self' 'wasm-unsafe-eval' http://localhost:3000; object-src 'self';" ,
1577
+ } ,
1578
+ host_permissions : [ 'http://localhost/*' ] ,
1579
+ permissions : [ 'tabs' , 'scripting' ] ,
1580
+ } ) ;
1581
+ } ) ;
1582
+ } ) ;
1499
1583
} ) ;
1500
1584
1501
1585
describe ( 'stripPathFromMatchPattern' , ( ) => {
0 commit comments