@@ -50,71 +50,71 @@ const fixtureLocation = (category, name, format, optionsKey, minified = false) =
5050 : `${ name } .js`
5151 } `;
5252
53- function generate ( shouldFail , category , name , codeSplit , formats , closureFlags ) {
54- const targetLength = longest ( formats ) ;
55- const optionLength = longest ( Object . keys ( closureFlags ) ) ;
53+ async function compile ( category , name , codeSplit , closureFlags , optionKey , format ) {
54+ const bundle = await rollup . rollup ( {
55+ input : fixtureLocation ( category , name , format , optionKey , false ) ,
56+ plugins : [ compiler ( closureFlags [ optionKey ] ) ] ,
57+ external : [ 'lodash' , './external.js' , './external-default.js' ] ,
58+ experimentalCodeSplitting : codeSplit ,
59+ onwarn : _ => null ,
60+ } ) ;
5661
57- async function compile ( optionKey , format ) {
58- const bundle = await rollup . rollup ( {
59- input : fixtureLocation ( category , name , format , optionKey , false ) ,
60- plugins : [ compiler ( closureFlags [ optionKey ] ) ] ,
61- external : [ 'lodash' , './external.js' , './external-default.js' ] ,
62- experimentalCodeSplitting : codeSplit ,
63- onwarn : _ => null ,
64- } ) ;
62+ const bundles = await bundle . generate ( {
63+ format,
64+ sourcemap : true ,
65+ } ) ;
6566
66- const bundles = await bundle . generate ( {
67- format,
68- sourcemap : true ,
69- } ) ;
70-
71- const output = [ ] ;
72- if ( bundles . output ) {
73- for ( file in bundles . output ) {
74- const minified = await fs . promises . readFile (
75- path . join (
76- fixtureLocation (
77- category ,
78- path . parse ( bundles . output [ file ] . fileName ) . name ,
79- format ,
80- optionKey ,
81- true ,
82- ) ,
83- ) ,
84- 'utf8' ,
85- ) ;
86- output . push ( {
87- minified,
88- code : bundles . output [ file ] . code ,
89- } ) ;
90- }
91- } else {
67+ const output = [ ] ;
68+ if ( bundles . output ) {
69+ for ( file in bundles . output ) {
9270 const minified = await fs . promises . readFile (
9371 path . join (
94- fixtureLocation ( category , path . parse ( bundles . fileName ) . name , format , optionKey , true ) ,
72+ fixtureLocation (
73+ category ,
74+ path . parse ( bundles . output [ file ] . fileName ) . name ,
75+ format ,
76+ optionKey ,
77+ true ,
78+ ) ,
9579 ) ,
9680 'utf8' ,
9781 ) ;
9882 output . push ( {
9983 minified,
100- code : bundles . code ,
84+ code : bundles . output [ file ] . code ,
10185 } ) ;
10286 }
103-
104- return output ;
87+ } else {
88+ const minified = await fs . promises . readFile (
89+ path . join (
90+ fixtureLocation ( category , path . parse ( bundles . fileName ) . name , format , optionKey , true ) ,
91+ ) ,
92+ 'utf8' ,
93+ ) ;
94+ output . push ( {
95+ minified,
96+ code : bundles . code ,
97+ } ) ;
10598 }
10699
100+ return output ;
101+ }
102+
103+ function generate ( shouldFail , category , name , codeSplit , formats , closureFlags ) {
104+ const targetLength = longest ( formats ) ;
105+ const optionLength = longest ( Object . keys ( closureFlags ) ) ;
106+
107107 for ( const format of formats ) {
108- for ( const optionKey of Object . keys ( closureFlags ) ) {
108+ for ( const optionKey of Object . keys ( closureFlags ) ) {
109109 const method = shouldFail ? test . serial . failing : test . serial ;
110110 method (
111111 `${ name } – ${ format . padEnd ( targetLength ) } – ${ optionKey . padEnd ( optionLength ) } ` ,
112112 async t => {
113- const output = await compile ( optionKey , format ) ;
113+ const output = await compile ( category , name , codeSplit , closureFlags , optionKey , format ) ;
114114
115115 t . plan ( output . length ) ;
116116 for ( result of output ) {
117- t . is ( result . code , result . minified )
117+ t . is ( result . code , result . minified ) ;
118118 }
119119 } ,
120120 ) ;
@@ -150,4 +150,5 @@ module.exports = {
150150 ESM_OUTPUT ,
151151 generator,
152152 failureGenerator,
153- } ;
153+ compile,
154+ } ;
0 commit comments