@@ -53,6 +53,21 @@ function testHtmlPlugin(
5353 expectWarnings
5454) {
5555 outputFile = outputFile || "index.html" ;
56+ const envSetup = ( ) => {
57+ let prevEnv = process . env . NODE_ENV ;
58+ process . env . NODE_ENV = webpackConfig . mode ;
59+ return ( ) => {
60+ process . env . NODE_ENV = prevEnv ;
61+ } ;
62+ } ;
63+
64+ let restoreEnv = envSetup ( ) ;
65+ let prevDone = done ;
66+ done = ( ...args ) => {
67+ restoreEnv ( ) ;
68+ prevDone ( ...args ) ;
69+ } ;
70+
5671 rspack ( { ...webpackConfig , builtins : { minify : false } } , ( err , stats ) => {
5772 expect ( err ) . toBeFalsy ( ) ;
5873 const statsJson = stats . toJson ( { all : true } ) ;
@@ -92,26 +107,31 @@ function testHtmlPlugin(
92107 let chunksInfo ;
93108 for ( let i = 0 ; i < expectedResults . length ; i ++ ) {
94109 const expectedResult = expectedResults [ i ] ;
95- if ( expectedResult instanceof RegExp ) {
96- expect ( htmlContent ) . toMatch ( expectedResult ) ;
97- } else if ( typeof expectedResult === "object" ) {
98- if ( expectedResult . type === "chunkhash" ) {
99- if ( ! chunksInfo ) {
100- chunksInfo = getChunksInfoFromStats ( stats ) ;
110+ try {
111+ if ( expectedResult instanceof RegExp ) {
112+ expect ( htmlContent ) . toMatch ( expectedResult ) ;
113+ } else if ( typeof expectedResult === "object" ) {
114+ if ( expectedResult . type === "chunkhash" ) {
115+ if ( ! chunksInfo ) {
116+ chunksInfo = getChunksInfoFromStats ( stats ) ;
117+ }
118+ // TODO: stats.hash
119+ // const chunkhash = chunksInfo[expectedResult.chunkName].hash;
120+ expect ( htmlContent ) . toContain (
121+ // expectedResult.containStr.replace("%chunkhash%", chunkhash)
122+ expectedResult
123+ ) ;
101124 }
102- // TODO: stats.hash
103- // const chunkhash = chunksInfo[expectedResult.chunkName].hash;
125+ } else {
104126 expect ( htmlContent ) . toContain (
105- // expectedResult.containStr.replace("%chunkhash%", chunkhash)
127+ // TODO: stats.hash
128+ // expectedResult.replace("%hash%", stats.hash)
106129 expectedResult
107130 ) ;
108131 }
109- } else {
110- expect ( htmlContent ) . toContain (
111- // TODO: stats.hash
112- // expectedResult.replace("%hash%", stats.hash)
113- expectedResult
114- ) ;
132+ } catch ( e ) {
133+ done ( e ) ;
134+ return ;
115135 }
116136 }
117137 done ( ) ;
@@ -132,7 +152,7 @@ function getChunksInfoFromStats(stats) {
132152}
133153
134154describe ( "HtmlWebpackPlugin" , ( ) => {
135- jest . setTimeout ( process . env . CI ? 120000 : 30000 ) ;
155+ jest . setTimeout ( process . env . CI ? 120000 : 10000 ) ;
136156
137157 beforeEach ( done => {
138158 rimraf ( OUTPUT_DIR , done ) ;
@@ -624,6 +644,28 @@ describe("HtmlWebpackPlugin", () => {
624644 ) ;
625645 } ) ;
626646
647+ it ( "works with process (issue#2179)" , done => {
648+ testHtmlPlugin (
649+ {
650+ mode : "development" ,
651+ devtool : "source-map" ,
652+ entry : path . join ( __dirname , "fixtures/index.js" ) ,
653+ output : {
654+ path : OUTPUT_DIR ,
655+ filename : "[name]_bundle.js"
656+ } ,
657+ plugins : [
658+ new HtmlWebpackPlugin ( {
659+ template : path . join ( __dirname , "fixtures/issue2179.html" )
660+ } )
661+ ]
662+ } ,
663+ [ "console.log(1)" ] ,
664+ null ,
665+ done
666+ ) ;
667+ } ) ;
668+
627669 it . skip ( "handles hashes in bundle filenames" , done => {
628670 testHtmlPlugin (
629671 {
0 commit comments