From 923ac94f828248097555688378263a653255bd69 Mon Sep 17 00:00:00 2001 From: Tobias Koppers Date: Mon, 1 Mar 2021 10:15:06 +0100 Subject: [PATCH] add test case for assets that become identical after optimization --- .../__snapshots__/StatsTestCases.test.js.snap | 102 +++++++++++------- test/statsCases/real-content-hash/a/a.js | 1 + test/statsCases/real-content-hash/a/b.js | 4 + test/statsCases/real-content-hash/b/a.js | 1 + test/statsCases/real-content-hash/b/b.js | 4 + .../real-content-hash/test.config.js | 5 +- .../real-content-hash/webpack.config.js | 10 +- 7 files changed, 84 insertions(+), 43 deletions(-) create mode 100644 test/statsCases/real-content-hash/a/a.js create mode 100644 test/statsCases/real-content-hash/a/b.js create mode 100644 test/statsCases/real-content-hash/b/a.js create mode 100644 test/statsCases/real-content-hash/b/b.js diff --git a/test/__snapshots__/StatsTestCases.test.js.snap b/test/__snapshots__/StatsTestCases.test.js.snap index 564aa2c01..49413d55e 100644 --- a/test/__snapshots__/StatsTestCases.test.js.snap +++ b/test/__snapshots__/StatsTestCases.test.js.snap @@ -2440,97 +2440,119 @@ LOG from webpack.FileSystemInfo exports[`StatsTestCases should print correct stats for real-content-hash 1`] = ` "a-normal: - assets by path *.js 3.14 KiB - asset 28d919d2ba0afe316d4d-28d919.js 2.65 KiB [emitted] [immutable] [minimized] (name: runtime~main) + assets by path *.js 3.16 KiB + asset 1a429866b1a4b47a3ece-1a4298.js 2.65 KiB [emitted] [immutable] [minimized] (name: runtime) asset a639a9edc4557744bf94-a639a9.js 288 bytes [emitted] [immutable] [minimized] (name: lazy) - asset 3cc8faad16137711c07e-3cc8fa.js 210 bytes [emitted] [immutable] [minimized] (name: main) + asset b32c1c3b5e5cb3818671-b32c1c.js 210 bytes [emitted] [immutable] [minimized] (name: index) + asset 666f2b8847021ccc7608-666f2b.js 21 bytes [emitted] [immutable] [minimized] (name: a, b) assets by chunk 20.4 KiB (auxiliary name: lazy) asset 89a353e9c515885abd8e.png 14.6 KiB [emitted] [immutable] [from: file.png] (auxiliary name: lazy) asset 7382fad5b015914e0811.jpg?query 5.89 KiB [cached] [immutable] [from: file.jpg?query] (auxiliary name: lazy) - asset 7382fad5b015914e0811.jpg 5.89 KiB [emitted] [immutable] [from: file.jpg] (auxiliary name: main) - Entrypoint main 2.85 KiB (5.89 KiB) = 28d919d2ba0afe316d4d-28d919.js 2.65 KiB 3cc8faad16137711c07e-3cc8fa.js 210 bytes 1 auxiliary asset + asset 7382fad5b015914e0811.jpg 5.89 KiB [emitted] [immutable] [from: file.jpg] (auxiliary name: index) + Entrypoint index 2.85 KiB (5.89 KiB) = 1a429866b1a4b47a3ece-1a4298.js 2.65 KiB b32c1c3b5e5cb3818671-b32c1c.js 210 bytes 1 auxiliary asset + Entrypoint a 21 bytes = 666f2b8847021ccc7608-666f2b.js + Entrypoint b 21 bytes = 666f2b8847021ccc7608-666f2b.js runtime modules 7.42 KiB 8 modules orphan modules 23 bytes [orphan] 1 module - cacheable modules 426 bytes (javascript) 26.3 KiB (asset) + cacheable modules 514 bytes (javascript) 26.3 KiB (asset) + javascript modules 388 bytes + ./a/index.js 150 bytes [built] [code generated] + ./a/a.js 22 bytes [built] [code generated] + ./a/b.js 66 bytes [built] [code generated] + ./a/lazy.js + 1 modules 150 bytes [built] [code generated] asset modules 126 bytes (javascript) 26.3 KiB (asset) ./a/file.jpg 42 bytes (javascript) 5.89 KiB (asset) [built] [code generated] ./a/file.png 42 bytes (javascript) 14.6 KiB (asset) [built] [code generated] ./a/file.jpg?query 42 bytes (javascript) 5.89 KiB (asset) [built] [code generated] - javascript modules 300 bytes - ./a/index.js 150 bytes [built] [code generated] - ./a/lazy.js + 1 modules 150 bytes [built] [code generated] a-normal (webpack x.x.x) compiled successfully in X ms b-normal: - assets by path *.js 3.14 KiB - asset 78946a272f83db936232-78946a.js 2.65 KiB [emitted] [immutable] [minimized] (name: runtime~main) + assets by path *.js 3.16 KiB + asset a608d8c4ea5e597b8ec0-a608d8.js 2.65 KiB [emitted] [immutable] [minimized] (name: runtime) asset a639a9edc4557744bf94-a639a9.js 288 bytes [emitted] [immutable] [minimized] (name: lazy) - asset 3cc8faad16137711c07e-3cc8fa.js 210 bytes [emitted] [immutable] [minimized] (name: main) + asset b32c1c3b5e5cb3818671-b32c1c.js 210 bytes [emitted] [immutable] [minimized] (name: index) + asset 666f2b8847021ccc7608-666f2b.js 21 bytes [emitted] [immutable] [minimized] (name: a, b) assets by chunk 20.4 KiB (auxiliary name: lazy) asset 89a353e9c515885abd8e.png 14.6 KiB [emitted] [immutable] [from: file.png] (auxiliary name: lazy) asset 7382fad5b015914e0811.jpg?query 5.89 KiB [cached] [immutable] [from: file.jpg?query] (auxiliary name: lazy) - asset 7382fad5b015914e0811.jpg 5.89 KiB [emitted] [immutable] [from: file.jpg] (auxiliary name: main) - Entrypoint main 2.85 KiB (5.89 KiB) = 78946a272f83db936232-78946a.js 2.65 KiB 3cc8faad16137711c07e-3cc8fa.js 210 bytes 1 auxiliary asset + asset 7382fad5b015914e0811.jpg 5.89 KiB [emitted] [immutable] [from: file.jpg] (auxiliary name: index) + Entrypoint index 2.85 KiB (5.89 KiB) = a608d8c4ea5e597b8ec0-a608d8.js 2.65 KiB b32c1c3b5e5cb3818671-b32c1c.js 210 bytes 1 auxiliary asset + Entrypoint a 21 bytes = 666f2b8847021ccc7608-666f2b.js + Entrypoint b 21 bytes = 666f2b8847021ccc7608-666f2b.js runtime modules 7.42 KiB 8 modules orphan modules 19 bytes [orphan] 1 module - cacheable modules 381 bytes (javascript) 26.3 KiB (asset) + cacheable modules 469 bytes (javascript) 26.3 KiB (asset) + javascript modules 343 bytes + ./b/index.js 109 bytes [built] [code generated] + ./b/a.js 22 bytes [built] [code generated] + ./b/b.js 66 bytes [built] [code generated] + ./b/lazy.js + 1 modules 146 bytes [built] [code generated] asset modules 126 bytes (javascript) 26.3 KiB (asset) ./b/file.jpg 42 bytes (javascript) 5.89 KiB (asset) [built] [code generated] ./b/file.png 42 bytes (javascript) 14.6 KiB (asset) [built] [code generated] ./b/file.jpg?query 42 bytes (javascript) 5.89 KiB (asset) [built] [code generated] - javascript modules 255 bytes - ./b/index.js 109 bytes [built] [code generated] - ./b/lazy.js + 1 modules 146 bytes [built] [code generated] b-normal (webpack x.x.x) compiled successfully in X ms a-source-map: - assets by path *.js 3.3 KiB - asset 6ab6298c9ee98458fcc2-6ab629.js 2.7 KiB [emitted] [immutable] [minimized] (name: runtime~main) - sourceMap 6ab6298c9ee98458fcc2-6ab629.js.map 14.6 KiB [emitted] [dev] (auxiliary name: runtime~main) + assets by path *.js 3.38 KiB + asset 2064caf3f763dcbec7da-2064ca.js 2.7 KiB [emitted] [immutable] [minimized] (name: runtime) + sourceMap 2064caf3f763dcbec7da-2064ca.js.map 14.6 KiB [emitted] [dev] (auxiliary name: runtime) asset 05c637d15dff2d0dc5fd-05c637.js 344 bytes [emitted] [immutable] [minimized] (name: lazy) sourceMap 05c637d15dff2d0dc5fd-05c637.js.map 399 bytes [emitted] [dev] (auxiliary name: lazy) - asset b8bfcec62cdd15c9a840-b8bfce.js 266 bytes [emitted] [immutable] [minimized] (name: main) - sourceMap b8bfcec62cdd15c9a840-b8bfce.js.map 366 bytes [emitted] [dev] (auxiliary name: main) + asset 793a9ff3858dbc0b791d-793a9f.js 266 bytes [emitted] [immutable] [minimized] (name: index) + sourceMap 793a9ff3858dbc0b791d-793a9f.js.map 366 bytes [emitted] [dev] (auxiliary name: index) + asset 222c2acc68675174e6b2-222c2a.js 77 bytes [emitted] [immutable] [minimized] (name: a, b) + sourceMap 222c2acc68675174e6b2-222c2a.js.map 254 bytes [emitted] [dev] (auxiliary name: a, b) assets by chunk 20.4 KiB (auxiliary name: lazy) asset 89a353e9c515885abd8e.png 14.6 KiB [emitted] [immutable] [from: file.png] (auxiliary name: lazy) asset 7382fad5b015914e0811.jpg?query 5.89 KiB [cached] [immutable] [from: file.jpg?query] (auxiliary name: lazy) - asset 7382fad5b015914e0811.jpg 5.89 KiB [emitted] [immutable] [from: file.jpg] (auxiliary name: main) - Entrypoint main 2.96 KiB (20.8 KiB) = 6ab6298c9ee98458fcc2-6ab629.js 2.7 KiB b8bfcec62cdd15c9a840-b8bfce.js 266 bytes 3 auxiliary assets + asset 7382fad5b015914e0811.jpg 5.89 KiB [emitted] [immutable] [from: file.jpg] (auxiliary name: index) + Entrypoint index 2.96 KiB (20.8 KiB) = 2064caf3f763dcbec7da-2064ca.js 2.7 KiB 793a9ff3858dbc0b791d-793a9f.js 266 bytes 3 auxiliary assets + Entrypoint a 77 bytes (254 bytes) = 222c2acc68675174e6b2-222c2a.js 1 auxiliary asset + Entrypoint b 77 bytes (254 bytes) = 222c2acc68675174e6b2-222c2a.js 1 auxiliary asset runtime modules 7.42 KiB 8 modules orphan modules 23 bytes [orphan] 1 module - cacheable modules 426 bytes (javascript) 26.3 KiB (asset) + cacheable modules 514 bytes (javascript) 26.3 KiB (asset) + javascript modules 388 bytes + ./a/index.js 150 bytes [built] [code generated] + ./a/a.js 22 bytes [built] [code generated] + ./a/b.js 66 bytes [built] [code generated] + ./a/lazy.js + 1 modules 150 bytes [built] [code generated] asset modules 126 bytes (javascript) 26.3 KiB (asset) ./a/file.jpg 42 bytes (javascript) 5.89 KiB (asset) [built] [code generated] ./a/file.png 42 bytes (javascript) 14.6 KiB (asset) [built] [code generated] ./a/file.jpg?query 42 bytes (javascript) 5.89 KiB (asset) [built] [code generated] - javascript modules 300 bytes - ./a/index.js 150 bytes [built] [code generated] - ./a/lazy.js + 1 modules 150 bytes [built] [code generated] a-source-map (webpack x.x.x) compiled successfully in X ms b-source-map: - assets by path *.js 3.3 KiB - asset a16ab0460019d5b48418-a16ab0.js 2.7 KiB [emitted] [immutable] [minimized] (name: runtime~main) - sourceMap a16ab0460019d5b48418-a16ab0.js.map 14.6 KiB [emitted] [dev] (auxiliary name: runtime~main) + assets by path *.js 3.38 KiB + asset 5a04964d0347bb4c6f39-5a0496.js 2.7 KiB [emitted] [immutable] [minimized] (name: runtime) + sourceMap 5a04964d0347bb4c6f39-5a0496.js.map 14.6 KiB [emitted] [dev] (auxiliary name: runtime) asset 05c637d15dff2d0dc5fd-05c637.js 344 bytes [emitted] [immutable] [minimized] (name: lazy) sourceMap 05c637d15dff2d0dc5fd-05c637.js.map 395 bytes [emitted] [dev] (auxiliary name: lazy) - asset b8bfcec62cdd15c9a840-b8bfce.js 266 bytes [emitted] [immutable] [minimized] (name: main) - sourceMap b8bfcec62cdd15c9a840-b8bfce.js.map 323 bytes [emitted] [dev] (auxiliary name: main) + asset 793a9ff3858dbc0b791d-793a9f.js 266 bytes [emitted] [immutable] [minimized] (name: index) + sourceMap 793a9ff3858dbc0b791d-793a9f.js.map 323 bytes [emitted] [dev] (auxiliary name: index) + asset 222c2acc68675174e6b2-222c2a.js 77 bytes [emitted] [immutable] [minimized] (name: a, b) + sourceMap 222c2acc68675174e6b2-222c2a.js.map 254 bytes [emitted] [dev] (auxiliary name: a, b) assets by chunk 20.4 KiB (auxiliary name: lazy) asset 89a353e9c515885abd8e.png 14.6 KiB [emitted] [immutable] [from: file.png] (auxiliary name: lazy) asset 7382fad5b015914e0811.jpg?query 5.89 KiB [cached] [immutable] [from: file.jpg?query] (auxiliary name: lazy) - asset 7382fad5b015914e0811.jpg 5.89 KiB [emitted] [immutable] [from: file.jpg] (auxiliary name: main) - Entrypoint main 2.96 KiB (20.8 KiB) = a16ab0460019d5b48418-a16ab0.js 2.7 KiB b8bfcec62cdd15c9a840-b8bfce.js 266 bytes 3 auxiliary assets + asset 7382fad5b015914e0811.jpg 5.89 KiB [emitted] [immutable] [from: file.jpg] (auxiliary name: index) + Entrypoint index 2.96 KiB (20.8 KiB) = 5a04964d0347bb4c6f39-5a0496.js 2.7 KiB 793a9ff3858dbc0b791d-793a9f.js 266 bytes 3 auxiliary assets + Entrypoint a 77 bytes (254 bytes) = 222c2acc68675174e6b2-222c2a.js 1 auxiliary asset + Entrypoint b 77 bytes (254 bytes) = 222c2acc68675174e6b2-222c2a.js 1 auxiliary asset runtime modules 7.42 KiB 8 modules orphan modules 19 bytes [orphan] 1 module - cacheable modules 381 bytes (javascript) 26.3 KiB (asset) + cacheable modules 469 bytes (javascript) 26.3 KiB (asset) + javascript modules 343 bytes + ./b/index.js 109 bytes [built] [code generated] + ./b/a.js 22 bytes [built] [code generated] + ./b/b.js 66 bytes [built] [code generated] + ./b/lazy.js + 1 modules 146 bytes [built] [code generated] asset modules 126 bytes (javascript) 26.3 KiB (asset) ./b/file.jpg 42 bytes (javascript) 5.89 KiB (asset) [built] [code generated] ./b/file.png 42 bytes (javascript) 14.6 KiB (asset) [built] [code generated] ./b/file.jpg?query 42 bytes (javascript) 5.89 KiB (asset) [built] [code generated] - javascript modules 255 bytes - ./b/index.js 109 bytes [built] [code generated] - ./b/lazy.js + 1 modules 146 bytes [built] [code generated] b-source-map (webpack x.x.x) compiled successfully in X ms" `; diff --git a/test/statsCases/real-content-hash/a/a.js b/test/statsCases/real-content-hash/a/a.js new file mode 100644 index 000000000..702f4280c --- /dev/null +++ b/test/statsCases/real-content-hash/a/a.js @@ -0,0 +1 @@ +console.log("hello"); diff --git a/test/statsCases/real-content-hash/a/b.js b/test/statsCases/real-content-hash/a/b.js new file mode 100644 index 000000000..96825f2fb --- /dev/null +++ b/test/statsCases/real-content-hash/a/b.js @@ -0,0 +1,4 @@ +// yes that's important +if (true) { + console.log("hel" + "lo"); +} diff --git a/test/statsCases/real-content-hash/b/a.js b/test/statsCases/real-content-hash/b/a.js new file mode 100644 index 000000000..702f4280c --- /dev/null +++ b/test/statsCases/real-content-hash/b/a.js @@ -0,0 +1 @@ +console.log("hello"); diff --git a/test/statsCases/real-content-hash/b/b.js b/test/statsCases/real-content-hash/b/b.js new file mode 100644 index 000000000..96825f2fb --- /dev/null +++ b/test/statsCases/real-content-hash/b/b.js @@ -0,0 +1,4 @@ +// yes that's important +if (true) { + console.log("hel" + "lo"); +} diff --git a/test/statsCases/real-content-hash/test.config.js b/test/statsCases/real-content-hash/test.config.js index 916d11d19..fcf63d858 100644 --- a/test/statsCases/real-content-hash/test.config.js +++ b/test/statsCases/real-content-hash/test.config.js @@ -16,9 +16,12 @@ module.exports = { const b = stats.stats[i + 1].toJson({ assets: true }); - expect(Object.keys(a.assetsByChunkName).length).toBe(3); + expect(Object.keys(a.assetsByChunkName).length).toBe(5); expect(a.assetsByChunkName.main).toEqual(b.assetsByChunkName.main); expect(a.assetsByChunkName.lazy).toEqual(b.assetsByChunkName.lazy); + expect(a.assetsByChunkName.a).toEqual(b.assetsByChunkName.a); + expect(a.assetsByChunkName.b).toEqual(b.assetsByChunkName.b); + expect(a.assetsByChunkName.a).toEqual(a.assetsByChunkName.b); } for (let i = 0; i < 4; i++) { const statsData = stats.stats[i].toJson({ diff --git a/test/statsCases/real-content-hash/webpack.config.js b/test/statsCases/real-content-hash/webpack.config.js index c7782aed2..ff7970c9a 100644 --- a/test/statsCases/real-content-hash/webpack.config.js +++ b/test/statsCases/real-content-hash/webpack.config.js @@ -3,7 +3,14 @@ const path = require("path"); /** @type {import("../../../").Configuration} */ const base = { mode: "production", - entry: "./index", + entry: { + index: { + import: "./index", + runtime: "runtime" + }, + a: "./a", + b: "./b" + }, module: { generator: { asset: { @@ -18,7 +25,6 @@ const base = { ] }, optimization: { - runtimeChunk: true, minimize: true }, stats: {