-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
test: Add component view test framework #22265
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: main
Are you sure you want to change the base?
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. |
44f8f09 to
464984b
Compare
| } catch (_e) { | ||
| // Best-effort guard; if state is not available yet, skip enforcement | ||
| } | ||
| return Reflect.apply(target, thisArg, args); |
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: Silent Error Suppression Breaks Runtime Guard
The runtime guard's error handling silently suppresses the intentional error thrown for forbidden mocks. The catch (_e) block catches both the expected "state not available" errors and the intentional "Forbidden jest.mock" errors, making the guard ineffective. The forbidden mock error should be re-thrown after being caught, or the try-catch should only wrap the state retrieval logic.
package.json
Outdated
| "test": "yarn test:unit", | ||
| "test:unit": "jest ./app/ ./locales/ ./e2e/**/*.test.ts .github/**/*.test.ts", | ||
| "test:unit": "jest ./app/ ./locales/ ./e2e/**/*.test.ts .github/**/*.test.ts --testPathIgnorePatterns='.*\\.integration(\\..*)?\\.test\\.(ts|tsx)$'", | ||
| "test:integration": "jest --runInBand --no-watchman --verbose --testPathPattern='.*\\.integration(\\..*)?\\.test\\.(ts|tsx)$'", |
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: Align Test Patterns with Supported File Types
The test script patterns only match .ts and .tsx files but the ESLint rules, documentation, and Cursor rules all specify support for .js and .jsx integration tests as well. The testPathIgnorePatterns and testPathPattern regexes should include (ts|tsx|js|jsx) instead of just (ts|tsx) to match the documented behavior and ESLint configuration.
7009fb7 to
94c3a78
Compare
| return Reflect.apply(target, thisArg, args); | ||
| }, | ||
| }); | ||
| })(); |
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: Silent Error Catch Undermines Mock Security
The runtime guard wraps jest.mock in a Proxy but catches and silently ignores all errors in the try-catch block at line 154. This means if global.expect?.getState?.() throws an error (not just returns undefined), the guard fails silently and allows unauthorized mocks through. The catch should only suppress errors when state is unavailable, not all errors including the intentional throw new Error at line 145 that enforces the whitelist.
| return Reflect.apply(target, thisArg, args); | ||
| }, | ||
| }); | ||
| })(); |
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: Guard's Silent Catch Undermines Enforcement
The runtime guard's catch block silently swallows all errors, including the enforcement error itself. When jest.mock is called with a forbidden module in an integration test, the thrown error gets caught and ignored, defeating the guard's purpose. The catch should only suppress errors from accessing expect.getState(), not from the enforcement logic.
package.json
Outdated
| "release:android:qa": "./scripts/build.sh android QA && open android/app/build/outputs/apk/release/", | ||
| "test": "yarn test:unit", | ||
| "test:unit": "jest ./app/ ./locales/ ./e2e/**/*.test.ts .github/**/*.test.ts", | ||
| "test:unit": "jest ./app/ ./locales/ ./e2e/**/*.test.ts .github/**/*.test.ts --testPathIgnorePatterns='.*\\.integration(\\..*)?\\.test\\.(ts|tsx)$'", |
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: CLI flags break Jest test path exclusion.
The --testPathIgnorePatterns CLI flag in test:unit overrides the testPathIgnorePatterns array in jest.config.js, causing unit tests to no longer ignore e2e specs, pages, and selectors. Jest CLI arguments replace rather than merge with config file settings, so the patterns for e2e files ('.*/e2e/specs/.*\\.spec\\.(ts|js)$', '.*/e2e/pages/', '.*/e2e/selectors/') are lost.
7c6dd34 to
2b4b451
Compare
| const testPath = state?.testPath ?? ''; | ||
| const isComponentViewTest = /\.[iI]view(\..*)?\.test\.(t|j)sx?$/.test( | ||
| testPath, | ||
| ); |
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: Case-Insensitive Regex Fails View Enforcement
The regex pattern /\.[iI]view(\..*)?\.test\.(t|j)sx?$/ uses [iI] which matches both lowercase i and uppercase I, but the intended pattern is .view (with lowercase v). This causes the guard to match files like .iview.test.ts or .Iview.test.ts instead of the documented .view.test.ts pattern, failing to enforce mocking restrictions on actual component-view test files.
| "test": "yarn test:unit", | ||
| "test:unit": "jest ./app/ ./locales/ ./e2e/**/*.test.ts .github/**/*.test.ts", | ||
| "test:unit": "jest ./app/ ./locales/ ./e2e/**/*.test.ts .github/**/*.test.ts --testPathIgnorePatterns='.*/e2e/specs/.*\\.spec\\.(ts|tsx|js)$|.*\\.view(\\..*)?\\.test\\.(ts|tsx)$'", | ||
| "test:view": "jest --runInBand --no-watchman --verbose --testPathPattern='.*\\.view(\\..*)?\\.test\\.(ts|tsx)$'", |
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: JS/JSX test files lack proper isolation.
The test patterns in test:unit and test:view only match .ts and .tsx files via (ts|tsx), but documentation and ESLint rules specify support for .js and .jsx files as well (*.view.test.{ts,tsx,js,jsx}). This causes .view.test.js and .view.test.jsx files to run in unit tests instead of being properly isolated.
| // Expect state is available when evaluating test files | ||
| const state = global.expect?.getState?.(); | ||
| const testPath = state?.testPath ?? ''; | ||
| const isComponentViewTest = /\.[iI]view(\..*)?\.test\.(t|j)sx?$/.test( |
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: Unauthorized Mocks Infiltrate View Tests
The regex pattern /\.[iI]view(\..*)?\.test\.(t|j)sx?$/ matches files with .iview or .Iview but not .view (lowercase 'v'). The actual test files use .view.test.tsx naming. This prevents the runtime guard from enforcing mock restrictions in component-view tests, allowing unauthorized mocks that should be blocked.
|
🔍 Smart E2E Test Selection
click to see 🤖 AI reasoning detailsAfter thorough analysis of all 20 changed files, I conclude that NO E2E test tags need to be run: Analysis Summary:
Key Findings:
Why No E2E Tags:
Risk Assessment: LOW
|
| // Expect state is available when evaluating test files | ||
| const state = global.expect?.getState?.(); | ||
| const testPath = state?.testPath ?? ''; | ||
| const isComponentViewTest = /\.[iI]view(\..*)?\.test\.(t|j)sx?$/.test( |
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: Security Guard's Blind Spot
The runtime guard regex /\.[iI]view(\..*)?\.test\.(t|j)sx?$/ expects files matching .iview.test.* or .Iview.test.*, but the actual component-view test files follow the pattern .view.test.* (lowercase 'v' without 'i' prefix). The regex [iI]view matches only iview or Iview, not view. This causes the runtime enforcement to never trigger for component-view tests, allowing unauthorized mocks that should be blocked.
cortisiko
left a comment
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.
left a few comments related to using TestIDs. otherwise it looks good @racitores
| }); | ||
|
|
||
| // Type 9.5 using keypad buttons | ||
| const scroll = getByTestId('bridge-view-scroll'); |
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.
Can we, similar to the e2e tests use the testIDs defined in the testID object? this way we have a consistent way of storing and using testIDs within e2e and integration tests? In this case, we can import selector string here and use it
|
|
||
| // Ensure keypad is visible | ||
| await waitFor(() => { | ||
| expect(queryByTestId('keypad-delete-button')).toBeTruthy(); |
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.
| }); | ||
|
|
||
| // Close possible banner to reveal keypad | ||
| const closeBanner = queryByTestId('banner-close-button-icon'); |
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.



