Skip to content

Commit 05b54f1

Browse files
test(css): compare the color corpus, and group the parser jobs by language
css-parsing-tests has 8366 cases and webpack compared 13 of them — the whole color half was run only to confirm no crash, with upstream's expected values discarded. They are CSSOM serializations rather than minifier output, so they cannot be compared literally; reading both the input and that serialization through webpack's own folding and canonicalizing to `#rrggbb` does compare, wherever both land in sRGB. That is 796 cases, and webpack agrees on all of them — no exception list. Where it declines to fold (lab, lch, out-of-gamut) the two spellings are not claims about the same thing, so those stay out rather than becoming noise: comparing every case reports 5549 differences, essentially all of them that. The three jobs reading an upstream parser corpus become one matrix, named for the language rather than for whose repository the fixtures live in — which had already drifted, since `html5lib` reads WPT for the corpus html5lib-tests dropped. They differed only in submodule, suite and coverage flag.
1 parent cb7e443 commit 05b54f1

3 files changed

Lines changed: 99 additions & 92 deletions

File tree

‎.github/workflows/test.yml‎

Lines changed: 38 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -280,54 +280,45 @@ jobs:
280280
env:
281281
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
282282

283-
# Parses all of test262 with webpack's parser and with acorn, and compares the
284-
# trees. Coverage instrumentation makes the parser ~5x slower, so this one job
285-
# runs without it — every line it reaches is covered by the suites that upload.
286-
test262-parser:
283+
# One job per language, the way `runtimes` is one per runtime: each reads that
284+
# language's upstream corpus, and they differ only in which submodule they
285+
# check out and which suite they run.
286+
parser:
287+
# Named for the language alone: a matrix row carries the suite and the
288+
# coverage flag too, and the generated name would otherwise print all three.
289+
name: parser (${{ matrix.language }})
287290
needs: [lint, basic, unit]
291+
strategy:
292+
fail-fast: false
293+
matrix:
294+
include:
295+
- language: css
296+
submodules: test/external/css-parsing-tests
297+
script: cover:css-parsing
298+
flags: css-parsing
299+
# WPT is 161k files, so only this leg checks it out, and only one
300+
# commit deep — it carries the tree-construction corpus html5lib-tests
301+
# dropped.
302+
- language: html
303+
submodules: test/external/html5lib-tests test/external/wpt
304+
script: cover:html5lib
305+
flags: html5lib
306+
# Parses all of test262 with webpack's parser and with acorn and
307+
# compares the trees. Coverage instrumentation makes the parser ~5x
308+
# slower, so this leg runs without it — every line it reaches is
309+
# covered by the suites that upload.
310+
- language: js
311+
submodules: test/external/test262-cases
312+
script: test:test262-parser
288313
runs-on: ubuntu-latest
289-
# Bounded: the suite allows ten minutes per area per mode, so a stall
314+
# Bounded: the js leg allows ten minutes per area per mode, so a stall
290315
# would otherwise hold a runner for the 6h default.
291316
timeout-minutes: 60
292317
steps:
293318
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
294319

295-
- name: Check out the test262 corpus
296-
run: node tooling/retry.js git submodule update --init --depth 1 test/external/test262-cases
297-
298-
- name: Use Node.js
299-
uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7.0.0
300-
with:
301-
node-version: lts/*
302-
cache: yarn
303-
304-
- run: node tooling/retry.js yarn --frozen-lockfile
305-
306-
- run: yarn link --frozen-lockfile || true
307-
308-
- run: yarn link webpack --frozen-lockfile
309-
310-
- name: Cache jest result
311-
uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
312-
with:
313-
path: .jest-cache
314-
key: jest-test262-parser-${{ runner.os }}-${{ hashFiles('**/yarn.lock', '**/jest.config.js') }}-${{ github.sha }}
315-
restore-keys: |
316-
jest-test262-parser-${{ runner.os }}-${{ hashFiles('**/yarn.lock', '**/jest.config.js') }}-
317-
jest-test262-parser-${{ runner.os }}-
318-
319-
- run: yarn test:test262-parser --ci --cacheDirectory .jest-cache
320-
321-
html5lib:
322-
needs: [lint, basic, unit]
323-
runs-on: ubuntu-latest
324-
steps:
325-
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
326-
327-
# WPT is 161k files, so only this job checks it out, and only one commit
328-
# deep — it carries the tree-construction corpus html5lib-tests dropped.
329-
- name: Check out the html5lib and WPT corpora
330-
run: node tooling/retry.js git submodule update --init --depth 1 test/external/html5lib-tests test/external/wpt
320+
- name: Check out the ${{ matrix.language }} corpus
321+
run: node tooling/retry.js git submodule update --init --depth 1 ${{ matrix.submodules }}
331322

