@@ -164,6 +164,20 @@ test('Platform path.resolve(\'file-with.ext\') aliasing', (t) => {
164
164
t . is ( resolved , path . resolve ( './test/files/folder/hipster.jsx' ) ) ;
165
165
} ) ;
166
166
167
+ const getModuleIdsFromBundle = ( bundle ) => {
168
+ if ( bundle . modules ) {
169
+ return Promise . resolve ( bundle . modules . map ( module => module . id ) ) ;
170
+ }
171
+ return bundle . generate ( { format : 'esm' } ) . then ( ( generated ) => {
172
+ if ( generated . output ) {
173
+ return generated . output . length ? generated . output : Object . keys ( generated . output )
174
+ . map ( chunkName => generated . output [ chunkName ] ) ;
175
+ }
176
+ return [ generated ] ;
177
+ } ) . then ( chunks => chunks
178
+ . reduce ( ( moduleIds , chunk ) => moduleIds . concat ( Object . keys ( chunk . modules ) ) , [ ] ) ) ;
179
+ } ;
180
+
167
181
// Tests in Rollup
168
182
test ( t => rollup ( {
169
183
input : './test/files/index.js' ,
@@ -173,12 +187,13 @@ test(t => rollup({
173
187
numberFolder : './folder' ,
174
188
'./numberFolder' : './folder' ,
175
189
} ) ] ,
176
- } ) . then ( ( stats ) => {
177
- const fileNames = stats . modules . map ( ( { id } ) => id ) . sort ( ) ;
178
- t . is ( fileNames . length , 5 ) ;
179
- t . is ( fileNames [ 0 ] . endsWith ( path . normalize ( '/files/aliasMe.js' ) ) , true ) ;
180
- t . is ( fileNames [ 1 ] . endsWith ( path . normalize ( '/files/folder/anotherNumber.js' ) ) , true ) ;
181
- t . is ( fileNames [ 2 ] . endsWith ( path . normalize ( '/files/index.js' ) ) , true ) ;
182
- t . is ( fileNames [ 3 ] . endsWith ( path . normalize ( '/files/localAliasMe.js' ) ) , true ) ;
183
- t . is ( fileNames [ 4 ] . endsWith ( path . normalize ( '/files/nonAliased.js' ) ) , true ) ;
184
- } ) ) ;
190
+ } ) . then ( getModuleIdsFromBundle )
191
+ . then ( ( moduleIds ) => {
192
+ moduleIds . sort ( ) ;
193
+ t . is ( moduleIds . length , 5 ) ;
194
+ t . is ( moduleIds [ 0 ] . endsWith ( path . normalize ( '/files/aliasMe.js' ) ) , true ) ;
195
+ t . is ( moduleIds [ 1 ] . endsWith ( path . normalize ( '/files/folder/anotherNumber.js' ) ) , true ) ;
196
+ t . is ( moduleIds [ 2 ] . endsWith ( path . normalize ( '/files/index.js' ) ) , true ) ;
197
+ t . is ( moduleIds [ 3 ] . endsWith ( path . normalize ( '/files/localAliasMe.js' ) ) , true ) ;
198
+ t . is ( moduleIds [ 4 ] . endsWith ( path . normalize ( '/files/nonAliased.js' ) ) , true ) ;
199
+ } ) ) ;
0 commit comments