@@ -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 ) ;
@@ -2098,5 +2107,106 @@ module.exports = {
20982107 } ) ;
20992108 } ) ;
21002109 } ) ;
2110+
2111+ if ( ! process . env . DISABLE_UNSTABLE_CHECKS ) {
2112+ describe ( 'enableIntegrityHashes() adds hashes to the entrypoints.json file' , ( ) => {
2113+ it ( 'Using default algorithm' , ( done ) => {
2114+ const config = createWebpackConfig ( 'web/build' , 'dev' ) ;
2115+ config . addEntry ( 'main' , [ './css/roboto_font.css' , './js/no_require' , 'vue' ] ) ;
2116+ config . addEntry ( 'other' , [ './css/roboto_font.css' , 'vue' ] ) ;
2117+ config . setPublicPath ( '/build' ) ;
2118+ config . configureSplitChunks ( ( splitChunks ) => {
2119+ splitChunks . chunks = 'all' ;
2120+ splitChunks . minSize = 0 ;
2121+ } ) ;
2122+ config . enableIntegrityHashes ( ) ;
2123+
2124+ testSetup . runWebpack ( config , ( ) => {
2125+ const integrityData = getIntegrityData ( config ) ;
2126+ const expectedHashes = {
2127+ '/build/runtime.js' : 'sha384-Q86c+opr0lBUPWN28BLJFqmLhho+9ZcJpXHorQvX6mYDWJ24RQcdDarXFQYN8HLc' ,
2128+ '/build/main.js' : 'sha384-ymG7OyjISWrOpH9jsGvajKMDEOP/mKJq8bHC0XdjQA6P8sg2nu+2RLQxcNNwE/3J' ,
2129+ '/build/main~other.js' : 'sha384-4g+Zv0iELStVvA4/B27g4TQHUMwZttA5TEojjUyB8Gl5p7sarU4y+VTSGMrNab8n' ,
2130+ '/build/main~other.css' : 'sha384-hfZmq9+2oI5Cst4/F4YyS2tJAAYdGz7vqSMP8cJoa8bVOr2kxNRLxSw6P8UZjwUn' ,
2131+ '/build/other.js' : 'sha384-ZU3hiTN/+Va9WVImPi+cI0/j/Q7SzAVezqL1aEXha8sVgE5HU6/0wKUxj1LEnkC9' ,
2132+
2133+ // vendors~main~other.js's hash is not tested since its
2134+ // content seems to change based on the build environment.
2135+ } ;
2136+
2137+ for ( const file in expectedHashes ) {
2138+ expect ( integrityData [ file ] ) . to . equal ( expectedHashes [ file ] ) ;
2139+ }
2140+
2141+ done ( ) ;
2142+ } ) ;
2143+ } ) ;
2144+
2145+ it ( 'Using another algorithm and a different public path' , ( done ) => {
2146+ const config = createWebpackConfig ( 'web/build' , 'dev' ) ;
2147+ config . addEntry ( 'main' , [ './css/roboto_font.css' , './js/no_require' , 'vue' ] ) ;
2148+ config . addEntry ( 'other' , [ './css/roboto_font.css' , 'vue' ] ) ;
2149+ config . setPublicPath ( 'http://localhost:8090/assets' ) ;
2150+ config . setManifestKeyPrefix ( 'assets' ) ;
2151+ config . configureSplitChunks ( ( splitChunks ) => {
2152+ splitChunks . chunks = 'all' ;
2153+ splitChunks . minSize = 0 ;
2154+ } ) ;
2155+ config . enableIntegrityHashes ( true , 'sha256' ) ;
2156+
2157+ testSetup . runWebpack ( config , ( ) => {
2158+ const integrityData = getIntegrityData ( config ) ;
2159+ const expectedHashes = {
2160+ 'http://localhost:8090/assets/runtime.js' : 'sha256-7Zze5YHq/8SPpzHbmtN7hFuexDEVMcNkYkeBJy2Uc2o=' ,
2161+ 'http://localhost:8090/assets/main.js' : 'sha256-RtW3TYA1SBHUGuBnIBBJZ7etIGyYisjargouvET4sFE=' ,
2162+ 'http://localhost:8090/assets/main~other.js' : 'sha256-q9xPQWa0UBbMPUNmhDaDuBFjV2gZU6ICiKzLN7jPccc=' ,
2163+ 'http://localhost:8090/assets/main~other.css' : 'sha256-KVo9sI0v6MnbxPg/xZMSn2XE7qIChWiDh1uED1tP5Fo=' ,
2164+ 'http://localhost:8090/assets/other.js' : 'sha256-rxT6mp9VrLO1++6G3g/VSLGisznX838ALokQhD3Jmyc=' ,
2165+
2166+ // vendors~main~other.js's hash is not tested since its
2167+ // content seems to change based on the build environment.
2168+ } ;
2169+
2170+ for ( const file in expectedHashes ) {
2171+ expect ( integrityData [ file ] ) . to . equal ( expectedHashes [ file ] ) ;
2172+ }
2173+
2174+ done ( ) ;
2175+ } ) ;
2176+ } ) ;
2177+
2178+ it ( 'Using multiple algorithms' , ( done ) => {
2179+ const config = createWebpackConfig ( 'web/build' , 'dev' ) ;
2180+ config . addEntry ( 'main' , [ './css/roboto_font.css' , './js/no_require' , 'vue' ] ) ;
2181+ config . addEntry ( 'other' , [ './css/roboto_font.css' , 'vue' ] ) ;
2182+ config . setPublicPath ( '/build' ) ;
2183+ config . configureSplitChunks ( ( splitChunks ) => {
2184+ splitChunks . chunks = 'all' ;
2185+ splitChunks . minSize = 0 ;
2186+ } ) ;
2187+ config . enableIntegrityHashes ( true , [ 'sha256' , 'sha512' ] ) ;
2188+
2189+ testSetup . runWebpack ( config , ( ) => {
2190+ const integrityData = getIntegrityData ( config ) ;
2191+ const expectedHashes = {
2192+ '/build/runtime.js' : 'sha256-H1kWMiF/ZrdlqCP49sLKyoxC/snwX7EVGJPluTM4wh8= sha512-XyYHXWTEdfInnsN/ZWV0YQ+DSO8jcczHljYQkmkTZ/xAzoEfjxiQ5NYug+V3OWbvFZ7Azwqs7FbKcz8ABE9ZAg==' ,
2193+ '/build/main.js' : 'sha256-RtW3TYA1SBHUGuBnIBBJZ7etIGyYisjargouvET4sFE= sha512-/wl1U/L6meBga5eeRTxPz5BxFiLmwL/kjy1NTcK0DNdxV3oUI/zZ9DEDU43Cl7XqGMnUH8pJhhFJR+1k9vZrYQ==' ,
2194+ '/build/main~other.js' : 'sha256-q9xPQWa0UBbMPUNmhDaDuBFjV2gZU6ICiKzLN7jPccc= sha512-1xuC/Y+goI01JUPVYBQOpPY36ttTXnZFOBsTgNPCJu53b2/ccFqzeW3abV3KG5mFzo4cfSUOS7AXjj8ajp/MjA==' ,
2195+ '/build/main~other.css' : 'sha256-6AltZJTjdVuLywCBE8qQevkscxazmWyh/19OL6cxkwY= sha512-zE1kAcqJ/jNnycEwELK7BfauEgRlK6cGrN+9urz4JI1K+s5BpglYFF9G0VOiSA7Kj3w46XX1WcjZ5w5QohBFEw==' ,
2196+ '/build/other.js' : 'sha256-rxT6mp9VrLO1++6G3g/VSLGisznX838ALokQhD3Jmyc= sha512-XZjuolIG3/QW1PwAIaPCtQZvKvkPNsAsoUjQdDqlW/uStd9lBrT3w16WrBdc3qe4X11bGkyA7IQpQwN3FGkPMA==' ,
2197+
2198+ // vendors~main~other.js's hash is not tested since its
2199+ // content seems to change based on the build environment.
2200+ } ;
2201+
2202+ for ( const file in expectedHashes ) {
2203+ expect ( integrityData [ file ] ) . to . equal ( expectedHashes [ file ] ) ;
2204+ }
2205+
2206+ done ( ) ;
2207+ } ) ;
2208+ } ) ;
2209+ } ) ;
2210+ }
21012211 } ) ;
21022212} ) ;
0 commit comments