332323
- name: Use Node.js
333324
uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7.0.0
@@ -345,17 +336,18 @@ jobs:
345336
uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
346337
with:
347338
path: .jest-cache
348-
key: jest-html5lib-${{ runner.os }}-${{ hashFiles('**/yarn.lock', '**/jest.config.js') }}-${{ github.sha }}
339+
key: jest-parser-${{ matrix.language }}-${{ runner.os }}-${{ hashFiles('**/yarn.lock', '**/jest.config.js') }}-${{ github.sha }}
349340
restore-keys: |
350-
jest-html5lib-${{ runner.os }}-${{ hashFiles('**/yarn.lock', '**/jest.config.js') }}-
351-
jest-html5lib-${{ runner.os }}-
341+
jest-parser-${{ matrix.language }}-${{ runner.os }}-${{ hashFiles('**/yarn.lock', '**/jest.config.js') }}-
342+
jest-parser-${{ matrix.language }}-${{ runner.os }}-
352343
353-
- run: yarn cover:html5lib --ci --cacheDirectory .jest-cache
344+
- run: yarn ${{ matrix.script }} --ci --cacheDirectory .jest-cache
354345

355346
- name: Codecov
347+
if: matrix.flags
356348
uses: codecov/codecov-action@fb8b3582c8e4def4969c97caa2f19720cb33a72f # v7.0.0
357349
with:
358-
flags: html5lib
350+
flags: ${{ matrix.flags }}
359351
env:
360352
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
361353

@@ -466,45 +458,6 @@ jobs:
466458
env:
467459
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
468460

469-
css-parsing:
470-
needs: [lint, basic, unit]
471-
runs-on: ubuntu-latest
472-
steps:
473-
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
474-
475-
- name: Check out the css-parsing corpus
476-
run: node tooling/retry.js git submodule update --init --depth 1 test/external/css-parsing-tests
477-
478-
- name: Use Node.js
479-
uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7.0.0
480-
with:
481-
node-version: lts/*
482-
cache: yarn
483-
484-
- run: node tooling/retry.js yarn --frozen-lockfile
485-
486-
- run: yarn link --frozen-lockfile || true
487-
488-
- run: yarn link webpack --frozen-lockfile
489-
490-
- name: Cache jest result
491-
uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
492-
with:
493-
path: .jest-cache
494-
key: jest-css-parsing-${{ runner.os }}-${{ hashFiles('**/yarn.lock', '**/jest.config.js') }}-${{ github.sha }}
495-
restore-keys: |
496-
jest-css-parsing-${{ runner.os }}-${{ hashFiles('**/yarn.lock', '**/jest.config.js') }}-
497-
jest-css-parsing-${{ runner.os }}-
498-
499-
- run: yarn cover:css-parsing --ci --cacheDirectory .jest-cache
500-
501-
- name: Codecov
502-
uses: codecov/codecov-action@fb8b3582c8e4def4969c97caa2f19720cb33a72f # v7.0.0
503-
with:
504-
flags: css-parsing
505-
env:
506-
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
507-
508461
# Run webpack's test suite under Deno and Bun (spec validation suites excluded).
509462
runtimes:
510463
needs: [lint, basic, unit]

