-
Notifications
You must be signed in to change notification settings - Fork 5.4k
feat: add jest-custom-console-reporter #38542
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: feat/jest-clean-console-reporter
Are you sure you want to change the base?
feat: add jest-custom-console-reporter #38542
Conversation
|
CLA Signature Action: All authors have signed the CLA. You may need to manually re-run the blocking PR check if it doesn't pass in a few minutes. |
Builds ready [af13477]
📊 Page Load Benchmark ResultsCurrent Commit: 📄 Localhost MetaMask Test DappSamples: 100 Summary
📈 Detailed Results
|
Builds ready [e27f47e]
UI Startup Metrics (1446 ± 143 ms)
📊 Page Load Benchmark ResultsCurrent Commit: 📄 Localhost MetaMask Test DappSamples: 100 Summary
📈 Detailed Results
|
Builds ready [805f210]
UI Startup Metrics (1273 ± 111 ms)
📊 Page Load Benchmark ResultsCurrent Commit: 📄 Localhost MetaMask Test DappSamples: 100 Summary
📈 Detailed Results
|
Builds ready [4570699]
UI Startup Metrics (1256 ± 87 ms)
📊 Page Load Benchmark ResultsCurrent Commit: 📄 Localhost MetaMask Test DappSamples: 100 Summary
📈 Detailed Results
|
Builds ready [026d725]
UI Startup Metrics (1263 ± 102 ms)
📊 Page Load Benchmark ResultsCurrent Commit: 📄 Localhost MetaMask Test DappSamples: 100 Summary
📈 Detailed Results
|
Builds ready [bc7f02b]
UI Startup Metrics (1289 ± 111 ms)
📊 Page Load Benchmark ResultsCurrent Commit: 📄 Localhost MetaMask Test DappSamples: 100 Summary
📈 Detailed Results
|
bc7f02b to
026d725
Compare
Builds ready [09986f3]
UI Startup Metrics (1234 ± 102 ms)
📊 Page Load Benchmark ResultsCurrent Commit: 📄 Localhost MetaMask Test DappSamples: 100 Summary
📈 Detailed Results
|
|
|
||
| - name: test:integration:coverage | ||
| run: yarn test:integration:coverage --silent | ||
| run: yarn test:integration:coverage |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to remove the --silent flag to be able to detect new warnings/errors
| filePath, | ||
| warnings: currentWarnings, | ||
| }); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bug: New files with warnings appear in two sections
When a new test file with warnings is detected, it gets added to both this.newFiles and this.violations arrays. This causes the same warnings to be displayed twice in the output: once in the "BASELINE VIOLATIONS DETECTED" section (with 🆕 NEW markers) and again in the "NEW FILES" section. The _printResults method calls both _printViolations() and _printNewFiles() when both contain the same file's data, leading to duplicate and confusing output. The test still correctly fails, but the reporting is redundant.
Description
Reason for change:
Building on PR #38208 which added
jest-clean-console-reporterto group and summarize console warnings, this PR adds a baseline enforcement system to prevent new console warnings/errors from being introduced into the codebase.Problem:
While
jest-clean-console-reporterorganizes the output, it doesn't prevent regressions. Developers can still introduce new warnings without realizing it, leading to gradual console pollution over time.Solution:
Added a custom Jest reporter that tracks console warnings per test file and fails tests when warnings increase above the baseline. This creates a "ratchet" effect where the codebase can only get cleaner over time.
Changes:
test/jest/console-baseline-reporter.js- Unified reporter for capture and enforcement modestest/jest/console-categorizer.js- Shared categorization logic using same rules asjest-clean-console-reportertest/jest/console-baseline-unit.json(495 files tracked)test/jest/console-baseline-integration.json(21 files tracked)yarn test:unit:update-baseline- Update unit test baselineyarn test:integration:update-baseline- Update integration test baselinetest/jest/CONSOLE-BASELINE.md- Quick reference guidetest/jest/CONSOLE-BASELINE-TEST.md- Manual testing stepsKey features:
Changelog
CHANGELOG entry: null
Related issues
Relates to: https://github.com/MetaMask/MetaMask-planning/issues/5286
Manual testing steps
See CONSOLE-BASELINE-TEST.md for detailed testing instructions.
Tests in the CI
In PR #38565, we've added a new warning in a unit test and a new warning in an integration test to prove that CI fails in such cases.
Screenshots/Recordings
Baseline Enforcement - Pass
Baseline Enforcement - Violation Detected
Baseline Update
Pre-merge author checklist
Pre-merge reviewer checklist
Note
Adds a custom Jest reporter and baselines to enforce no new console warnings/errors, with scripts, config updates, and docs.
test/jest/console-baseline-reporter.jsto capture/enforce per-file console baselines (unit/integration).test/jest/console-categorizer.jsusing existing console reporter rules.test/jest/console-baseline-unit.jsonandtest/jest/console-baseline-integration.json.jest.config.jsandjest.integration.config.js.verbose: falseto buffer console output for reporters.package.json):test:unit:update-baselineandtest:integration:update-baseline(useUPDATE_BASELINE=true)..github/workflows/run-tests.yml):yarn test:integration:coveragewithout--silentand upload coverage artifact.test/jest/CONSOLE-BASELINE.mdandtest/jest/CONSOLE-BASELINE-TEST.mdwith usage and manual testing steps.Written by Cursor Bugbot for commit 09986f3. This will update automatically on new commits. Configure here.