refactor(test): migrate errors.js/warnings.js to Jest snapshots#20966
Conversation
|
|
This PR is packaged and the instant preview is available (dba0399). Install it locally:
npm i -D webpack@https://pkg.pr.new/webpack@dba0399
yarn add -D webpack@https://pkg.pr.new/webpack@dba0399
pnpm add -D webpack@https://pkg.pr.new/webpack@dba0399 |
Codecov Report✅ All modified and coverable lines are covered by tests. ❌ Your changes status has failed because you have indirect coverage changes. Learn more about Unexpected Coverage Changes and reasons for indirect coverage changes. Additional details and impacted files@@ Coverage Diff @@
## main #20966 +/- ##
==========================================
- Coverage 90.92% 90.90% -0.02%
==========================================
Files 573 573
Lines 58610 58610
Branches 15762 15762
==========================================
- Hits 53290 53281 -9
- Misses 5320 5329 +9
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
fe8c3a6 to
e68efe3
Compare
alexander-akait
left a comment
There was a problem hiding this comment.
What about to name files - warnings.snap instead normal.snap?
|
Same for errors.snap |
e68efe3 to
d8fd646
Compare
This comment was marked as outdated.
This comment was marked as outdated.
|
Looks like this failure also exists on the main branch. just wait this PR #20967 FAIL test/ConfigTestCases.basictest.js (94.868 s, 414 MB heap size)
● ConfigTestCases › html › style-tag › exported tests › should process inline <style> tags through the CSS pipeline
expect(received).toBe(expected) // Object.is equality
Expected: 3
Received: 1
38 | // three times.
39 | const cssHeaderCount = (page_namespaceObject.match(/css data:text\/css,/g) || []).length;
> 40 | expect(cssHeaderCount).toBe(3);
| ^
41 | });
42 |
43 | /******/ })()
|
96d684e to
150239a
Compare
|
Yeah, already fix, conflict in merge |
| "webpack": patch | ||
| --- | ||
|
|
||
| Migrate hand-written errors.js/warnings.js test expectation files to Jest snapshots. The `checkArrayExpectation` helper now falls back to `toMatchSnapshot()` when no expectation file exists, with path normalization for portable snapshots across environments. |
There was a problem hiding this comment.
I think we don't need to mark this as a patch, it is internal change, right?
|
@xiaoxiaojx can you rebase again and I think we can merge it, thanks |
a6cf557 to
2d1910c
Compare
Replace hand-written regex-based error/warning expectation files with Jest snapshot matching. checkArrayExpectation now falls back to toMatchSnapshot() when no .js expectation file exists, with path normalization (<TEST_DIR>, <WEBPACK_ROOT>, <ANCESTOR>) for portable snapshots across environments. - 90 errors.js/warnings.js files deleted across test/cases and test/configCases - 5 complex/function-based expectation files retained - Per-case snapshot hooks added to TestCases.template.js - Snapshot resolver updated for new suite mapping
The module resolution order is nondeterministic, so exact snapshot matching fails across runs. Restore the original loose regex.
28861d4 to
c0ff11b
Compare
Types CoverageCoverage after merging refactor/errors-warnings-to-snapshots into main will be
Coverage Report
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
ci failed due to: webpack/enhanced-resolve#587 |
|
@xiaoxiaojx yeah, already released |
|
thanks for fix |
Summary
Replace hand-written
errors.js/warnings.jsregex-based test expectation files with Jest snapshot matching, as discussed in the feedback that "adding them manually is very annoying".The
checkArrayExpectationhelper now falls back totoMatchSnapshot()when no.jsexpectation file exists. Absolute paths are normalized with stable placeholders (<TEST_DIR>,<WEBPACK_ROOT>,<ANCESTOR>) so snapshots are portable across environments.Key changes:
test/checkArrayExpectation.js— snapshot fallback with configurableSNAPSHOT_FIELDSfor easy extensiontest/TestCases.template.js— per-case snapshot hooks viaregisterPerCaseSnapshotHookstest/harness/snapshot/resolver.js— addednormalsuite mappingerrors.js/warnings.jsdeleted acrosstest/cases/andtest/configCases/, replaced by__snapshots__/*.snapAdding or updating error/warning expectations is now
yarn jest -uinstead of hand-writing regex patterns.What kind of change does this PR introduce?
refactor
Did you add tests for your changes?
This PR modifies the test infrastructure itself. All existing test cases continue to pass — the assertion mechanism changed from regex matching to snapshot matching, but the coverage is the same.
Does this PR introduce a breaking change?
No.
If relevant, what needs to be documented once your changes are merged or what have you already documented?
TESTING_DOCS.md could be updated to describe the new snapshot-based workflow for error/warning expectations (run
yarn jest -uinstead of writingerrors.js/warnings.js).Use of AI
Claude Code was used to draft the implementation, perform the bulk migration, and scan for issues (path leaks, false positive snapshots) under human review.