From 722e60e4b11902321ec6f14c61d38aef97a7ecb4 Mon Sep 17 00:00:00 2001 From: alexander-akait Date: Wed, 21 Jan 2026 18:29:28 +0300 Subject: [PATCH 1/8] refactor: migrate to jest assertion --- package.json | 3 --- 1 file changed, 3 deletions(-) diff --git a/package.json b/package.json index 3f8d1b57..b213c922 100644 --- a/package.json +++ b/package.json @@ -70,8 +70,6 @@ "babel-eslint": "10.1.0", "babel-loader": "9.2.1", "babel-plugin-lodash": "3.3.4", - "chai": "4.3.4", - "chai-subset": "1.6.0", "classnames": "2.3.1", "core-js": "3.12.1", "css-loader": "5.2.5", @@ -96,7 +94,6 @@ "preact": "10.5.13", "prettier": "^3.8.0", "puppeteer": "^24.30.0", - "stream-combiner2": "1.1.1", "style-loader": "2.0.0", "terser-webpack-plugin": "5.1.2", "webpack": "5.98.0", From cc15a42eebca9266de6b3c944794c100d30a52f1 Mon Sep 17 00:00:00 2001 From: alexander-akait Date: Fri, 23 Jan 2026 16:04:41 +0300 Subject: [PATCH 2/8] chore: rebase --- package-lock.json | 96 ---------------------------------------------- test/Logger.js | 3 -- test/analyzer.js | 3 -- test/parseUtils.js | 3 -- test/plugin.js | 3 -- test/statsUtils.js | 3 -- test/utils.js | 3 -- test/viewer.js | 3 -- 8 files changed, 117 deletions(-) diff --git a/package-lock.json b/package-lock.json index b0fe6bc1..414098ff 100644 --- a/package-lock.json +++ b/package-lock.json @@ -38,8 +38,6 @@ "babel-eslint": "10.1.0", "babel-loader": "9.2.1", "babel-plugin-lodash": "3.3.4", - "chai": "4.3.4", - "chai-subset": "1.6.0", "classnames": "2.3.1", "core-js": "3.12.1", "css-loader": "5.2.5", @@ -64,7 +62,6 @@ "preact": "10.5.13", "prettier": "^3.8.0", "puppeteer": "^24.30.0", - "stream-combiner2": "1.1.1", "style-loader": "2.0.0", "terser-webpack-plugin": "5.1.2", "webpack": "5.98.0", @@ -4362,15 +4359,6 @@ "url": "https://github.com/sponsors/ljharb" } }, - "node_modules/assertion-error": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/assertion-error/-/assertion-error-1.1.0.tgz", - "integrity": "sha512-jgsaNduz+ndvGyFt3uSuWqvy4lCnIJiovtouQN5JZHOKCS2QuhEdbcQHFhVksz2N2U9hXJo8odG7ETyWlEeuDw==", - "dev": true, - "engines": { - "node": "*" - } - }, "node_modules/ast-types": { "version": "0.13.4", "resolved": "https://registry.npmjs.org/ast-types/-/ast-types-0.13.4.tgz", @@ -5012,32 +5000,6 @@ ], "license": "CC-BY-4.0" }, - "node_modules/chai": { - "version": "4.3.4", - "resolved": "https://registry.npmjs.org/chai/-/chai-4.3.4.tgz", - "integrity": "sha512-yS5H68VYOCtN1cjfwumDSuzn/9c+yza4f3reKXlE5rUg7SFcCEy90gJvydNgOYtblyf4Zi6jIWRnXOgErta0KA==", - "dev": true, - "dependencies": { - "assertion-error": "^1.1.0", - "check-error": "^1.0.2", - "deep-eql": "^3.0.1", - "get-func-name": "^2.0.0", - "pathval": "^1.1.1", - "type-detect": "^4.0.5" - }, - "engines": { - "node": ">=4" - } - }, - "node_modules/chai-subset": { - "version": "1.6.0", - "resolved": "https://registry.npmjs.org/chai-subset/-/chai-subset-1.6.0.tgz", - "integrity": "sha1-pdDKFOMpp5WW7XAFi2ZGvWmIz+k=", - "dev": true, - "engines": { - "node": ">=4" - } - }, "node_modules/chalk": { "version": "4.1.2", "resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz", @@ -5071,15 +5033,6 @@ "integrity": "sha512-mT8iDcrh03qDGRRmoA2hmBJnxpllMR+0/0qlzjqZES6NdiWDcZkCNAk4rPFZ9Q85r27unkiNNg8ZOiwZXBHwcA==", "dev": true }, - "node_modules/check-error": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/check-error/-/check-error-1.0.2.tgz", - "integrity": "sha512-BrgHpW9NURQgzoNyjfq0Wu6VFO6D7IZEmJNdtgNqpzGG8RuNFHt2jQxWlAs4HMe119chBnv+34syEZtc6IhLtA==", - "dev": true, - "engines": { - "node": "*" - } - }, "node_modules/chrome-trace-event": { "version": "1.0.3", "resolved": "https://registry.npmjs.org/chrome-trace-event/-/chrome-trace-event-1.0.3.tgz", @@ -5729,18 +5682,6 @@ } } }, - "node_modules/deep-eql": { - "version": "3.0.1", - "resolved": "https://registry.npmjs.org/deep-eql/-/deep-eql-3.0.1.tgz", - "integrity": "sha512-+QeIQyN5ZuO+3Uk5DYh6/1eKO0m0YmJFGNmFHGACpf1ClL1nmlV/p4gNgbl2pJGxgXb4faqo6UE+M5ACEMyVcw==", - "dev": true, - "dependencies": { - "type-detect": "^4.0.0" - }, - "engines": { - "node": ">=0.12" - } - }, "node_modules/deep-is": { "version": "0.1.3", "resolved": "https://registry.npmjs.org/deep-is/-/deep-is-0.1.3.tgz", @@ -6132,15 +6073,6 @@ "node": ">= 0.4" } }, - "node_modules/duplexer2": { - "version": "0.1.4", - "resolved": "https://registry.npmjs.org/duplexer2/-/duplexer2-0.1.4.tgz", - "integrity": "sha1-ixLauHjA1p4+eJEFFmKjL8a93ME=", - "dev": true, - "dependencies": { - "readable-stream": "^2.0.2" - } - }, "node_modules/eastasianwidth": { "version": "0.2.0", "resolved": "https://registry.npmjs.org/eastasianwidth/-/eastasianwidth-0.2.0.tgz", @@ -7639,15 +7571,6 @@ "node": ">=6.9.0" } }, - "node_modules/get-func-name": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/get-func-name/-/get-func-name-2.0.0.tgz", - "integrity": "sha512-Hm0ixYtaSZ/V7C8FJrtZIuBBI+iSgL+1Aq82zSu8VQNB4S3Gk8e7Qs3VwBDJAhmRZcFqkl3tQu36g/Foh5I5ig==", - "dev": true, - "engines": { - "node": "*" - } - }, "node_modules/get-intrinsic": { "version": "1.2.7", "resolved": "https://registry.npmjs.org/get-intrinsic/-/get-intrinsic-1.2.7.tgz", @@ -11034,15 +10957,6 @@ "node": ">=8" } }, - "node_modules/pathval": { - "version": "1.1.1", - "resolved": "https://registry.npmjs.org/pathval/-/pathval-1.1.1.tgz", - "integrity": "sha512-Dp6zGqpTdETdR63lehJYPeIOqpiNBNtc7BpWSLrOje7UaIsE5aY92r/AunQA7rsXvet3lrJ3JnZX29UPTKXyKQ==", - "dev": true, - "engines": { - "node": "*" - } - }, "node_modules/pend": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/pend/-/pend-1.2.0.tgz", @@ -13108,16 +13022,6 @@ "node": ">= 0.8" } }, - "node_modules/stream-combiner2": { - "version": "1.1.1", - "resolved": "https://registry.npmjs.org/stream-combiner2/-/stream-combiner2-1.1.1.tgz", - "integrity": "sha1-+02KFCDqNidk4hrUeAOXvry0HL4=", - "dev": true, - "dependencies": { - "duplexer2": "~0.1.0", - "readable-stream": "^2.0.2" - } - }, "node_modules/streamx": { "version": "2.23.0", "resolved": "https://registry.npmjs.org/streamx/-/streamx-2.23.0.tgz", diff --git a/test/Logger.js b/test/Logger.js index 2c16d52e..4033e9ee 100644 --- a/test/Logger.js +++ b/test/Logger.js @@ -1,6 +1,3 @@ -const chai = require("chai"); -chai.use(require("chai-subset")); -const { expect } = chai; const Logger = require("../lib/Logger"); class TestLogger extends Logger { diff --git a/test/analyzer.js b/test/analyzer.js index a38cc2a8..bdc2177f 100644 --- a/test/analyzer.js +++ b/test/analyzer.js @@ -1,6 +1,3 @@ -const chai = require("chai"); -chai.use(require("chai-subset")); -const { expect } = chai; const fs = require("fs"); const path = require("path"); const del = require("del"); diff --git a/test/parseUtils.js b/test/parseUtils.js index f129ea19..72ce96e8 100644 --- a/test/parseUtils.js +++ b/test/parseUtils.js @@ -1,6 +1,3 @@ -const chai = require("chai"); -chai.use(require("chai-subset")); -const { expect } = chai; const fs = require("fs"); const { parseBundle } = require("../lib/parseUtils"); diff --git a/test/plugin.js b/test/plugin.js index 2566c288..193f8a0d 100644 --- a/test/plugin.js +++ b/test/plugin.js @@ -1,6 +1,3 @@ -const chai = require("chai"); -chai.use(require("chai-subset")); -const { expect } = chai; const fs = require("fs"); const del = require("del"); const path = require("path"); diff --git a/test/statsUtils.js b/test/statsUtils.js index f1f84a86..6b9b2ef5 100644 --- a/test/statsUtils.js +++ b/test/statsUtils.js @@ -1,6 +1,3 @@ -const chai = require("chai"); -chai.use(require("chai-subset")); -const { expect } = chai; const path = require("path"); const { readFileSync } = require("fs"); const globby = require("globby"); diff --git a/test/utils.js b/test/utils.js index d01ecc15..140d6d90 100644 --- a/test/utils.js +++ b/test/utils.js @@ -1,6 +1,3 @@ -const chai = require("chai"); -chai.use(require("chai-subset")); -const { expect } = chai; const { createAssetsFilter } = require("../lib/utils"); describe("createAssetsFilter", function () { diff --git a/test/viewer.js b/test/viewer.js index 70f33087..4b56734a 100644 --- a/test/viewer.js +++ b/test/viewer.js @@ -1,6 +1,3 @@ -const chai = require("chai"); -chai.use(require("chai-subset")); -const { expect } = chai; const crypto = require("crypto"); const net = require("net"); From 779834af331774b67258d549f032080087b6fb6d Mon Sep 17 00:00:00 2001 From: alexander-akait Date: Fri, 23 Jan 2026 16:34:28 +0300 Subject: [PATCH 3/8] test: refactor --- test/Logger.js | 10 +++--- test/analyzer.js | 78 +++++++++++++++++++++++----------------------- test/parseUtils.js | 8 ++--- test/plugin.js | 26 +++++++--------- test/statsUtils.js | 2 +- test/utils.js | 44 +++++++++++++------------- test/viewer.js | 12 +++---- 7 files changed, 89 insertions(+), 91 deletions(-) diff --git a/test/Logger.js b/test/Logger.js index 4033e9ee..916d769a 100644 --- a/test/Logger.js +++ b/test/Logger.js @@ -33,12 +33,12 @@ describe("Logger", function () { ) { it(`should log "${level}" message`, function () { logger[level]("msg1", "msg2"); - expect(logger.logs).to.deep.equal([[level, "msg1", "msg2"]]); + expect(logger.logs).toEqual([[level, "msg1", "msg2"]]); }); } else { it(`should not log "${level}" message`, function () { logger[level]("msg1", "msg2"); - expect(logger.logs).to.be.empty; + expect(logger.logs).toHaveLength(0); }); } } @@ -60,13 +60,13 @@ describe("Logger", function () { }); it("should throw if level is invalid on instance creation", function () { - expect(() => new TestLogger("invalid")).to.throw( + expect(() => new TestLogger("invalid")).toThrow( invalidLogLevelMessage("invalid"), ); }); it("should throw if level is invalid on `setLogLevel`", function () { - expect(() => new TestLogger().setLogLevel("invalid")).to.throw( + expect(() => new TestLogger().setLogLevel("invalid")).toThrow( invalidLogLevelMessage("invalid"), ); }); @@ -89,7 +89,7 @@ function expectLoggerLevel(logger, level) { ) .map((testLevel) => [testLevel, "msg1", "msg2"]); - expect(logger.logs).to.deep.equal(expectedLogs); + expect(logger.logs).toEqual(expectedLogs); } function invalidLogLevelMessage(level) { diff --git a/test/analyzer.js b/test/analyzer.js index bdc2177f..c6f056e8 100644 --- a/test/analyzer.js +++ b/test/analyzer.js @@ -39,7 +39,7 @@ describe("Analyzer", function () { it("should generate report containing worker bundles", async function () { generateReportFrom("with-worker-loader/stats.json"); const chartData = await getChartData(); - expect(chartData[1]).to.containSubset({ + expect(chartData[1]).toMatchObject({ label: "bundle.worker.js", }); }); @@ -47,11 +47,11 @@ describe("Analyzer", function () { it("should generate report for array webpack.config.js", async function () { generateReportFrom("with-array-config/stats.json"); const chartData = await getChartData(); - expect(chartData).to.have.lengthOf(2); - expect(chartData[0]).to.containSubset({ + expect(chartData).toHaveLength(2); + expect(chartData[0]).toMatchObject({ label: "config-1-main.js", }); - expect(chartData[1]).to.containSubset({ + expect(chartData[1]).toMatchObject({ label: "config-2-main.js", }); }); @@ -59,7 +59,7 @@ describe("Analyzer", function () { it("should generate report when worker bundles have dynamic imports", async function () { generateReportFrom("with-worker-loader-dynamic-import/stats.json"); const chartData = await getChartData(); - expect(chartData[1]).to.containSubset({ + expect(chartData[1]).toMatchObject({ label: "1.bundle.worker.js", }); }); @@ -67,7 +67,7 @@ describe("Analyzer", function () { it("should support stats files with modules inside `chunks` array", async function () { generateReportFrom("with-modules-in-chunks/stats.json"); const chartData = await getChartData(); - expect(chartData).to.containSubset( + expect(chartData).toMatchObject( require("./stats/with-modules-in-chunks/expected-chart-data"), ); }); @@ -75,7 +75,7 @@ describe("Analyzer", function () { it("should record accurate byte lengths for sources with special chars", async function () { generateReportFrom("with-special-chars/stats.json"); const chartData = await getChartData(); - expect(chartData).to.containSubset( + expect(chartData).toMatchObject( require("./stats/with-special-chars/expected-chart-data"), ); }); @@ -88,7 +88,7 @@ describe("Analyzer", function () { it("should use information about concatenated modules generated by webpack 4", async function () { generateReportFrom("with-module-concatenation-info/stats.json"); const chartData = await getChartData(); - expect(chartData[0].groups[0]).to.containSubset( + expect(chartData[0].groups[0]).toMatchObject( require("./stats/with-module-concatenation-info/expected-chart-data"), ); }); @@ -96,7 +96,7 @@ describe("Analyzer", function () { it("should handle stats with minimal configuration", async function () { generateReportFrom("minimal-stats/stats.json"); const chartData = await getChartData(); - expect(chartData).to.be.empty; + expect(chartData).toHaveLength(0); }); it.skip("should not filter out modules that we couldn't find during parsing", async function () { @@ -108,14 +108,14 @@ describe("Analyzer", function () { unparsedModules++; } }); - expect(unparsedModules).to.equal(1); + expect(unparsedModules).toBe(1); }); it.skip("should gracefully parse invalid chunks", async function () { generateReportFrom("with-invalid-chunk/stats.json"); const chartData = await getChartData(); const invalidChunk = chartData.find((i) => i.label === "invalid-chunk.js"); - expect(invalidChunk.groups).to.containSubset([ + expect(invalidChunk.groups).toMatchObject([ { id: 1, label: "invalid.js", @@ -123,24 +123,24 @@ describe("Analyzer", function () { statSize: 24, }, ]); - expect(invalidChunk.statSize).to.equal(24); - expect(invalidChunk.parsedSize).to.equal(30); + expect(invalidChunk.statSize).toBe(24); + expect(invalidChunk.parsedSize).toBe(30); }); it.skip("should gracefully process missing chunks", async function () { generateReportFrom("with-missing-chunk/stats.json"); const chartData = await getChartData(); const invalidChunk = chartData.find((i) => i.label === "invalid-chunk.js"); - expect(invalidChunk).to.exist; - expect(invalidChunk.statSize).to.equal(24); + expect(invalidChunk).toBeDefined(); + expect(invalidChunk.statSize).toBe(24); forEachChartItem([invalidChunk], (item) => { - expect(typeof item.statSize).to.equal("number"); - expect(item.parsedSize).to.be.undefined; + expect(typeof item.statSize).toBe("number"); + expect(item.parsedSize).toBeUndefined(); }); const validChunk = chartData.find((i) => i.label === "valid-chunk.js"); forEachChartItem([validChunk], (item) => { - expect(typeof item.statSize).to.equal("number"); - expect(typeof item.parsedSize).to.equal("number"); + expect(typeof item.statSize).toBe("number"); + expect(typeof item.parsedSize).toBe("number"); }); }); @@ -148,16 +148,16 @@ describe("Analyzer", function () { generateReportFrom("with-missing-module-chunks/stats.json"); const chartData = await getChartData(); const invalidChunk = chartData.find((i) => i.label === "invalid-chunk.js"); - expect(invalidChunk).to.exist; - expect(invalidChunk.statSize).to.equal(568); + expect(invalidChunk).toBeDefined(); + expect(invalidChunk.statSize).toBe(568); forEachChartItem([invalidChunk], (item) => { - expect(typeof item.statSize).to.equal("number"); - expect(item.parsedSize).to.be.undefined; + expect(typeof item.statSize).toBe("number"); + expect(item.parsedSize).toBeUndefined(); }); const validChunk = chartData.find((i) => i.label === "valid-chunk.js"); forEachChartItem([validChunk], (item) => { - expect(typeof item.statSize).to.equal("number"); - expect(typeof item.parsedSize).to.equal("number"); + expect(typeof item.statSize).toBe("number"); + expect(typeof item.parsedSize).toBe("number"); }); }); @@ -174,7 +174,7 @@ describe("Analyzer", function () { it("should properly parse extremely optimized bundle from webpack 5", async function () { generateReportFrom("extremely-optimized-webpack-5-bundle/stats.json"); const chartData = await getChartData(); - expect(chartData).to.containSubset( + expect(chartData).toMatchObject( require("./stats/extremely-optimized-webpack-5-bundle/expected-chart-data"), ); }); @@ -184,7 +184,7 @@ describe("Analyzer", function () { async function () { generateReportFrom("webpack-5-bundle-with-single-entry/stats.json"); const chartData = await getChartData(); - expect(chartData).to.containSubset( + expect(chartData).toMatchObject( require("./stats/webpack-5-bundle-with-single-entry/expected-chart-data"), ); }, @@ -195,7 +195,7 @@ describe("Analyzer", function () { async function () { generateReportFrom("webpack-5-bundle-with-multiple-entries/stats.json"); const chartData = await getChartData(); - expect(chartData).to.containSubset( + expect(chartData).toMatchObject( require("./stats/webpack-5-bundle-with-multiple-entries/expected-chart-data"), ); }, @@ -206,7 +206,7 @@ describe("Analyzer", function () { "webpack-5-bundle-with-concatenated-entry-module/stats.json", ); const chartData = await getChartData(); - expect(chartData).to.containSubset( + expect(chartData).toMatchObject( require("./stats/webpack-5-bundle-with-concatenated-entry-module/expected-chart-data"), ); }); @@ -215,7 +215,7 @@ describe("Analyzer", function () { generateJSONReportFrom("with-modules-in-chunks/stats.json"); const chartData = require(path.resolve(__dirname, "output/report.json")); - expect(chartData).to.containSubset( + expect(chartData).toMatchObject( require("./stats/with-modules-in-chunks/expected-chart-data"), ); }); @@ -228,7 +228,7 @@ describe("Analyzer", function () { it("should map chunks correctly to entrypoints", async function () { generateReportFrom("with-multiple-entrypoints/stats.json"); const chartData = await getChartData(); - expect(chartData).to.containSubset( + expect(chartData).toMatchObject( require("./stats/with-multiple-entrypoints/expected-chart-data"), ); }); @@ -250,7 +250,7 @@ describe("Analyzer", function () { const generatedReportTitle = await getTitleFromReport(); - expect(generatedReportTitle).to.equal(reportTitle); + expect(generatedReportTitle).toBe(reportTitle); }); it("should take the -t option", async function () { const reportTitle = "A string report title"; @@ -259,7 +259,7 @@ describe("Analyzer", function () { const generatedReportTitle = await getTitleFromReport(); - expect(generatedReportTitle).to.equal(reportTitle); + expect(generatedReportTitle).toBe(reportTitle); }); it("should use a suitable default title", async function () { generateReportFrom("with-modules-chunk.json"); @@ -278,7 +278,7 @@ describe("Analyzer", function () { "with-modules-chunk.json", "--compression-algorithm brotli", ); - expect(await getCompressionAlgorithm()).to.equal("brotli"); + expect(await getCompressionAlgorithm()).toBe("brotli"); }); it("should accept --compression-algorithm gzip", async function () { @@ -286,7 +286,7 @@ describe("Analyzer", function () { "with-modules-chunk.json", "--compression-algorithm gzip", ); - expect(await getCompressionAlgorithm()).to.equal("gzip"); + expect(await getCompressionAlgorithm()).toBe("gzip"); }); if (isZstdSupported) { @@ -295,13 +295,13 @@ describe("Analyzer", function () { "with-modules-chunk.json", "--compression-algorithm zstd", ); - expect(await getCompressionAlgorithm()).to.equal("zstd"); + expect(await getCompressionAlgorithm()).toBe("zstd"); }); } it("should default to gzip", async function () { generateReportFrom("with-modules-chunk.json"); - expect(await getCompressionAlgorithm()).to.equal("gzip"); + expect(await getCompressionAlgorithm()).toBe("gzip"); }); }); }); @@ -356,9 +356,9 @@ function forEachChartItem(chartData, cb) { async function expectValidReport(opts) { const { bundleLabel = "bundle.js", statSize = 141 } = opts || {}; - expect(fs.existsSync(`${__dirname}/output/report.html`)).to.be.true; + expect(fs.existsSync(`${__dirname}/output/report.html`)).toBe(true); const chartData = await getChartData(); - expect(chartData[0]).to.containSubset({ + expect(chartData[0]).toMatchObject({ label: bundleLabel, statSize, }); diff --git a/test/parseUtils.js b/test/parseUtils.js index 72ce96e8..05eb2995 100644 --- a/test/parseUtils.js +++ b/test/parseUtils.js @@ -20,15 +20,15 @@ describe("parseBundle", function () { fs.readFileSync(`${BUNDLES_DIR}/${bundleName}.modules.json`), ); - expect(bundle.src).to.equal(fs.readFileSync(bundleFile, "utf8")); - expect(bundle.modules).to.deep.equal(expectedModules.modules); + expect(bundle.src).toBe(fs.readFileSync(bundleFile, "utf8")); + expect(bundle.modules).toEqual(expectedModules.modules); }); }); it("should parse invalid bundle and return it's content and empty modules hash", function () { const bundleFile = `${BUNDLES_DIR}/invalidBundle.js`; const bundle = parseBundle(bundleFile); - expect(bundle.src).to.equal(fs.readFileSync(bundleFile, "utf8")); - expect(bundle.modules).to.deep.equal({}); + expect(bundle.src).toBe(fs.readFileSync(bundleFile, "utf8")); + expect(bundle.modules).toEqual({}); }); }); diff --git a/test/plugin.js b/test/plugin.js index 193f8a0d..26bcc9f3 100644 --- a/test/plugin.js +++ b/test/plugin.js @@ -8,7 +8,7 @@ const { isZstdSupported } = require("../src/sizeUtils"); describe("Plugin", function () { describe("options", function () { it("should be optional", function () { - expect(() => new BundleAnalyzerPlugin()).not.to.throw(); + expect(() => new BundleAnalyzerPlugin()).not.toThrow(); }); }); }); @@ -58,10 +58,10 @@ describe("Plugin", function () { await webpackCompile(config); const chartData = await getChartDataFromJSONReport(); - expect(chartData).to.exist; + expect(chartData).toBeDefined(); }); - it("should support webpack config with `multi` module", async function () { + it.only("should support webpack config with `multi` module", async function () { const config = makeWebpackConfig(); config.entry.bundle = ["./src/a.js", "./src/b.js"]; @@ -73,7 +73,7 @@ describe("Plugin", function () { (group) => group.label === "bundle.js", ); - expect(bundleGroup.groups).to.containSubset([ + expect(bundleGroup.groups).toMatchObject([ { label: "src", path: "./src", @@ -106,7 +106,7 @@ describe("Plugin", function () { await webpackCompile(config); const chartData = await getChartDataFromReport(); - expect(chartData.map((i) => i.label)).to.deep.equal(["bundle.js"]); + expect(chartData.map((i) => i.label)).toEqual(["bundle.js"]); }); }); }); @@ -116,7 +116,7 @@ describe("Plugin", function () { const config = makeWebpackConfig(); await webpackCompile(config, "4.44.2"); const generatedReportTitle = await getTitleFromReport(); - expect(generatedReportTitle).to.match( + expect(generatedReportTitle).toMatch( /^webpack-bundle-analyzer \[.* at \d{2}:\d{2}\]/u, ); }); @@ -130,7 +130,7 @@ describe("Plugin", function () { }); await webpackCompile(config, "4.44.2"); const generatedReportTitle = await getTitleFromReport(); - expect(generatedReportTitle).to.equal(reportTitle); + expect(generatedReportTitle).toBe(reportTitle); }); it("should support a function value", async function () { @@ -142,7 +142,7 @@ describe("Plugin", function () { }); await webpackCompile(config, "4.44.2"); const generatedReportTitle = await getTitleFromReport(); - expect(generatedReportTitle).to.equal(reportTitleResult); + expect(generatedReportTitle).toBe(reportTitleResult); }); it("should propagate an error in a function", async function () { @@ -162,7 +162,7 @@ describe("Plugin", function () { error = e; } - expect(error).to.equal(reportTitleError); + expect(error).toBe(reportTitleError); }); }); @@ -221,14 +221,12 @@ describe("Plugin", function () { expect( fs.existsSync(`${__dirname}/output/${bundleFilename}`), - "bundle file missing", - ).to.be.true; + ).toBe(true); expect( fs.existsSync(`${__dirname}/output/${reportFilename}`), - "report file missing", - ).to.be.true; + ).toBe(true); const chartData = await getChartDataFromReport(reportFilename); - expect(chartData[0]).to.containSubset({ + expect(chartData[0]).toMatchObject({ label: bundleLabel, statSize, parsedSize, diff --git a/test/statsUtils.js b/test/statsUtils.js index 6b9b2ef5..9bf09b08 100644 --- a/test/statsUtils.js +++ b/test/statsUtils.js @@ -66,7 +66,7 @@ describe("StatsSerializeStream", () => { }); async function expectProperJson(json) { - expect(await stringify(json)).to.equal(JSON.stringify(json, null, 2)); + expect(await stringify(json)).toBe(JSON.stringify(json, null, 2)); } async function stringify(json) { diff --git a/test/utils.js b/test/utils.js index 140d6d90..f4a67ca6 100644 --- a/test/utils.js +++ b/test/utils.js @@ -4,39 +4,39 @@ describe("createAssetsFilter", function () { it("should create a noop filter if pattern is not set", function () { for (const pattern of [undefined, null, []]) { const filter = createAssetsFilter(pattern); - expect(filter("foo")).to.equal(true); + expect(filter("foo")).toBe(true); } }); it("should allow a string as a pattern", function () { const filter = createAssetsFilter("^foo"); - expect(filter("foo")).to.equal(false); - expect(filter("foo-bar")).to.equal(false); - expect(filter("bar")).to.equal(true); - expect(filter("bar-foo")).to.equal(true); + expect(filter("foo")).toBe(false); + expect(filter("foo-bar")).toBe(false); + expect(filter("bar")).toBe(true); + expect(filter("bar-foo")).toBe(true); }); it("should allow a RegExp as a pattern", function () { const filter = createAssetsFilter(/^foo/iu); - expect(filter("foo")).to.equal(false); - expect(filter("FOO")).to.equal(false); - expect(filter("foo-bar")).to.equal(false); - expect(filter("bar")).to.equal(true); - expect(filter("bar-foo")).to.equal(true); + expect(filter("foo")).toBe(false); + expect(filter("FOO")).toBe(false); + expect(filter("foo-bar")).toBe(false); + expect(filter("bar")).toBe(true); + expect(filter("bar-foo")).toBe(true); }); it("should allow a filter function as a pattern", function () { const filter = createAssetsFilter((asset) => asset.startsWith("foo")); - expect(filter("foo")).to.equal(false); - expect(filter("foo-bar")).to.equal(false); - expect(filter("bar")).to.equal(true); - expect(filter("bar-foo")).to.equal(true); + expect(filter("foo")).toBe(false); + expect(filter("foo-bar")).toBe(false); + expect(filter("bar")).toBe(true); + expect(filter("bar-foo")).toBe(true); }); it("should throw on invalid pattern types", function () { - expect(() => createAssetsFilter(5)).to.throw('but "5" got'); - expect(() => createAssetsFilter({ a: 1 })).to.throw('but "{ a: 1 }" got'); - expect(() => createAssetsFilter([true])).to.throw('but "true" got'); + expect(() => createAssetsFilter(5)).toThrow('but "5" got'); + expect(() => createAssetsFilter({ a: 1 })).toThrow('but "{ a: 1 }" got'); + expect(() => createAssetsFilter([true])).toThrow('but "true" got'); }); it("should allow an array of patterns", function () { @@ -45,10 +45,10 @@ describe("createAssetsFilter", function () { /bar$/iu, (asset) => asset.includes("baz"), ]); - expect(filter("foo")).to.equal(false); - expect(filter("bar")).to.equal(false); - expect(filter("fooBar")).to.equal(false); - expect(filter("fooBARbaz")).to.equal(false); - expect(filter("bar-foo")).to.equal(true); + expect(filter("foo")).toBe(false); + expect(filter("bar")).toBe(false); + expect(filter("fooBar")).toBe(false); + expect(filter("fooBARbaz")).toBe(false); + expect(filter("bar-foo")).toBe(true); }); }); diff --git a/test/viewer.js b/test/viewer.js index 4b56734a..7c6209a0 100644 --- a/test/viewer.js +++ b/test/viewer.js @@ -67,7 +67,7 @@ describe("WebSocket server", function () { // Because data may be received in multiple chunks, only check the first one if (count === 1) { - expect(chunk.equals(expected)).to.be.true; + expect(chunk.equals(expected)).toBe(true); } // Send a WebSocket frame with a reserved opcode (5) to trigger an error @@ -104,14 +104,14 @@ describe("getEntrypoints", () => { }, }, }; - expect(JSON.stringify(getEntrypoints(bundleStats))).to.equal( + expect(JSON.stringify(getEntrypoints(bundleStats))).toBe( JSON.stringify(["A", "B"]), ); }); it("should handle when bundlestats is null or undefined ", function () { - expect(JSON.stringify(getEntrypoints(null))).to.equal(JSON.stringify([])); - expect(JSON.stringify(getEntrypoints(undefined))).to.equal( + expect(JSON.stringify(getEntrypoints(null))).toBe(JSON.stringify([])); + expect(JSON.stringify(getEntrypoints(undefined))).toBe( JSON.stringify([]), ); }); @@ -120,12 +120,12 @@ describe("getEntrypoints", () => { const bundleStatsWithoutEntryPoints = {}; expect( JSON.stringify(getEntrypoints(bundleStatsWithoutEntryPoints)), - ).to.equal(JSON.stringify([])); + ).toBe(JSON.stringify([])); }); it("should handle when entrypoints is empty", function () { const bundleStatsEmptyEntryPoint = { entrypoints: {} }; - expect(JSON.stringify(getEntrypoints(bundleStatsEmptyEntryPoint))).to.equal( + expect(JSON.stringify(getEntrypoints(bundleStatsEmptyEntryPoint))).toBe( JSON.stringify([]), ); }); From f9d03c4d3e862a9b3bd5f27a0e47ada5b3e4c3e3 Mon Sep 17 00:00:00 2001 From: alexander-akait Date: Fri, 23 Jan 2026 16:43:43 +0300 Subject: [PATCH 4/8] test: refactor --- test/analyzer.js | 42 ++++++++++++++++-------------------------- test/plugin.js | 12 ++++-------- test/viewer.js | 10 ++++------ 3 files changed, 24 insertions(+), 40 deletions(-) diff --git a/test/analyzer.js b/test/analyzer.js index c6f056e8..2db46fe6 100644 --- a/test/analyzer.js +++ b/test/analyzer.js @@ -7,10 +7,6 @@ const { isZstdSupported } = require("../src/sizeUtils"); let browser; -// On node.js v16 and lower, the calculated gzip is slightly different -const itFailsOnNode16 = - parseInt(process.versions.node.split(".")[0]) <= 16 ? it.failing : it; - describe("Analyzer", function () { jest.setTimeout(15000); @@ -179,27 +175,21 @@ describe("Analyzer", function () { ); }); - itFailsOnNode16( - "should properly parse webpack 5 bundle with single entry", - async function () { - generateReportFrom("webpack-5-bundle-with-single-entry/stats.json"); - const chartData = await getChartData(); - expect(chartData).toMatchObject( - require("./stats/webpack-5-bundle-with-single-entry/expected-chart-data"), - ); - }, - ); + it("should properly parse webpack 5 bundle with single entry", async function () { + generateReportFrom("webpack-5-bundle-with-single-entry/stats.json"); + const chartData = await getChartData(); + expect(chartData).toMatchObject( + require("./stats/webpack-5-bundle-with-single-entry/expected-chart-data"), + ); + }); - itFailsOnNode16( - "should properly parse webpack 5 bundle with multiple entries", - async function () { - generateReportFrom("webpack-5-bundle-with-multiple-entries/stats.json"); - const chartData = await getChartData(); - expect(chartData).toMatchObject( - require("./stats/webpack-5-bundle-with-multiple-entries/expected-chart-data"), - ); - }, - ); + it("should properly parse webpack 5 bundle with multiple entries", async function () { + generateReportFrom("webpack-5-bundle-with-multiple-entries/stats.json"); + const chartData = await getChartData(); + expect(chartData).toMatchObject( + require("./stats/webpack-5-bundle-with-multiple-entries/expected-chart-data"), + ); + }); it("should properly parse webpack 5 bundle with an entry module that is a concatenated module", async function () { generateReportFrom( @@ -236,7 +226,7 @@ describe("Analyzer", function () { it("should return empty chartData if there are no entrypoints", async function () { generateReportFrom("with-no-entrypoints/stats.json"); const chartData = await getChartData(); - expect(chartData).to.be.empty; + expect(chartData).toHaveLength(0); }); describe("options", function () { @@ -266,7 +256,7 @@ describe("Analyzer", function () { const generatedReportTitle = await getTitleFromReport(); - expect(generatedReportTitle).to.match( + expect(generatedReportTitle).toMatch( /^webpack-bundle-analyzer \[.* at \d{2}:\d{2}\]/u, ); }); diff --git a/test/plugin.js b/test/plugin.js index 26bcc9f3..0c21a9d9 100644 --- a/test/plugin.js +++ b/test/plugin.js @@ -61,7 +61,7 @@ describe("Plugin", function () { expect(chartData).toBeDefined(); }); - it.only("should support webpack config with `multi` module", async function () { + it("should support webpack config with `multi` module", async function () { const config = makeWebpackConfig(); config.entry.bundle = ["./src/a.js", "./src/b.js"]; @@ -181,7 +181,7 @@ describe("Plugin", function () { await expectValidReport({ parsedSize: 1311, gzipSize: 341 }); }); - it.only("should support brotli", async function () { + it("should support brotli", async function () { const config = makeWebpackConfig({ analyzerOpts: { compressionAlgorithm: "brotli" }, }); @@ -219,12 +219,8 @@ describe("Plugin", function () { gzipSize, } = { gzipSize: 770, ...opts }; - expect( - fs.existsSync(`${__dirname}/output/${bundleFilename}`), - ).toBe(true); - expect( - fs.existsSync(`${__dirname}/output/${reportFilename}`), - ).toBe(true); + expect(fs.existsSync(`${__dirname}/output/${bundleFilename}`)).toBe(true); + expect(fs.existsSync(`${__dirname}/output/${reportFilename}`)).toBe(true); const chartData = await getChartDataFromReport(reportFilename); expect(chartData[0]).toMatchObject({ label: bundleLabel, diff --git a/test/viewer.js b/test/viewer.js index 7c6209a0..e2b860db 100644 --- a/test/viewer.js +++ b/test/viewer.js @@ -111,16 +111,14 @@ describe("getEntrypoints", () => { it("should handle when bundlestats is null or undefined ", function () { expect(JSON.stringify(getEntrypoints(null))).toBe(JSON.stringify([])); - expect(JSON.stringify(getEntrypoints(undefined))).toBe( - JSON.stringify([]), - ); + expect(JSON.stringify(getEntrypoints(undefined))).toBe(JSON.stringify([])); }); it("should handle when bundlestats is empty", function () { const bundleStatsWithoutEntryPoints = {}; - expect( - JSON.stringify(getEntrypoints(bundleStatsWithoutEntryPoints)), - ).toBe(JSON.stringify([])); + expect(JSON.stringify(getEntrypoints(bundleStatsWithoutEntryPoints))).toBe( + JSON.stringify([]), + ); }); it("should handle when entrypoints is empty", function () { From 376a10884ea01f42b94f771fa3c7ed8fc61ab273 Mon Sep 17 00:00:00 2001 From: alexander-akait Date: Fri, 23 Jan 2026 16:59:00 +0300 Subject: [PATCH 5/8] test: refactor --- test/plugin.js | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/test/plugin.js b/test/plugin.js index 0c21a9d9..73f4098c 100644 --- a/test/plugin.js +++ b/test/plugin.js @@ -39,10 +39,8 @@ describe("Plugin", function () { await webpackCompile(config); await expectValidReport({ - parsedSize: 1343, - // On node.js v16 and lower, the calculated gzip is one byte larger. Nice. - gzipSize: - parseInt(process.versions.node.split(".")[0]) <= 16 ? 360 : 358, + parsedSize: 1349, + gzipSize: 358, }); }); }); @@ -222,14 +220,23 @@ describe("Plugin", function () { expect(fs.existsSync(`${__dirname}/output/${bundleFilename}`)).toBe(true); expect(fs.existsSync(`${__dirname}/output/${reportFilename}`)).toBe(true); const chartData = await getChartDataFromReport(reportFilename); - expect(chartData[0]).toMatchObject({ + + const expected = { label: bundleLabel, statSize, parsedSize, gzipSize, - brotliSize: opts.brotliSize, - zstdSize: opts.zstdSize, - }); + }; + + if (typeof opts.brotliSize !== "undefined") { + expected.brotliSize = opts.brotliSize; + } + + if (typeof opts.zstdSize !== "undefined") { + expected.zstdSize = opts.zstdSize; + } + + expect(chartData[0]).toMatchObject(expected); } function getChartDataFromJSONReport(reportFilename = "report.json") { From f971f0d84cb00ee97d5be7649744f61749aa93b1 Mon Sep 17 00:00:00 2001 From: alexander-akait Date: Fri, 23 Jan 2026 18:01:37 +0300 Subject: [PATCH 6/8] test: refactor --- test/plugin.js | 43 ++++++++++++++++++++++--------------------- 1 file changed, 22 insertions(+), 21 deletions(-) diff --git a/test/plugin.js b/test/plugin.js index 73f4098c..c7549d4b 100644 --- a/test/plugin.js +++ b/test/plugin.js @@ -71,22 +71,24 @@ describe("Plugin", function () { (group) => group.label === "bundle.js", ); - expect(bundleGroup.groups).toMatchObject([ - { - label: "src", - path: "./src", - groups: [ - { - label: "a.js", - path: "./src/a.js", - }, - { - label: "b.js", - path: "./src/b.js", - }, - ], - }, - ]); + expect(bundleGroup.groups).toEqual( + expect.arrayContaining([ + expect.objectContaining({ + label: "src", + path: "./src", + groups: expect.arrayContaining([ + expect.objectContaining({ + label: "a.js", + path: "./src/a.js", + }), + expect.objectContaining({ + label: "b.js", + path: "./src/b.js", + }), + ]), + }), + ]), + ); }); }); @@ -168,7 +170,7 @@ describe("Plugin", function () { it("should default to gzip", async function () { const config = makeWebpackConfig({ analyzerOpts: {} }); await webpackCompile(config, "4.44.2"); - await expectValidReport({ parsedSize: 1311, gzipSize: 341 }); + await expectValidReport({ parsedSize: 1317, gzipSize: 341 }); }); it("should support gzip", async function () { @@ -176,7 +178,7 @@ describe("Plugin", function () { analyzerOpts: { compressionAlgorithm: "gzip" }, }); await webpackCompile(config, "4.44.2"); - await expectValidReport({ parsedSize: 1311, gzipSize: 341 }); + await expectValidReport({ parsedSize: 1317, gzipSize: 341 }); }); it("should support brotli", async function () { @@ -185,8 +187,7 @@ describe("Plugin", function () { }); await webpackCompile(config, "4.44.2"); await expectValidReport({ - parsedSize: 1317, - gzipSize: undefined, + parsedSize: 1311, brotliSize: 295, }); }); @@ -197,7 +198,7 @@ describe("Plugin", function () { }); await webpackCompile(config, "4.44.2"); await expectValidReport({ - parsedSize: 1311, + parsedSize: 1317, gzipSize: undefined, brotliSize: undefined, zstdSize: 345, From bd7b4afa6903d9b3d3892efd629c3669aa40bbaa Mon Sep 17 00:00:00 2001 From: alexander-akait Date: Fri, 23 Jan 2026 18:07:12 +0300 Subject: [PATCH 7/8] test: refactor --- test/plugin.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/plugin.js b/test/plugin.js index c7549d4b..942146aa 100644 --- a/test/plugin.js +++ b/test/plugin.js @@ -187,7 +187,7 @@ describe("Plugin", function () { }); await webpackCompile(config, "4.44.2"); await expectValidReport({ - parsedSize: 1311, + parsedSize: 1317, brotliSize: 295, }); }); From b1955e3671c629029142d0d33bba45670950e2a7 Mon Sep 17 00:00:00 2001 From: alexander-akait Date: Fri, 23 Jan 2026 18:11:06 +0300 Subject: [PATCH 8/8] test: refactor --- test/plugin.js | 1 + 1 file changed, 1 insertion(+) diff --git a/test/plugin.js b/test/plugin.js index 942146aa..1c49be6a 100644 --- a/test/plugin.js +++ b/test/plugin.js @@ -188,6 +188,7 @@ describe("Plugin", function () { await webpackCompile(config, "4.44.2"); await expectValidReport({ parsedSize: 1317, + gzipSize: 770, brotliSize: 295, }); });