Description
Introduces a Component-view testing framework with engine-only mocks, state-driven presets, and deterministic rendering helpers to speed up view-level tests without full E2E.
Adds initial tests for BridgeView and Wallet views leveraging presets and renderers.
Updates CI workflow to run component-view tests reliably across OS, and minor ESLint/test setup adjustments.
Adds local rules and documentation for Component-view tests.
Changelog
CHANGELOG entry:
Related issues
Fixes:
Manual testing steps
Screenshots/Recordings
Before
After
Pre-merge author checklist
Pre-merge reviewer checklist
Note
Introduces a component-view testing framework with mocks/presets/renderers, adds BridgeView and Wallet tests, and updates CI and test setup.
app/util/test/component-view/(mocks,render.tsx, state fixtures, presets, and view-specific renderers for Bridge and Wallet).BridgeViewandWalletinapp/components/UI/Bridge/Views/BridgeView/BridgeView.view.test.tsxandapp/components/Views/Wallet/Wallet.view.test.tsx..cursor/rules/*,INTEGRATION_TEST_RULES.md,README.md).ci.ymlto run component-view tests across environments.app/util/test/testSetup.jsand platform helpers.package.jsonandeslintrc.jsto support the new tests.Written by Cursor Bugbot for commit 74b633a. This will update automatically on new commits. Configure here.