Skip to content

Commit f9817c9

Browse files
test: move unit tests into unitCases (#22132)
1 parent c1e87d4 commit f9817c9

132 files changed

Lines changed: 673 additions & 663 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎AGENTS.md‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ The directory listings below are the canonical map of the repository. **Whenever
105105

106106
**Tests** — see [TESTING_DOCS.md](TESTING_DOCS.md) for directory structure, naming, and how to run a single case.
107107

108-
- `test/` — All test suites (`cases/`, `configCases/`, `watchCases/`, `hotCases/`, `statsCases/`, `typesCases/`, `test262-cases/`, `html5lib-tests/`, `wpt/`, `css-parsing-tests/`, `benchmarkCases/`, `memoryLimitCases/`, etc.). `RoundTripConfigCases` re-bundles the output of `configCases` marked with a `roundTrip.js` file. `wpt/` is web-platform-tests, checked out one commit deep by the `html5lib` and `syntax-equivalence` jobs — it is where the HTML tree-construction corpus lives since html5lib-tests dropped it.
108+
- `test/` — All test suites (`unitCases/`, `cases/`, `configCases/`, `watchCases/`, `hotCases/`, `statsCases/`, `typesCases/`, `test262-cases/`, `html5lib-tests/`, `wpt/`, `css-parsing-tests/`, `benchmarkCases/`, `memoryLimitCases/`, etc.). `RoundTripConfigCases` re-bundles the output of `configCases` marked with a `roundTrip.js` file. `wpt/` is web-platform-tests, checked out one commit deep by the `html5lib` and `syntax-equivalence` jobs — it is where the HTML tree-construction corpus lives since html5lib-tests dropped it.
109109

110110
**Git submodules** — the spec-conformance corpora are submodules, checked out on demand: `yarn setup` does not fetch them, and each CI job fetches only the submodules it needs, one commit deep.
111111

@@ -152,8 +152,8 @@ The loader context is not one of these: `LoaderContext` and the loader-definitio
152152
5. **Generated output and snapshots** — run `yarn fix:special`, then update the snapshots the option's _name_ leaks into. A schema property is read back by several tests that no `configCases/` pattern will match:
153153
- `test/__snapshots__/Cli.basictest.js.snap` — the CLI flags are derived from the schema, so every new property adds one.
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.
155-
- `test/__snapshots__/target-browserslist.unittest.js.snap` — same, per browserslist query.
156-
- `test/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.
155+
- `test/unitCases/__snapshots__/target-browserslist.unittest.js.snap` — same, per browserslist query.
156+
- `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.
157157
- `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`.
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.

‎TESTING_DOCS.md‎

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,9 @@ This document explains the structure of the `test/` directory in the Webpack pro
9191
- **Purpose**: Tests for Webpack’s watch mode functionality.
9292
- **Usage**: Ensures file changes trigger correct rebuild behavior.
9393

94-
### 14. `*.unittest.js`
94+
### 14. `unitCases/`
9595

96-
- **Purpose**: Contains unit tests for various functionalities.
96+
- **Purpose**: Contains `*.unittest.js` unit tests for various functionalities.
9797
- **Usage**: Ensures individual modules and functions work as expected.
9898

9999
### 15. `CodeSizeTestCases.size.js`
@@ -138,7 +138,7 @@ During the test run, webpack compiles this project and compares the result with
138138

139139
### Suites that drive a real browser
140140

141-
`ProfilingPlugin.unittest.js`, `syntaxEquivalence.spectest.js` and
141+
`unitCases/ProfilingPlugin.unittest.js`, `syntaxEquivalence.spectest.js` and
142142
`WebpackDevServer.longtest.js` launch Chrome through `test/helpers/launchChrome.js`.
143143
**A browser that will not launch fails the suite — it is never skipped**, so no
144144
environment can report these checks as passing without having run them. The
@@ -204,20 +204,20 @@ yarn test
204204

205205
**Choose test command based on modified directory:**
206206

207-
| Modified directory/file | Command |
208-
| ------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------ |
209-
| `test/*.unittest.js` | `yarn test:base --testPathPatterns="<filename>"` |
210-
| `test/cases/` | `yarn test:basic` |
211-
| `test/configCases/` | `yarn test:basic --testPathPatterns="ConfigTestCases"` |
212-
| `test/statsCases/` | `yarn test:basic --testPathPatterns="StatsTestCases"` |
213-
| `test/watchCases/` | `yarn test:base --testPathPatterns="WatchTestCases"` |
214-
| `test/hotCases/` | `yarn test:base --testPathPatterns="HotTestCases"` |
215-
| `test/benchmarkCases/` | `FILTER="<case-name>" yarn benchmark` |
216-
| `lib/runtime/` | `yarn test:size` (size of the generated code; `--filter "<category>/"` narrows it) |
217-
| `test/test262-cases/` | `yarn test:test262` (requires `git submodule update --init test/test262-cases` first) |
218-
| `test/html5lib-tests/` | `yarn test:html5lib` (requires `git submodule update --init test/html5lib-tests` first) |
219-
| `test/wpt/` | `yarn test:html5lib` + `yarn test:syntax-equivalence` (require `git submodule update --init --depth 1 test/html5lib-tests test/wpt` first) |
220-
| `test/css-parsing-tests/` | `yarn test:css-parsing` (requires `git submodule update --init test/css-parsing-tests` first) |
207+
| Modified directory/file | Command |
208+
| ------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------ |
209+
| `test/unitCases/*.unittest.js` | `yarn test:base --testPathPatterns="<filename>"` |
210+
| `test/cases/` | `yarn test:basic` |
211+
| `test/configCases/` | `yarn test:basic --testPathPatterns="ConfigTestCases"` |
212+
| `test/statsCases/` | `yarn test:basic --testPathPatterns="StatsTestCases"` |
213+
| `test/watchCases/` | `yarn test:base --testPathPatterns="WatchTestCases"` |
214+
| `test/hotCases/` | `yarn test:base --testPathPatterns="HotTestCases"` |
215+
| `test/benchmarkCases/` | `FILTER="<case-name>" yarn benchmark` |
216+
| `lib/runtime/` | `yarn test:size` (size of the generated code; `--filter "<category>/"` narrows it) |
217+
| `test/test262-cases/` | `yarn test:test262` (requires `git submodule update --init test/test262-cases` first) |
218+
| `test/html5lib-tests/` | `yarn test:html5lib` (requires `git submodule update --init test/html5lib-tests` first) |
219+
| `test/wpt/` | `yarn test:html5lib` + `yarn test:syntax-equivalence` (require `git submodule update --init --depth 1 test/html5lib-tests test/wpt` first) |
220+
| `test/css-parsing-tests/` | `yarn test:css-parsing` (requires `git submodule update --init test/css-parsing-tests` first) |
221221

222222
**Running a single test case** with `--testNamePattern`. The test name format is `<category> <case-name>` (e.g., `css basic`, `asset url`):
223223

‎cspell.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -578,7 +578,7 @@
578578
"types.d.ts",
579579
"**/**/*.snap",
580580
"test/cases/json/weird-properties/globals.json",
581-
"test/JavascriptParser.unittest.js",
581+
"test/unitCases/JavascriptParser.unittest.js",
582582
"lib/javascript/regexpData.js",
583583
"tooling/html-entities.json",
584584
"test/test262-cases/**",

‎jest.config.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ const config = {
1616
"<rootDir>/test/*.test.js",
1717
"<rootDir>/test/*.basictest.js",
1818
"<rootDir>/test/*.longtest.js",
19-
"<rootDir>/test/*.unittest.js",
19+
"<rootDir>/test/unitCases/*.unittest.js",
2020
"<rootDir>/test/*.spectest.js"
2121
],
2222
watchPathIgnorePatterns: [

‎lib/util/globUtils.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -558,7 +558,7 @@ const braceFreeGlobToPathRegExpSource = (glob) => {
558558
* pattern built with `path.resolve` works everywhere; use `[*]` to match a
559559
* literal `*`), and a relative pattern matches at any depth. Matching follows
560560
* `path.matchesGlob`, except where its minimatch shows through — see the
561-
* divergences listed above the corpus in `test/globUtils.unittest.js`.
561+
* divergences listed above the corpus in `test/unitCases/globUtils.unittest.js`.
562562
* @param {string} pattern glob pattern
563563
* @param {GlobMatchOptions=} options options
564564
* @returns {((str: string) => boolean) | null} matcher, null for un-compilable patterns

‎package.json‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@
6565
"test:basic": "yarn test:base --testMatch \"<rootDir>/test/*.basictest.js\"",
6666
"test:basic:deno": "yarn test:base:deno --testMatch \"<rootDir>/test/*.basictest.js\"",
6767
"test:basic:bun": "yarn test:base:bun --testMatch \"<rootDir>/test/*.basictest.js\"",
68-
"test:unit": "yarn test:base --testMatch \"<rootDir>/test/*.unittest.js\"",
68+
"test:unit": "yarn test:base --testMatch \"<rootDir>/test/unitCases/*.unittest.js\"",
6969
"test:integration": "yarn test:base --testMatch \"<rootDir>/test/*.{basictest,longtest,test}.js\"",
7070
"test:integration:a": "yarn test:base --testMatch \"<rootDir>/test/*.{basictest,test}.js\"",
7171
"test:integration:b": "yarn test:base --testMatch \"<rootDir>/test/*.longtest.js\"",
@@ -74,9 +74,9 @@
7474
"test:html5lib": "yarn test:base --testMatch \"<rootDir>/test/html5lib.spectest.js\"",
7575
"test:syntax-equivalence": "yarn test:base --testMatch \"<rootDir>/test/syntaxEquivalence.spectest.js\"",
7676
"test:css-parsing": "yarn test:base --testMatch \"<rootDir>/test/cssParsing-webpack.spectest.js\"",
77-
"test:deno": "yarn test:base:deno --reporters default --reporters \"<rootDir>/test/runtimeCrashReporter.js\" --testMatch \"<rootDir>/test/*.{basictest,longtest,test,unittest}.js\" --testPathIgnorePatterns \"/node_modules/\" \"(ProfilingPlugin[.]unittest|WebpackDevServer)\"",
77+
"test:deno": "yarn test:base:deno --reporters default --reporters \"<rootDir>/test/runtimeCrashReporter.js\" --testMatch \"<rootDir>/test/*.{basictest,longtest,test}.js\" \"<rootDir>/test/unitCases/*.unittest.js\" --testPathIgnorePatterns \"/node_modules/\" \"(ProfilingPlugin[.]unittest|WebpackDevServer)\"",
7878
"test:base:deno": "deno --allow-read --allow-env --allow-sys --allow-ffi --allow-write --allow-run --allow-net --import-map=test/deno-import-map.json --v8-flags='--max-old-space-size=4096' ./node_modules/jest-cli/bin/jest.js --workerIdleMemoryLimit=512MB --logHeapUsage",
79-
"test:bun": "yarn test:base:bun --reporters default --reporters \"<rootDir>/test/runtimeCrashReporter.js\" --testMatch \"<rootDir>/test/*.{basictest,longtest,test,unittest}.js\" --testPathIgnorePatterns \"/node_modules/\" \"(ProfilingPlugin[.]unittest|WebpackDevServer)\"",
79+
"test:bun": "yarn test:base:bun --reporters default --reporters \"<rootDir>/test/runtimeCrashReporter.js\" --testMatch \"<rootDir>/test/*.{basictest,longtest,test}.js\" \"<rootDir>/test/unitCases/*.unittest.js\" --testPathIgnorePatterns \"/node_modules/\" \"(ProfilingPlugin[.]unittest|WebpackDevServer)\"",
8080
"test:base:bun": "NODE_EXTRA_CA_CERTS=./test/hotCases/lazy-compilation/https/cert.pem bun --bun --smol --preload ./test/bun-preload.js ./node_modules/jest-cli/bin/jest.js --workerThreads --workerIdleMemoryLimit=2048MB --logHeapUsage",
8181
"test:update-snapshots": "yarn test:base -u",
8282
"test:size": "node --max-old-space-size=4096 ./test/CodeSizeTestCases.size.js",
@@ -88,7 +88,7 @@
8888
"cover": "yarn cover:all && yarn report:cover",
8989
"cover:base": "node --expose-gc --max-old-space-size=4096 --experimental-vm-modules node_modules/jest-cli/bin/jest --workerIdleMemoryLimit=512MB --logHeapUsage",
9090
"cover:all": "yarn cover:base --coverage",
91-
"cover:unit": "yarn cover:base --testMatch \"<rootDir>/test/*.unittest.js\" --coverage",
91+
"cover:unit": "yarn cover:base --testMatch \"<rootDir>/test/unitCases/*.unittest.js\" --coverage",
9292
"cover:basic": "yarn cover:base --testMatch \"<rootDir>/test/*.basictest.js\" --coverage",
9393
"cover:integration": "yarn cover:base --testMatch \"<rootDir>/test/*.{basictest,longtest,test}.js\" --coverage",
9494
"cover:integration:a": "yarn cover:base --testMatch \"<rootDir>/test/*.{basictest,test}.js\" --coverage",

‎test/configCases/side-effects/deep-import-chain/webpack.config.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const path = require("path");
1010
// chain via `HarmonyImportSideEffectDependency.getModuleEvaluationSideEffectsState`,
1111
// which used to recurse and overflow V8's stack on 5.107.0 (issue #20986).
1212
// The chain here is linear (mod-N is terminal) — that's enough to exercise
13-
// the same recursive path. The unit test in `test/NormalModule.unittest.js`
13+
// the same recursive path. The unit test in `test/unitCases/NormalModule.unittest.js`
1414
// covers a 20000-deep chain to assert the algorithm is stack-safe
1515
// regardless of size.
1616
const N = 500;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"use strict";
22

3-
const AbstractMethodError = require("../lib/errors/AbstractMethodError");
3+
const AbstractMethodError = require("../../lib/errors/AbstractMethodError");
44

55
// Only Node folds the caller name into the message reliably: JSC (Bun) formats
66
// Error.stack differently and Deno's V8 stack frames differ too, so the exact
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"use strict";
22

3-
const ArrayHelpers = require("../lib/util/ArrayHelpers");
3+
const ArrayHelpers = require("../../lib/util/ArrayHelpers");
44

55
describe("ArrayHelpers", () => {
66
it("groupBy should partition into two arrays", () => {
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"use strict";
22

3-
const ArrayQueue = require("../lib/util/ArrayQueue");
3+
const ArrayQueue = require("../../lib/util/ArrayQueue");
44

55
describe("ArrayQueue", () => {
66
it("should seed from an iterable and report length", () => {

0 commit comments

Comments
 (0)