@@ -60,6 +60,15 @@ function getEntrypointData(config, entryName) {
6060 return entrypointsData . entrypoints [ entryName ] ;
6161}
6262
63+ function getIntegrityData ( config ) {
64+ const entrypointsData = JSON . parse ( readOutputFileContents ( 'entrypoints.json' , config ) ) ;
65+ if ( typeof entrypointsData . integrity === 'undefined' ) {
66+ throw new Error ( 'The entrypoints.json file does not contain an integrity object!' ) ;
67+ }
68+
69+ return entrypointsData . integrity ;
70+ }
71+
6372describe ( 'Functional tests using webpack' , function ( ) {
6473 // being functional tests, these can take quite long
6574 this . timeout ( 10000 ) ;
@@ -132,7 +141,8 @@ describe('Functional tests using webpack', function() {
132141 js : [ '/build/runtime.js' ] ,
133142 css : [ '/build/bg.css' ]
134143 }
135- }
144+ } ,
145+ integrity : { }
136146 } ) ;
137147
138148 done ( ) ;
@@ -160,7 +170,8 @@ describe('Functional tests using webpack', function() {
160170 js : [ '/build/runtime.js' , '/build/vendors~main~other.js' , '/build/main~other.js' , '/build/other.js' ] ,
161171 css : [ '/build/main~other.css' ]
162172 }
163- }
173+ } ,
174+ integrity : { }
164175 } ) ;
165176
166177 done ( ) ;
@@ -763,7 +774,8 @@ describe('Functional tests using webpack', function() {
763774 js : [ '/build/runtime.js' , '/build/shared.js' , '/build/other.js' ] ,
764775 css : [ '/build/shared.css' ]
765776 }
766- }
777+ } ,
778+ integrity : { }
767779 } ) ;
768780
769781 testSetup . requestTestPage (
@@ -1848,7 +1860,8 @@ module.exports = {
18481860 js : [ '/build/runtime.js' , '/build/vendors~main~other.js' , '/build/main~other.js' , '/build/other.js' ] ,
18491861 css : [ '/build/main~other.css' ]
18501862 }
1851- }
1863+ } ,
1864+ integrity : { }
18521865 } ) ;
18531866
18541867 // make split chunks are correct in manifest
@@ -1890,7 +1903,8 @@ module.exports = {
18901903 ] ,
18911904 css : [ 'http://localhost:8080/build/main~other.css' ]
18921905 }
1893- }
1906+ } ,
1907+ integrity : { }
18941908 } ) ;
18951909
18961910 // make split chunks are correct in manifest
@@ -1932,7 +1946,8 @@ module.exports = {
19321946 ] ,
19331947 css : [ '/subdirectory/build/main~other.css' ]
19341948 }
1935- }
1949+ } ,
1950+ integrity : { }
19361951 } ) ;
19371952
19381953 // make split chunks are correct in manifest
@@ -1964,7 +1979,8 @@ module.exports = {
19641979 js : [ '/build/runtime.js' , '/build/0.js' , '/build/1.js' , '/build/other.js' ] ,
19651980 css : [ '/build/1.css' ]
19661981 }
1967- }
1982+ } ,
1983+ integrity : { }
19681984 } ) ;
19691985
19701986 // make split chunks are correct in manifest
@@ -1995,7 +2011,8 @@ module.exports = {
19952011 // so, it has that filename, instead of following the normal pattern
19962012 js : [ '/build/runtime.js' , '/build/vendors~main~other.js' , '/build/0.js' , '/build/other.js' ]
19972013 }
1998- }
2014+ } ,
2015+ integrity : { }
19992016 } ) ;
20002017
20012018 // make split chunks are correct in manifest
@@ -2098,5 +2115,78 @@ module.exports = {
20982115 } ) ;
20992116 } ) ;
21002117 } ) ;
2118+
2119+ if ( ! process . env . DISABLE_UNSTABLE_CHECKS ) {
2120+ describe ( 'enableIntegrityHashes() adds hashes to the entrypoints.json file' , ( ) => {
2121+ it ( 'Using default algorithm' , ( done ) => {
2122+ const config = createWebpackConfig ( 'web/build' , 'dev' ) ;
2123+ config . addEntry ( 'main' , [ './css/roboto_font.css' , './js/no_require' , 'vue' ] ) ;
2124+ config . addEntry ( 'other' , [ './css/roboto_font.css' , 'vue' ] ) ;
2125+ config . setPublicPath ( '/build' ) ;
2126+ config . configureSplitChunks ( ( splitChunks ) => {
2127+ splitChunks . chunks = 'all' ;
2128+ splitChunks . minSize = 0 ;
2129+ } ) ;
2130+ config . enableIntegrityHashes ( ) ;
2131+
2132+ testSetup . runWebpack ( config , ( ) => {
2133+ const integrityData = getIntegrityData ( config ) ;
2134+ const expectedHashes = {
2135+ '/build/runtime.js' : 'Q86c+opr0lBUPWN28BLJFqmLhho+9ZcJpXHorQvX6mYDWJ24RQcdDarXFQYN8HLc' ,
2136+ '/build/main.js' : 'ymG7OyjISWrOpH9jsGvajKMDEOP/mKJq8bHC0XdjQA6P8sg2nu+2RLQxcNNwE/3J' ,
2137+ '/build/main~other.js' : '4g+Zv0iELStVvA4/B27g4TQHUMwZttA5TEojjUyB8Gl5p7sarU4y+VTSGMrNab8n' ,
2138+ '/build/main~other.css' : 'hfZmq9+2oI5Cst4/F4YyS2tJAAYdGz7vqSMP8cJoa8bVOr2kxNRLxSw6P8UZjwUn' ,
2139+ '/build/other.js' : 'ZU3hiTN/+Va9WVImPi+cI0/j/Q7SzAVezqL1aEXha8sVgE5HU6/0wKUxj1LEnkC9' ,
2140+
2141+ // vendors~main~other.js's hash is not tested since its
2142+ // content seems to change based on the build environment.
2143+ } ;
2144+
2145+ expect ( integrityData . algorithm ) . to . equal ( 'sha384' ) ;
2146+
2147+ for ( const file in expectedHashes ) {
2148+ expect ( integrityData . hashes [ file ] ) . to . deep . equal ( expectedHashes [ file ] ) ;
2149+ }
2150+
2151+ done ( ) ;
2152+ } ) ;
2153+ } ) ;
2154+
2155+ it ( 'Using another algorithm and a different public path' , ( done ) => {
2156+ const config = createWebpackConfig ( 'web/build' , 'dev' ) ;
2157+ config . addEntry ( 'main' , [ './css/roboto_font.css' , './js/no_require' , 'vue' ] ) ;
2158+ config . addEntry ( 'other' , [ './css/roboto_font.css' , 'vue' ] ) ;
2159+ config . setPublicPath ( 'http://localhost:8090/assets' ) ;
2160+ config . setManifestKeyPrefix ( 'assets' ) ;
2161+ config . configureSplitChunks ( ( splitChunks ) => {
2162+ splitChunks . chunks = 'all' ;
2163+ splitChunks . minSize = 0 ;
2164+ } ) ;
2165+ config . enableIntegrityHashes ( true , 'md5' ) ;
2166+
2167+ testSetup . runWebpack ( config , ( ) => {
2168+ const integrityData = getIntegrityData ( config ) ;
2169+ const expectedHashes = {
2170+ 'http://localhost:8090/assets/runtime.js' : 'mg7CHb72gsDGpEFL9KCo7g==' ,
2171+ 'http://localhost:8090/assets/main.js' : 'lv1wLOA041Myhs9zSGGPwA==' ,
2172+ 'http://localhost:8090/assets/main~other.js' : 'DejRltgCse+f7tQHIZ3AEA==' ,
2173+ 'http://localhost:8090/assets/main~other.css' : 'foQmt62xKImGVEn/9fou8Q==' ,
2174+ 'http://localhost:8090/assets/other.js' : '1CtbEVw6vOl+/SUVHyKBbA==' ,
2175+
2176+ // vendors~main~other.js's hash is not tested since its
2177+ // content seems to change based on the build environment.
2178+ } ;
2179+
2180+ expect ( integrityData . algorithm ) . to . equal ( 'md5' ) ;
2181+
2182+ for ( const file in expectedHashes ) {
2183+ expect ( integrityData . hashes [ file ] ) . to . deep . equal ( expectedHashes [ file ] ) ;
2184+ }
2185+
2186+ done ( ) ;
2187+ } ) ;
2188+ } ) ;
2189+ } ) ;
2190+ }
21012191 } ) ;
21022192} ) ;
0 commit comments