‎AGENTS.md‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -202,16 +202,16 @@ The directory listings below are the canonical map of the repository. **Whenever
202202

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

205-
- `test/` — All test suites (`unitCases/`, `cases/`, `configCases/`, `specCases/`, `watchCases/`, `hotCases/`, `statsCases/`, `typesCases/`, `benchmarkCases/`, `memoryLimitCases/`, etc.). `templates/` holds the suite drivers (`TestCases.js`, `ConfigTestCases.js`, `HotTestCases.js`, `WatchTestCases.js`) that the `*.test.js` / `*.basictest.js` / `*.longtest.js` files at the top of `test/` are thin shims over — each exports `describeCases(config)` and resolves case directories against the `test/` root, never against its own. The option sets those shims pass live together in `templates/variants.js`, re-exported as `variants`, so what differs between the suites reads side by side rather than one file at a time — a shim exists per entry because jest parallelizes per file, not per describe. `harness/` holds what runs those suites rather than what they test — jest's own lifecycle (`globalSetup.js`, `globalTeardown.js`, `setupTestFramework.js`), the `patch-node-env.js` environment, the crash reporter, the case `runner/` and `snapshot/` resolver, and `runtimes/` for the preload and setup files that let jest run under Bun and Deno. Reusable assertions and fixtures stay in `helpers/`. `RoundTripConfigCases` re-bundles the output of `configCases` marked with a `roundTrip.js` file. `external/` holds what webpack does not maintain — every git submodule checked out for testing, today the four spec corpora below, so a directory there is upstream's to change and ours only to pin. `external/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. acorn's own test suite is the one upstream corpus that is vendored instead of pinned, as `fixtures/acorn-corpus.json`, because acorn's npm tarball ships no tests. `unitCases/WebpackParser.unittest.js` holds both of webpack's parser entry points to it, and owns the recording of it too — no generator script and no `package.json` entry: it replays acorn's `test/tests*.js` against a driver that records each case instead of running it, and keeps the sources and options, never the expected trees, which it takes from acorn itself. Bumping the `acorn` devDependency is what moves the corpus, and the same file is what refreshes it: clone acorn at the new version into `node_modules/.cache/acorn-<version>` and re-run it with `WEBPACK_UPDATE_ACORN_CORPUS=1`. Where that checkout exists the run checks the vendored corpus against it; where it does not — CI, and every machine that never cloned — the corpus stands on the version it names, which the run pins to the installed acorn.
205+
- `test/` — All test suites (`unitCases/`, `cases/`, `configCases/`, `specCases/`, `watchCases/`, `hotCases/`, `statsCases/`, `typesCases/`, `benchmarkCases/`, `memoryLimitCases/`, etc.). `templates/` holds the suite drivers (`TestCases.js`, `ConfigTestCases.js`, `HotTestCases.js`, `WatchTestCases.js`) that the `*.test.js` / `*.basictest.js` / `*.longtest.js` files at the top of `test/` are thin shims over — each exports `describeCases(config)` and resolves case directories against the `test/` root, never against its own. The option sets those shims pass live together in `templates/variants.js`, re-exported as `variants`, so what differs between the suites reads side by side rather than one file at a time — a shim exists per entry because jest parallelizes per file, not per describe. `harness/` holds what runs those suites rather than what they test — jest's own lifecycle (`globalSetup.js`, `globalTeardown.js`, `setupTestFramework.js`), the `patch-node-env.js` environment, the crash reporter, the case `runner/` and `snapshot/` resolver, and `runtimes/` for the preload and setup files that let jest run under Bun and Deno. Reusable assertions and fixtures stay in `helpers/`. `RoundTripConfigCases` re-bundles the output of `configCases` marked with a `roundTrip.js` file. `external/` holds what webpack does not maintain — every git submodule checked out for testing, today the four spec corpora below, so a directory there is upstream's to change and ours only to pin. `external/wpt/` is web-platform-tests, checked out one commit deep by the `parser (html)` and `syntax-equivalence` jobs — it is where the HTML tree-construction corpus lives since html5lib-tests dropped it. acorn's own test suite is the one upstream corpus that is vendored instead of pinned, as `fixtures/acorn-corpus.json`, because acorn's npm tarball ships no tests. `unitCases/WebpackParser.unittest.js` holds both of webpack's parser entry points to it, and owns the recording of it too — no generator script and no `package.json` entry: it replays acorn's `test/tests*.js` against a driver that records each case instead of running it, and keeps the sources and options, never the expected trees, which it takes from acorn itself. Bumping the `acorn` devDependency is what moves the corpus, and the same file is what refreshes it: clone acorn at the new version into `node_modules/.cache/acorn-<version>` and re-run it with `WEBPACK_UPDATE_ACORN_CORPUS=1`. Where that checkout exists the run checks the vendored corpus against it; where it does not — CI, and every machine that never cloned — the corpus stands on the version it names, which the run pins to the installed acorn.
206206

207207
**Git submodules** — every submodule lives under `test/external/`, checked out on demand: `yarn setup` does not fetch them, and each CI job fetches only the submodules it needs, one commit deep.
208208

209209
| Path | Upstream | Fetched by |
210210
| --------------------------------- | ------------------------------------------------------------------------------------- | ------------------------------------------------ |
211-
| `test/external/test262-cases` | [tc39/test262](https://github.com/tc39/test262) | `test262`, `test262-parser` |
212-
| `test/external/html5lib-tests` | [html5lib/html5lib-tests](https://github.com/html5lib/html5lib-tests) | `html5lib` |
213-
| `test/external/wpt` | [web-platform-tests/wpt](https://github.com/web-platform-tests/wpt) | `html5lib`, `syntax-equivalence` (every browser) |
214-
| `test/external/css-parsing-tests` | [CourtBouillon/css-parsing-tests](https://github.com/CourtBouillon/css-parsing-tests) | `css-parsing` |
211+
| `test/external/test262-cases` | [tc39/test262](https://github.com/tc39/test262) | `test262`, `parser (js)` |
212+
| `test/external/html5lib-tests` | [html5lib/html5lib-tests](https://github.com/html5lib/html5lib-tests) | `parser (html)` |
213+
| `test/external/wpt` | [web-platform-tests/wpt](https://github.com/web-platform-tests/wpt) | `parser (html)`, `syntax-equivalence` (browsers) |
214+
| `test/external/css-parsing-tests` | [CourtBouillon/css-parsing-tests](https://github.com/CourtBouillon/css-parsing-tests) | `parser (css)` |
215215

216216
```sh
217217
git submodule update --init --recursive --depth 1 # check out the commits the repo pins
@@ -718,7 +718,7 @@ A report that measures rather than tests — performance, memory, a preview buil
718718

