From c2b6f7866e33c63288261c012b05e00aa6bacca2 Mon Sep 17 00:00:00 2001 From: Tobias Koppers Date: Fri, 29 Oct 2021 14:50:39 +0200 Subject: [PATCH] fix test cases for node 17 --- test/WasmHashes.unittest.js | 5 ++++- test/__snapshots__/StatsTestCases.basictest.js.snap | 4 ++-- test/statsCases/exclude-with-loader/webpack.config.js | 3 +++ test/statsCases/real-content-hash/test.config.js | 5 ++--- 4 files changed, 11 insertions(+), 6 deletions(-) diff --git a/test/WasmHashes.unittest.js b/test/WasmHashes.unittest.js index 21a59351ff2..c6a0886f3a0 100644 --- a/test/WasmHashes.unittest.js +++ b/test/WasmHashes.unittest.js @@ -15,7 +15,10 @@ const wasmHashes = { const createMd4Hash = require("../lib/util/hash/md4"); return { createHash: createMd4Hash, - createReferenceHash: async () => createHash("md4"), + createReferenceHash: + parseInt(process.version.slice(1), 10) < 17 + ? async () => createHash("md4") + : createMd4Hash, regExp: /^[0-9a-f]{32}$/ }; } diff --git a/test/__snapshots__/StatsTestCases.basictest.js.snap b/test/__snapshots__/StatsTestCases.basictest.js.snap index eb330bc4611..5b2de4a5af9 100644 --- a/test/__snapshots__/StatsTestCases.basictest.js.snap +++ b/test/__snapshots__/StatsTestCases.basictest.js.snap @@ -952,9 +952,9 @@ webpack x.x.x compiled successfully in X ms" exports[`StatsTestCases should print correct stats for exclude-with-loader 1`] = ` "hidden assets 34 bytes 1 asset -asset bundle.js 5.28 KiB [emitted] (name: main) +asset bundle.js 5.25 KiB [emitted] (name: main) runtime modules 1.72 KiB 5 modules -hidden modules 123 bytes 2 modules +hidden modules 99 bytes 2 modules cacheable modules 119 bytes ./index.js 77 bytes [built] [code generated] ./a.txt 42 bytes [built] [code generated] diff --git a/test/statsCases/exclude-with-loader/webpack.config.js b/test/statsCases/exclude-with-loader/webpack.config.js index 973691d20bd..725e0252c5c 100644 --- a/test/statsCases/exclude-with-loader/webpack.config.js +++ b/test/statsCases/exclude-with-loader/webpack.config.js @@ -18,6 +18,9 @@ module.exports = { { test: /\.json/, loader: "file-loader", + options: { + name: "[sha256:hash:8].[ext]" + }, type: "javascript/auto" } ] diff --git a/test/statsCases/real-content-hash/test.config.js b/test/statsCases/real-content-hash/test.config.js index fcf63d858af..a0a96aea222 100644 --- a/test/statsCases/real-content-hash/test.config.js +++ b/test/statsCases/real-content-hash/test.config.js @@ -1,6 +1,6 @@ const fs = require("fs"); const path = require("path"); -const crypto = require("crypto"); +const createHash = require("../../../lib/util/createHash"); const hashedFiles = { "file.jpg": a => a.name.endsWith(".jpg"), @@ -31,8 +31,7 @@ module.exports = { const asset = statsData.assets.find(hashedFiles[name]); expect(asset).not.toBe(undefined); const content = fs.readFileSync(path.resolve(__dirname, "a", name)); - const hash = crypto - .createHash("md4") + const hash = createHash("md4") .update(content) .digest("hex") .slice(0, 20);