11check = require ( '../check.js' ) ;
22const fs = require ( 'fs' ) ;
3- const expected = 'lib1 fn,dep3 fn,lib2 fn,dep2 fn' ;
4- const path = __dirname ;
3+ const expected = 'dep4 fn' ;
4+ const path = require ( 'path' ) ;
5+
6+ describe ( 'bundling chunks' , ( ) => {
7+ function findChunk ( ) {
8+ let chunks = fs . readdirSync ( path . join ( __dirname , 'bundle_chunks' ) )
9+ . filter ( name => name . startsWith ( 'chunk-' ) && name . endsWith ( '.js' ) ) ;
10+ if ( chunks . length != 1 ) {
11+ fail ( 'Not 1 chunk ' + chunks ) ;
12+ }
13+ return chunks [ 0 ] ;
14+ }
515
6- describe ( 'bundling additional entry point' , ( ) => {
716 it ( 'should work' , ( ) => {
8- check ( path , 'bundle.min.js' , 'goldens/bundle.min.js_' ) ;
9- check ( path , 'bundle.min.es2015.js' , 'goldens/bundle.min.es2015.js_' ) ;
17+ check ( __dirname , 'bundle.min.js' , 'goldens/bundle.min.js_' ) ;
18+ check ( __dirname , 'bundle.min.es2015.js' , 'goldens/bundle.min.es2015.js_' ) ;
1019 } ) ;
1120
1221 // Disabled because native ESModules can't be loaded in current nodejs
1322 // see https://github.com/bazelbuild/rules_nodejs/issues/593
1423 xit ( 'bundle_chunks_es6 should work' , ( ) => {
1524 const additional_entry = require (
16- 'build_bazel_rules_nodejs/internal/e2e/rollup_code_splitting/bundle_chunks_es6/additional_entry.js' ) ;
17- const actual = ( new additional_entry ( ) ) . test ( ) ;
25+ 'build_bazel_rules_nodejs/internal/e2e/rollup_code_splitting/bundle_chunks_es6/' +
26+ findChunk ( ) ) ;
27+ const actual = additional_entry . fn ( ) ;
1828 expect ( actual ) . toEqual ( expected ) ;
1929 } ) ;
2030
2131 it ( 'bundle_chunks should work' , ( ) => {
22- const additional_entry =
23- require (
24- 'build_bazel_rules_nodejs/internal/e2e/rollup_code_splitting/bundle_chunks/additional_entry.js' )
25- . default ;
26- const actual = ( new additional_entry ( ) ) . test ( ) ;
32+ const additional_entry = require (
33+ 'build_bazel_rules_nodejs/internal/e2e/rollup_code_splitting/bundle_chunks/' + findChunk ( ) ) ;
34+ const actual = additional_entry . fn ( ) ;
2735 expect ( actual ) . toEqual ( expected ) ;
2836 } ) ;
2937
3038 it ( 'bundle_chunks_min should work' , ( ) => {
31- const additional_entry =
32- require (
33- 'build_bazel_rules_nodejs/internal/e2e/rollup_code_splitting/bundle_chunks_min/additional_entry.js' )
34- . default ;
35- const actual = ( new additional_entry ( ) ) . test ( ) ;
39+ const additional_entry = require (
40+ 'build_bazel_rules_nodejs/internal/e2e/rollup_code_splitting/bundle_chunks_min/' +
41+ findChunk ( ) ) ;
42+ const actual = additional_entry . fn ( ) ;
3643 expect ( actual ) . toEqual ( expected ) ;
3744 } ) ;
3845
3946 it ( 'bundle_chunks_min_debug should work' , ( ) => {
40- const additional_entry =
41- require (
42- 'build_bazel_rules_nodejs/internal/e2e/rollup_code_splitting/bundle_chunks_min_debug/additional_entry.js' )
43- . default ;
44- const actual = ( new additional_entry ( ) ) . test ( ) ;
47+ const additional_entry = require (
48+ 'build_bazel_rules_nodejs/internal/e2e/rollup_code_splitting/bundle_chunks_min_debug/' +
49+ findChunk ( ) ) ;
50+ const actual = additional_entry . fn ( ) ;
4551 expect ( actual ) . toEqual ( expected ) ;
4652 } ) ;
4753
4854 it ( 'should have a license header' , ( ) => {
4955 const content = fs . readFileSync (
5056 require . resolve (
51- 'build_bazel_rules_nodejs/internal/e2e/rollup_code_splitting/bundle_chunks_min_debug/additional_entry.js' ) ,
57+ 'build_bazel_rules_nodejs/internal/e2e/rollup_code_splitting/bundle_chunks_min_debug/' +
58+ findChunk ( ) ) ,
5259 { encoding : 'utf-8' } ) ;
5360 expect ( content ) . toContain ( 'dummy license banner' ) ;
5461 } ) ;
55- } ) ;
62+ } ) ;
0 commit comments