-
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
Open
gauthierpetetin
wants to merge
12
commits into
feat/jest-clean-console-reporter
Choose a base branch
from
feat/jest-custom-console-reporter
base: feat/jest-clean-console-reporter
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
af13477
feat: add custom jest reporter to prevent introduction of new warning…
gauthierpetetin b33cd23
Merge branch 'feat/jest-clean-console-reporter' into feat/jest-custom…
gauthierpetetin e27f47e
fix: linting errors
gauthierpetetin 4442517
CI was not failing when baseline violations were detected
gauthierpetetin 805f210
Update baselines after syncing with main branch
gauthierpetetin f40af78
fix linting issues
gauthierpetetin 4570699
Remove summary and update unit test baseline
gauthierpetetin 1332229
Stop using prettier as it was not working
gauthierpetetin ae9ffee
Update unit test baseline
gauthierpetetin 026d725
Update unit test baseline
gauthierpetetin 724bbac
No longer silence integration test warnings
gauthierpetetin 09986f3
Update unit test baseline
gauthierpetetin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,196 @@ | ||
| # Console Baseline Reporter - Manual Testing Steps | ||
|
|
||
| ## Prerequisites | ||
|
|
||
| - Node.js v24+ | ||
| - Run `yarn install` | ||
|
|
||
| --- | ||
|
|
||
| ## Test 1: Unit Test Warning Detection | ||
|
|
||
| ### 1. Add a test warning to a unit test | ||
|
|
||
| Add this code to `app/scripts/controllers/permissions/background-api.test.js` at the top of the first `describe` block: | ||
|
|
||
| ```javascript | ||
| describe('permission background API methods', () => { | ||
| beforeEach(() => { | ||
| // Test warning to verify baseline system | ||
| console.warn( | ||
| 'REVIEWER_TEST: This warning should be detected by the baseline system', | ||
| ); | ||
| }); | ||
|
|
||
| // ... rest of the tests | ||
| }); | ||
| ``` | ||
|
|
||
| ### 2. Run the unit test - should FAIL with the new warning | ||
|
|
||
| ```bash | ||
| yarn test:unit app/scripts/controllers/permissions/background-api.test.js | ||
| ``` | ||
|
|
||
| **Expected output:** | ||
|
|
||
| ``` | ||
| PASS app/scripts/controllers/permissions/background-api.test.js | ||
|
|
||
| Test Suites: 1 passed, 1 total | ||
| Tests: 45 passed, 45 total | ||
| ... | ||
|
|
||
| ❌ BASELINE VIOLATIONS DETECTED | ||
|
|
||
| 📁 app/scripts/controllers/permissions/background-api.test.js | ||
| 🆕 NEW: warn: REVIEWER_TEST: This warning should | ||
| Current: 45 occurrences | ||
|
|
||
| 💡 Next steps: | ||
| 1. Fix the warnings in your code, OR | ||
| 2. Update baseline: yarn test:unit:update-baseline (requires justification) | ||
| ``` | ||
|
|
||
| **Note:** Jest shows "Test Suites: 1 passed" but the command **fails** (exit code 1) due to the baseline violation. | ||
|
|
||
| ### 3. Add the warning to the baseline | ||
|
|
||
| ```bash | ||
| yarn test:unit:update-baseline app/scripts/controllers/permissions/background-api.test.js | ||
| ``` | ||
|
|
||
| **Expected output:** | ||
|
|
||
| ``` | ||
| PASS app/scripts/controllers/permissions/background-api.test.js | ||
|
|
||
| ✅ Baseline updated: 1 file(s) updated, 495 total in baseline | ||
| Written to: /path/to/test/jest/console-baseline-unit.json | ||
| ``` | ||
|
|
||
| ### 4. Re-run the test - should PASS | ||
|
|
||
| ```bash | ||
| yarn test:unit app/scripts/controllers/permissions/background-api.test.js | ||
| ``` | ||
|
|
||
| **Expected output:** | ||
|
|
||
| ``` | ||
| PASS app/scripts/controllers/permissions/background-api.test.js | ||
|
|
||
| ✅ Console baseline matches exactly! | ||
| ``` | ||
|
|
||
| ✅ **System verified!** The warning is now in the baseline and the test passes. | ||
|
|
||
| ### 5. Clean up | ||
|
|
||
| Remove the test warning from `app/scripts/controllers/permissions/background-api.test.js`: | ||
|
|
||
| ```javascript | ||
| describe('permission background API methods', () => { | ||
| // DELETE the beforeEach block with the REVIEWER_TEST warning | ||
| // ... rest of the tests | ||
| }); | ||
| ``` | ||
|
|
||
| Then update the baseline to remove it: | ||
|
|
||
| ```bash | ||
| yarn test:unit:update-baseline app/scripts/controllers/permissions/background-api.test.js | ||
| ``` | ||
|
|
||
| Verify tests still pass: | ||
|
|
||
| ```bash | ||
| yarn test:unit app/scripts/controllers/permissions/background-api.test.js | ||
| ``` | ||
|
|
||
| --- | ||
|
|
||
| ## Test 2: Integration Test Warning Detection | ||
|
|
||
| ### 1. Add a test warning to an integration test | ||
|
|
||
| Add this code to `test/integration/confirmations/signatures/permit.test.tsx` at the top of the first `describe` block: | ||
|
|
||
| ```typescript | ||
| describe('Permit Confirmation', () => { | ||
| beforeEach(() => { | ||
| // Test warning to verify baseline system | ||
| console.warn( | ||
| 'REVIEWER_TEST: This warning should be detected by the baseline system', | ||
| ); | ||
| }); | ||
|
|
||
| // ... rest of the tests | ||
| }); | ||
| ``` | ||
|
|
||
| ### 2. Run the integration test - should FAIL with the new warning | ||
|
|
||
| ```bash | ||
| yarn test:integration test/integration/confirmations/signatures/permit.test.tsx | ||
| ``` | ||
|
|
||
| **Expected output:** | ||
|
|
||
| ``` | ||
| PASS test/integration/confirmations/signatures/permit.test.tsx | ||
| ... | ||
|
|
||
| ❌ BASELINE VIOLATIONS DETECTED | ||
|
|
||
| 📁 test/integration/confirmations/signatures/permit.test.tsx | ||
| 🆕 NEW: warn: REVIEWER_TEST: This warning should | ||
| Current: X occurrences | ||
|
|
||
| 💡 Next steps: | ||
| 1. Fix the warnings in your code, OR | ||
| 2. Update baseline: yarn test:integration:update-baseline (requires justification) | ||
| ``` | ||
|
|
||
| ### 3. Add the warning to the baseline | ||
|
|
||
| ```bash | ||
| yarn test:integration:update-baseline test/integration/confirmations/signatures/permit.test.tsx | ||
| ``` | ||
|
|
||
| ### 4. Re-run the test - should PASS | ||
|
|
||
| ```bash | ||
| yarn test:integration test/integration/confirmations/signatures/permit.test.tsx | ||
| ``` | ||
|
|
||
| **Expected output:** | ||
|
|
||
| ``` | ||
| ✅ Console baseline matches exactly! | ||
| ``` | ||
|
|
||
| ✅ **System verified!** | ||
|
|
||
| ### 5. Clean up | ||
|
|
||
| Remove the test warning from `test/integration/confirmations/signatures/permit.test.tsx` and update baseline: | ||
|
|
||
| ```bash | ||
| yarn test:integration:update-baseline test/integration/confirmations/signatures/permit.test.tsx | ||
| ``` | ||
|
|
||
| --- | ||
|
|
||
| ## Summary | ||
|
|
||
| All test types follow the same pattern: | ||
|
|
||
| | Step | Action | Result | | ||
| | ---- | --------------- | --------------------- | | ||
| | 1 | Add warning | ❌ Test fails | | ||
| | 2 | Update baseline | Warning added to JSON | | ||
| | 3 | Re-run test | ✅ Test passes | | ||
| | 4 | Clean up | Remove test code | | ||
|
|
||
| This demonstrates the baseline system correctly detects, stores, and validates console warnings! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,88 @@ | ||
| # Console Baseline Enforcement | ||
|
|
||
| Prevents new console warnings/errors from being introduced. Baseline is tracked **per test file**. | ||
|
|
||
| ## Quick Reference | ||
|
|
||
| | Command | Description | | ||
| | ---------------------------------------------------- | -------------------------------------- | | ||
| | `yarn test:unit` | Run tests with baseline enforcement | | ||
| | `yarn test:unit:update-baseline` | Update baseline (all files) | | ||
| | `yarn test:unit:update-baseline path/to/file` | Update baseline (single file) | | ||
| | `yarn test:integration` | Run integration tests with enforcement | | ||
| | `yarn test:integration:update-baseline` | Update integration baseline | | ||
| | `yarn test:integration:update-baseline path/to/file` | Update baseline (single file) | | ||
|
|
||
| ## How It Works | ||
|
|
||
| 1. **Run tests** → Reporter compares console output against baseline | ||
| 2. **Violation detected** → Test fails, shows which file/category increased | ||
| 3. **Improvement detected** → Shows reduced warnings (doesn't fail) | ||
| 4. **Update baseline** → Run with `:update-baseline` to accept changes | ||
|
|
||
| ## Example Output | ||
|
|
||
| ``` | ||
| ❌ BASELINE VIOLATIONS DETECTED | ||
|
|
||
| 📁 ui/pages/send/send.test.tsx | ||
| ⬆️ React: Act warnings | ||
| Baseline: 5, Current: 12 (+7) | ||
|
|
||
| 💡 Next steps: | ||
| 1. Fix the warnings in your code, OR | ||
| 2. Update baseline: yarn test:unit:update-baseline (requires justification) | ||
| ``` | ||
|
|
||
| ## Workflow | ||
|
|
||
| ```bash | ||
| # 1. Run tests (fails if warnings increased) | ||
| yarn test:unit path/to/my-component.test.tsx | ||
|
|
||
| # 2. Fix warnings in code, OR update baseline if justified | ||
| yarn test:unit:update-baseline path/to/my-component.test.tsx | ||
|
|
||
| # 3. Commit baseline changes | ||
| git add test/jest/console-baseline-*.json | ||
| git commit -m "fix: reduce warnings in my-component" | ||
| ``` | ||
|
|
||
| ## Configuration | ||
|
|
||
| In `jest.config.js`: | ||
|
|
||
| ```javascript | ||
| reporters: [ | ||
| [ | ||
| '<rootDir>/test/jest/console-baseline-reporter.js', | ||
| { | ||
| testType: 'unit', // 'unit' or 'integration' | ||
| failOnViolation: true, // Fail on increased warnings | ||
| showImprovements: true, // Show reduced warnings | ||
| }, | ||
| ], | ||
| ]; | ||
| ``` | ||
|
|
||
| ## Baseline Files | ||
|
|
||
| - `test/jest/console-baseline-unit.json` - Unit test baseline | ||
| - `test/jest/console-baseline-integration.json` - Integration test baseline | ||
|
|
||
| Structure: | ||
|
|
||
| ```json | ||
| { | ||
| "files": { | ||
| "path/to/test.tsx": { | ||
| "React: Act warnings": 5, | ||
| "MetaMask: Background connection not initialized": 2 | ||
| } | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| ## Related Documentation | ||
|
|
||
| - [Manual Testing Guide](./CONSOLE-BASELINE-TEST.md) - Step-by-step verification instructions |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
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
--silentflag to be able to detect new warnings/errors