719719
**Do not read, chase, or act on coverage until every suite that uploads it has finished.** Coverage arrives in pieces: each test suite uploads its own flag as it completes, and the service recomputes the totals after every upload. Until the last one lands the number on the PR is a partial sum — it will show a large drop, the comment will be rewritten in place several times with different percentages, and a deficit at that moment means "some suites have not reported yet", not "you lost coverage". The report itself says so, naming how many uploads the head is still missing; **read that line before reading the percentage**, and treat a non-zero count as "not ready" no matter how alarming the number next to it. **A red coverage check while coverage changed is the normal state of a healthy PR mid-run** and is not a failure to fix.
720720

721-
**What you are waiting for is those suites, not the whole run.** The uploading suites are the jobs that call the coverage action in `.github/workflows/test.yml` — today `unit`, `integration`, `test262`, `html5lib` and `css-parsing` (`integration` is sharded, so it alone accounts for most of the uploads, and it is gated behind `lint`, `basic` and `unit`). Read the workflow rather than this list if they have moved. Everything else on the PR — benchmarks, code scanning, dependency review, preview publishing, type-coverage, the changeset echo — never uploads a coverage report and cannot move the number, so a coverage gap is safe to fix while they are still running or even while one of them is red. Waiting on them buys nothing.
721+
**What you are waiting for is those suites, not the whole run.** The uploading suites are the jobs that call the coverage action in `.github/workflows/test.yml` — today `unit`, `integration`, `test262` and the `parser (css)` / `parser (html)` legs (`integration` is sharded, so it alone accounts for most of the uploads, and it is gated behind `lint`, `basic` and `unit`). Read the workflow rather than this list if they have moved. Everything else on the PR — benchmarks, code scanning, dependency review, preview publishing, type-coverage, the changeset echo — never uploads a coverage report and cannot move the number, so a coverage gap is safe to fix while they are still running or even while one of them is red. Waiting on them buys nothing.
722722

