Skip to content

Commit 5752faf

Browse files
test: move focused suites and fix parser benchmark (#22133)
* test: move focused suites to unitCases * test: use available minified parser fixture * test: restore three minified parser fixture
1 parent f9817c9 commit 5752faf

28 files changed

Lines changed: 634 additions & 584 deletions

‎AGENTS.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ The loader context is not one of these: `LoaderContext` and the loader-definitio
154154
- `test/configCases/ecmaVersion/browserslist*/webpack.config.js` — these carry an **inline** snapshot of the resolved `output.environment`, so an entry there must be added to nine config files.
155155
- `test/unitCases/__snapshots__/target-browserslist.unittest.js.snap` — same, per browserslist query.
156156
- `test/unitCases/Defaults.unittest.js` — its **inline** snapshots carry the whole resolved config twice over, once for the base defaults and once per browserslist fixture, so an `output.environment` property adds a line to each. It runs in the `unit` flag, which no `configCases` or `basic` run reaches.
157-
- `test/Validation.test.js` — its **inline** snapshots quote the "these properties are valid" list, so a new property under `module.rules` changes one. It runs in the `integration` matrix, not `basic`.
157+
- `test/unitCases/Validation.unittest.js` — its **inline** snapshots quote the "these properties are valid" list, so a new property under `module.rules` changes one. It runs in the `unit` matrix, not `basic`.
158158

159159
Skipping any layer silently breaks the option. After editing schemas, run `yarn fix:special` so `lib/` code can reference the updated types. If you added or modified options, consider updating `examples/` and run `yarn build:examples` to verify.
160160

‎TESTING_DOCS.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ This document explains the structure of the `test/` directory in the Webpack pro
105105
- **Options**: `--output <file>` (report path), `--baseline <file>` (report to compare against), `--summary <file>` (append the markdown comparison, e.g. `$GITHUB_STEP_SUMMARY`), `--filter` / `--negative-filter` (regexps matched against `<category>/<case>`, also read from `FILTER` / `NEGATIVE_FILTER`).
106106
- **Note**: the cases are built with the defaults a user gets — minification on, no `output.pathinfo` — not with the `ConfigTestCases` ones. Needs Node.js >= 22.15 for zstd.
107107

108-
### 16. `BannerPlugin.test.js`
108+
### 16. `unitCases/BannerPlugin.unittest.js`
109109

110110
- **Purpose**: Tests Webpack’s `BannerPlugin` functionality.
111111
- **Usage**: Ensures that the plugin correctly adds banners to the bundled files.

‎eslint.config.mjs‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -287,16 +287,16 @@ export default defineConfig([
287287
}
288288
},
289289
{
290-
files: ["test/Compiler-filesystem-caching.test.js"],
290+
files: ["test/unitCases/Compiler-filesystem-caching.unittest.js"],
291291
languageOptions: {
292292
ecmaVersion: 2022
293293
}
294294
},
295295
{
296296
files: [
297297
"test/configCases/{dll-plugin-entry,dll-plugin-side-effects,dll-plugin}/**/webpack.config.js",
298-
"test/NodeTemplatePlugin.test.js",
299-
"test/PersistentCaching.test.js"
298+
"test/unitCases/NodeTemplatePlugin.unittest.js",
299+
"test/unitCases/PersistentCaching.unittest.js"
300300
],
301301
rules: {
302302
"import/extensions": "off",

‎test/benchmarkCases/js-parser-unit/index.bench.mjs‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@ const typescriptSource = fs.readFileSync(
3030
const threeEsmPath = fileURLToPath(import.meta.resolve("three"));
3131
const threeEsmSource = fs.readFileSync(threeEsmPath, "utf8");
3232
const threeEsmMinSource = fs.readFileSync(
33-
threeEsmPath.replace(/\.js$/, ".min.js"),
33+
fileURLToPath(
34+
new URL("../../js/benchmark/three.module.min.js", import.meta.url)
35+
),
3436
"utf8"
3537
);
3638
// Popular libraries also shipped as devDependencies.
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import fs from "fs/promises";
2+
import { fileURLToPath } from "url";
3+
import { minify } from "terser";
4+
5+
export async function setup() {
6+
const source = await fs.readFile(
7+
fileURLToPath(import.meta.resolve("three")),
8+
"utf8"
9+
);
10+
const { code } = await minify(source, { module: true });
11+
12+
if (!code) {
13+
throw new Error("Failed to minify the three ESM fixture");
14+
}
15+
16+
const outputPath = fileURLToPath(
17+
new URL("../../js/benchmark/three.module.min.js", import.meta.url)
18+
);
19+
20+
await fs.mkdir(new URL("../../js/benchmark/", import.meta.url), {
21+
recursive: true
22+
});
23+
await fs.writeFile(outputPath, code);
24+
}
Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
"use strict";
22

33
const path = require("path");
4+
const testDirectory = path.resolve(__dirname, "..");
45
const fs = require("graceful-fs");
56

6-
const webpack = require("..");
7-
const expectNoDeprecations = require("./helpers/expectNoDeprecations");
7+
const webpack = require("../..");
8+
const expectNoDeprecations = require("../helpers/expectNoDeprecations");
89

9-
const pluginDir = path.join(__dirname, "js", "BannerPlugin");
10+
const pluginDir = path.join(testDirectory, "js", "BannerPlugin");
1011
const outputDir = path.join(pluginDir, "output");
1112

1213
expectNoDeprecations();
@@ -42,15 +43,15 @@ describe("BannerPlugin", () => {
4243
expect(footerFileResults[0]).toBe("/*! banner is a string */");
4344
fs.writeFileSync(entry2File, "2", "utf8");
4445
compiler.run((err, stats) => {
45-
const { assets } = /** @type {import("../").Stats} */ (stats).toJson();
46-
const assetsList = /** @type {import("../").StatsAsset[]} */ (assets);
46+
const { assets } = /** @type {import("../../").Stats} */ (stats).toJson();
47+
const assetsList = /** @type {import("../../").StatsAsset[]} */ (assets);
4748
expect(
48-
/** @type {import("../").StatsAsset} */ (
49+
/** @type {import("../../").StatsAsset} */ (
4950
assetsList.find((as) => as.name === "entry1.js")
5051
).emitted
5152
).toBe(false);
5253
expect(
53-
/** @type {import("../").StatsAsset} */ (
54+
/** @type {import("../../").StatsAsset} */ (
5455
assetsList.find((as) => as.name === "entry2.js")
5556
).emitted
5657
).toBe(true);

test/ChangesAndRemovals.test.js renamed to test/unitCases/ChangesAndRemovals.unittest.js

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,30 @@
11
"use strict";
22

3-
require("./helpers/warmup-webpack");
3+
require("../helpers/warmup-webpack");
44

55
const path = require("path");
6+
const testDirectory = path.resolve(__dirname, "..");
67
const fs = require("graceful-fs");
78
const { Volume, createFsFromVolume } = require("memfs");
89
/** @type {(path: string, callback: (err?: unknown) => void) => void} */
910
const rimraf = require("rimraf");
10-
const expectNoDeprecations = require("./helpers/expectNoDeprecations");
11+
const expectNoDeprecations = require("../helpers/expectNoDeprecations");
1112

1213
/**
13-
* @param {import("../").Configuration} config config
14-
* @returns {import("../").Compiler} compiler
14+
* @param {import("../../").Configuration} config config
15+
* @returns {import("../../").Compiler} compiler
1516
*/
1617
const createCompiler = (config) => {
17-
const webpack = require("..");
18+
const webpack = require("../..");
1819

19-
const compiler = /** @type {import("../").Compiler} */ (webpack(config));
20+
const compiler = /** @type {import("../../").Compiler} */ (webpack(config));
2021
compiler.outputFileSystem = /** @type {EXPECTED_ANY} */ (
2122
createFsFromVolume(new Volume())
2223
);
2324
return compiler;
2425
};
2526

26-
const tempFolderPath = path.join(__dirname, "ChangesAndRemovalsTemp");
27+
const tempFolderPath = path.join(testDirectory, "ChangesAndRemovalsTemp");
2728
const tempFilePath = path.join(tempFolderPath, "temp-file.js");
2829
const tempFile2Path = path.join(tempFolderPath, "temp-file2.js");
2930

@@ -37,7 +38,7 @@ const createSingleCompiler = () =>
3738
});
3839

3940
/**
40-
* @param {import("../").Compiler} compiler compiler
41+
* @param {import("../../").Compiler} compiler compiler
4142
* @param {() => void} action action
4243
*/
4344
const onceDone = (compiler, action) => {
@@ -50,7 +51,7 @@ const onceDone = (compiler, action) => {
5051
};
5152

5253
/**
53-
* @param {import("../").Compiler} compiler compiler
54+
* @param {import("../../").Compiler} compiler compiler
5455
* @returns {{ removed: string[] | undefined, modified: string[] | undefined }} changes
5556
*/
5657
const getChanges = (compiler) => {
@@ -127,7 +128,7 @@ describe("ChangesAndRemovals", () => {
127128
});
128129
})
129130
);
130-
const watcher = /** @type {import("../").Watching} */ (
131+
const watcher = /** @type {import("../../").Watching} */ (
131132
compiler.watch({ aggregateTimeout: 200 }, (err) => {
132133
if (err) done(err);
133134
})
@@ -140,7 +141,7 @@ describe("ChangesAndRemovals", () => {
140141

141142
it("should track modified files when they've been modified", (done) => {
142143
const compiler = createSingleCompiler();
143-
/** @type {import("../").Watching | null} */
144+
/** @type {import("../../").Watching | null} */
144145
let watcher = null;
145146

146147
compiler.hooks.watchRun.tap("ChangesAndRemovalsTest", (compiler) => {
@@ -154,7 +155,7 @@ describe("ChangesAndRemovals", () => {
154155
watcher = null;
155156
});
156157

157-
watcher = /** @type {import("../").Watching} */ (
158+
watcher = /** @type {import("../../").Watching} */ (
158159
compiler.watch({ aggregateTimeout: 200 }, (err) => {
159160
if (err) done(err);
160161
})
@@ -167,7 +168,7 @@ describe("ChangesAndRemovals", () => {
167168

168169
itSkipBun("should track removed file when removing file", (done) => {
169170
const compiler = createSingleCompiler();
170-
/** @type {import("../").Watching | null} */
171+
/** @type {import("../../").Watching | null} */
171172
let watcher = null;
172173

173174
compiler.hooks.watchRun.tap("ChangesAndRemovalsTest", (compiler) => {
@@ -181,7 +182,7 @@ describe("ChangesAndRemovals", () => {
181182
watcher = null;
182183
});
183184

184-
watcher = /** @type {import("../").Watching} */ (
185+
watcher = /** @type {import("../../").Watching} */ (
185186
compiler.watch({ aggregateTimeout: 200 }, (err) => {
186187
if (err) done(err);
187188
})

test/CompilationRelease.test.js renamed to test/unitCases/CompilationRelease.unittest.js

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
11
"use strict";
22

3-
require("./helpers/warmup-webpack");
3+
require("../helpers/warmup-webpack");
44

55
const path = require("path");
6+
const testDirectory = path.resolve(__dirname, "..");
67
const { Volume, createFsFromVolume } = require("memfs");
78

8-
/** @typedef {import("../").Compilation} Compilation */
9-
/** @typedef {import("../").Compiler} Compiler */
10-
/** @typedef {import("../").Module} Module */
11-
/** @typedef {import("../").NormalModule} NormalModule */
12-
/** @typedef {import("../").Stats} Stats */
13-
/** @typedef {import("../").WebpackPluginInstance} WebpackPluginInstance */
9+
/** @typedef {import("../../").Compilation} Compilation */
10+
/** @typedef {import("../../").Compiler} Compiler */
11+
/** @typedef {import("../../").Module} Module */
12+
/** @typedef {import("../../").NormalModule} NormalModule */
13+
/** @typedef {import("../../").Stats} Stats */
14+
/** @typedef {import("../../").WebpackPluginInstance} WebpackPluginInstance */
1415

15-
const CONTEXT = path.join(__dirname, "fixtures");
16+
const CONTEXT = path.join(testDirectory, "fixtures");
1617

1718
// One fixture per nesting level, so every level owns a module instance no other
1819
// level shares — a shared instance is cleaned up by whichever level is reached.
@@ -26,7 +27,7 @@ const LEVEL_ENTRIES = ["./a.js", "./b.js", "./main1.js", "./main2.js"];
2627
*/
2728
const nestedChildPlugin = (depth) => ({
2829
apply(compiler) {
29-
const webpack = require("..");
30+
const webpack = require("../..");
3031

3132
compiler.hooks.make.tapAsync(
3233
"NestedChildPlugin",
@@ -105,12 +106,12 @@ const collectLevels = (compilation, level, out) => {
105106
/**
106107
* Runs one compilation and hands the compiler and stats to the caller before
107108
* closing it.
108-
* @param {import("../").Configuration} options webpack options
109+
* @param {import("../../").Configuration} options webpack options
109110
* @returns {Promise<{ compiler: Compiler, stats: Stats, close: () => Promise<void> }>} the finished build
110111
*/
111112
const build = (options) =>
112113
new Promise((resolve, reject) => {
113-
const webpack = require("..");
114+
const webpack = require("../..");
114115

115116
const compiler = webpack({
116117
mode: "production",
@@ -119,7 +120,7 @@ const build = (options) =>
119120
...options
120121
});
121122
compiler.outputFileSystem =
122-
/** @type {import("../").OutputFileSystem} */
123+
/** @type {import("../../").OutputFileSystem} */
123124
(/** @type {unknown} */ (createFsFromVolume(new Volume())));
124125
compiler.run((err, stats) => {
125126
if (err) return reject(err);
@@ -140,12 +141,12 @@ const build = (options) =>
140141

141142
/**
142143
* Runs one watch build and resolves once the compiler has gone idle.
143-
* @param {import("../").Configuration} options webpack options
144+
* @param {import("../../").Configuration} options webpack options
144145
* @returns {Promise<{ compiler: Compiler, stats: Stats, close: () => Promise<void> }>} the finished build
145146
*/
146147
const watchOnce = (options) =>
147148
new Promise((resolve, reject) => {
148-
const webpack = require("..");
149+
const webpack = require("../..");
149150

150151
const compiler = webpack({
151152
mode: "production",
@@ -154,10 +155,10 @@ const watchOnce = (options) =>
154155
...options
155156
});
156157
compiler.outputFileSystem =
157-
/** @type {import("../").OutputFileSystem} */
158+
/** @type {import("../../").OutputFileSystem} */
158159
(/** @type {unknown} */ (createFsFromVolume(new Volume())));
159160
let settled = false;
160-
const watching = /** @type {import("../").Watching} */ (
161+
const watching = /** @type {import("../../").Watching} */ (
161162
compiler.watch({ aggregateTimeout: 10 }, (err, stats) => {
162163
if (settled) return;
163164
settled = true;
@@ -193,7 +194,7 @@ describe("Compilation release", () => {
193194

194195
// what the next build does before it starts
195196
const internalCompiler =
196-
/** @type {import("../lib/Compiler")} */
197+
/** @type {import("../../lib/Compiler")} */
197198
(/** @type {unknown} */ (compiler));
198199

199200
internalCompiler._cleanupLastCompilation();
@@ -217,7 +218,7 @@ describe("Compilation release", () => {
217218
output: { path: "/" }
218219
});
219220
const internalCompiler =
220-
/** @type {import("../lib/Compiler")} */
221+
/** @type {import("../../lib/Compiler")} */
221222
(/** @type {unknown} */ (compiler));
222223

223224
expect(stats.compilation.modules.size).toBeGreaterThan(0);

0 commit comments

Comments
 (0)