Skip to content

Commit ed39adf

Browse files
committed
making a test more resistant to chunk id changes
1 parent 3d31646 commit ed39adf

File tree

2 files changed

+23
-13
lines changed

2 files changed

+23
-13
lines changed

test/functional.js

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2663,21 +2663,21 @@ module.exports = {
26632663

26642664
testSetup.runWebpack(config, (webpackAssert) => {
26652665
// in production, we hash the chunk names to avoid exposing any extra details
2666-
webpackAssert.assertOutputJsonFileMatches('entrypoints.json', {
2667-
entrypoints: {
2668-
main: {
2669-
js: ['/build/runtime.js', '/build/843.js', '/build/38.js', '/build/main.js'],
2670-
css: ['/build/38.css']
2671-
},
2672-
other: {
2673-
js: ['/build/runtime.js', '/build/843.js', '/build/38.js', '/build/other.js'],
2674-
css: ['/build/38.css']
2675-
}
2676-
}
2677-
});
2666+
const entrypointsData = JSON.parse(webpackAssert.readOutputFile('entrypoints.json'));
2667+
const mainJsFiles = entrypointsData.entrypoints.main.js;
2668+
expect(mainJsFiles).to.have.length(4);
2669+
expect(mainJsFiles[0]).equals('/build/runtime.js');
2670+
// keys 1 and 2 are "split files" with an integer name that sometimes changes
2671+
expect(mainJsFiles[3]).equals('/build/main.js');
2672+
2673+
expect(entrypointsData.entrypoints.main.css[0]).equals('/build/38.css');
26782674

26792675
// make split chunks are correct in manifest
2680-
webpackAssert.assertManifestKeyExists('build/843.js');
2676+
const manifestData = JSON.parse(webpackAssert.readOutputFile('manifest.json'));
2677+
mainJsFiles.forEach((file) => {
2678+
// file.substring(1) => /build/main.js -> build/main.js
2679+
expect(Object.keys(manifestData)).includes(file.substring(1));
2680+
});
26812681

26822682
done();
26832683
});

test/helpers/assert.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,16 @@ class Assert {
265265
throw new Error(`Files ${Object.keys(expectedFileStrings).join(', ')} were expected to be found in the directory but were not. Actual files: ${actualFiles.join(', ')}`);
266266
}
267267
}
268+
269+
/**
270+
* Return the contents of a built file.
271+
*
272+
* @param {string} filePath
273+
* @return {string}
274+
*/
275+
readOutputFile(filePath) {
276+
return readOutputFile(this.webpackConfig, filePath);
277+
}
268278
}
269279

270280
module.exports = function(webpackConfig) {

0 commit comments

Comments
 (0)