723723
Once those suites are in, read the report; only then is a genuine patch gap worth adding a test for. Chasing an intermediate number costs a round of pointless commits and, worse, tempts changes to `lib/` that exist only to move a percentage.
724724

‎test/specCases/cssParsing-webpack.spectest.js‎

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,11 @@ const fs = require("fs");
1313
const path = require("path");
1414
const { Volume, createFsFromVolume } = require("memfs");
1515
const webpack = require("../..");
16-
const { parseABlocksContents } = require("../../lib/css/syntax");
16+
const { COLOR_NAME_TO_RGB } = require("../../lib/css/data");
17+
const {
18+
SourceProcessor,
19+
parseABlocksContents
20+
} = require("../../lib/css/syntax");
1721
const expectNoDeprecations = require("../helpers/expectNoDeprecations");
1822

1923
const casesDir = path.resolve(__dirname, "../external/css-parsing-tests");
@@ -220,3 +224,53 @@ describe("css-parsing-tests block contents", () => {
220224
});
221225
}
222226
});
227+
228+
// The corpus states each color as CSSOM serializes it, which is not what a
229+
// minifier writes — so this compares webpack's reading of the input against its
230+
// reading of that serialization, and only where both resolved to sRGB.
231+
describe("css-parsing-tests colors", () => {
232+
const files = fs.existsSync(casesDir)
233+
? fs.readdirSync(casesDir).filter((f) => f.startsWith("color"))
234+
: [];
235+
if (files.length === 0) {
236+
it("submodule not initialized (run `git submodule update --init test/external/css-parsing-tests`)", () => {
237+
// No-op: the conformance data is an optional git submodule.
238+
});
239+
240+
return;
241+
}
242+
243+
const fold = (color) =>
244+
new SourceProcessor()
245+
.process(`a{color:${color}}`, { mode: "minify" })
246+
.code.slice(8, -1);
247+
248+
/**
249+
* @param {string} folded what the minifier wrote
250+
* @returns {string | null} the same color as `#rrggbb`, or null if it is not sRGB
251+
*/
252+
const canonical = (folded) => {
253+
const named = COLOR_NAME_TO_RGB.get(folded);
254+
if (named !== undefined) return `#${named.toString(16).padStart(6, "0")}`;
255+
const short = /^#([0-9a-f]{3})$/.exec(folded);
256+
if (short) return `#${[...short[1]].map((c) => c + c).join("")}`;
257+
return /^#[0-9a-f]{6}$/.test(folded) ? folded : null;
258+
};
259+
260+
for (const file of files) {
261+
const data = JSON.parse(fs.readFileSync(path.join(casesDir, file), "utf8"));
262+
for (let i = 0; i < data.length; i += 2) {
263+
const source = data[i];
264+
const serialized = data[i + 1];
265+
if (typeof source !== "string" || serialized === null) continue;
266+
const want = canonical(fold(serialized));
267+
if (want === null) continue;
268+
const got = canonical(fold(source));
269+
if (got === null) continue;
270+
271+
it(`${file} reads ${JSON.stringify(source)} as ${want}`, () => {
272+
expect(got).toBe(want);
273+
});
274+
}
275+
}
276+
});

0 commit comments

Comments
 (0)