@@ -9,22 +9,19 @@ function fixture(...args) {
99}
1010
1111async function write ( { input, output, plugin, outDir, options } ) {
12-
1312 const jsCodePath = path . join ( outDir , 'bundle.js' ) ;
1413
1514 const bundle = await rollup ( {
1615 input : fixture ( input ) ,
17- plugins : [
18- plugin ,
19- ] ,
16+ plugins : [ plugin ] ,
2017 } ) ;
2118
2219 await bundle . write ( {
2320 format : 'esm' ,
2421 file : path . join ( outDir , output ) ,
2522 sourcemap : true ,
2623 sourcemapFile : path . join ( outDir , `${ output } .map` ) ,
27- ...options
24+ ...options ,
2825 } ) ;
2926
3027 return {
@@ -44,21 +41,20 @@ async function write({ input, output, plugin, outDir, options }) {
4441 hasSourceMap ( bundle ) {
4542 const file = fs . readFileSync ( path . join ( outDir , bundle ) , 'utf8' ) ;
4643 return file . includes ( 'sourceMappingURL' ) ;
47- }
44+ } ,
4845 } ;
49-
5046}
5147
5248test ( 'should process with plugins declared in rollup.config.js' , async ( ) => {
5349 const res = await write ( {
5450 input : 'component.js' ,
5551 output : 'bundle.js' ,
56- outDir : 'test/onExtract ' ,
52+ outDir : 'test/extract ' ,
5753 plugin : inlinePostCSS ( {
5854 plugins : [ require ( 'postcss-csso' ) , require ( 'postcss-rgb-plz' ) ] ,
5955 } ) ,
6056 options : {
61- sourcemap : false
57+ sourcemap : false ,
6258 } ,
6359 } ) ;
6460 expect ( await res . hasRGBColorValues ( 'bundle.js' ) ) . toBe ( true ) ;
@@ -70,7 +66,7 @@ test('should process file with custom regex', async () => {
7066 const res = await write ( {
7167 input : 'custom.js' ,
7268 output : 'custom.js' ,
73- outDir : 'test/onExtract ' ,
69+ outDir : 'test/extract ' ,
7470 plugin : inlinePostCSS ( {
7571 styleRegex : / (?: f o o ` ) ( ( .| \n ) + ?) (? = ( ` ( \n | ; | , ) ) ) / gi,
7672 } ) ,
@@ -84,7 +80,7 @@ test('should reference postcss.config.js', async () => {
8480 const res = await write ( {
8581 input : 'component.js' ,
8682 output : 'config.js' ,
87- outDir : 'test/onExtract ' ,
83+ outDir : 'test/extract ' ,
8884 plugin : inlinePostCSS ( {
8985 configPath : path . join ( __dirname , 'config' ) ,
9086 } ) ,
@@ -98,13 +94,38 @@ test('should process multiple css declarations', async () => {
9894 const res = await write ( {
9995 input : 'multiple.js' ,
10096 output : 'multiple.js' ,
101- outDir : 'test/onExtract ' ,
97+ outDir : 'test/extract ' ,
10298 plugin : inlinePostCSS ( ) ,
10399 options : { } ,
104100 } ) ;
105101 expect ( await res . hasRGBColorValues ( 'multiple.js' ) ) . toBe ( true ) ;
106102 expect ( await res . hasSourceMap ( 'multiple.js' ) ) . toBe ( true ) ;
107- // expect(await res.isMinified('multiple.js')).toBe(true);
108103} ) ;
109104
105+ test ( 'should not minify css when environnment is development' , async ( ) => {
106+ const res = await write ( {
107+ input : 'custom.js' ,
108+ output : 'unminified.js' ,
109+ outDir : 'test/extract' ,
110+ plugin : inlinePostCSS ( {
111+ configPath : path . join ( __dirname , 'unminified' ) ,
112+ env : 'DEV' ,
113+ } ) ,
114+ options : { } ,
115+ } ) ;
116+ expect ( await res . isMinified ( 'unminified.js' ) ) . toBe ( false ) ;
117+ } ) ;
110118
119+ test ( 'should minify css when environnment is production' , async ( ) => {
120+ const res = await write ( {
121+ input : 'custom.js' ,
122+ output : 'minified.js' ,
123+ outDir : 'test/extract' ,
124+ plugin : inlinePostCSS ( {
125+ configPath : path . join ( __dirname , 'unminified' ) ,
126+ env : 'PROD' ,
127+ } ) ,
128+ options : { } ,
129+ } ) ;
130+ expect ( await res . isMinified ( 'minified.js' ) ) . toBe ( false ) ;
131+ } ) ;
0 commit comments