test: Bridge expand component view tests coverage - Metamask Issues#25908
test: Bridge expand component view tests coverage - Metamask Issues#25908
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. |
12174f0 to
f162e18
Compare
Co-authored-by: Ramon AC <racitores@users.noreply.github.com>
Co-authored-by: Ramon AC <racitores@users.noreply.github.com>
Co-authored-by: Ramon AC <racitores@users.noreply.github.com>
Co-authored-by: Ramon AC <racitores@users.noreply.github.com>
Co-authored-by: Ramon AC <racitores@users.noreply.github.com>
Co-authored-by: Ramon AC <racitores@users.noreply.github.com>
20fc88a to
d222d3c
Compare
|
Hey @racitores can we add a description on what we are accomplishing regarding the ci.yml changes and the new scripts on the package json? Also I see that the new report do not have only coverage by component but also redux Let me know your thoughts |
Matt561
left a comment
There was a problem hiding this comment.
Approving for the Earn file change 👍
I'll update the description, thanks for the feedback 👍 In regards the new merge of component view tests and unit tests coverage, you are right. They are merged to compute together for sonarcloud metrics. I'll update the step accordingly |
🔍 Smart E2E Test Selection
click to see 🤖 AI reasoning detailsE2E Test Selection:
None of these changes affect:
The changes are isolated to Jest-based component-view testing infrastructure, which runs separately from Detox E2E tests. No E2E tags are needed. Performance Test Selection: |
| const { getByTestId, queryByTestId } = defaultBridgeWithTokens({ | ||
| bridge: { | ||
| sourceAmount: '100', | ||
| sourceToken: USDC_DEST, |
There was a problem hiding this comment.
Destination constant USDC_DEST used as source token
Low Severity
The USDC_DEST constant, explicitly documented as "USDC (mainnet) token used as default destination in Bridge view tests," is used here as sourceToken. While the token metadata is direction-agnostic so the test functions correctly, the naming actively contradicts its usage, which is confusing for future maintainers. A direction-neutral name like USDC_TOKEN or a separate USDC_SOURCE constant would better express intent.
Additional Locations (1)
|





This PR adds improved test scripts, CI optimizations and test coverage.
Test Updates
BridgeView Tests: Added issue regression test coverage and created
bridgeViewTestConstants.tswith reusable test constants (ETH_SOURCE, USDC_DEST, DEFAULT_BRIDGE).MusdConversionAssetListCta Tests: Updated to use
describeForPlatformsand improved test setup with proper version-gated feature flags and fiatOrders state handling.New Test Scripts (
package.json)test:view:base: New base script providing a common foundation for all component-view test commands. Runs Jest with view config, in-band execution, and silent output by default.test:view: Refactored to usetest:view:basewith coverage disabled and test path pattern matching.test:view:one: New script for running a single component-view test file with verbose output and extended timeout (30s). Useful for debugging individual test files.test:view:coverage: New script for running all component-view tests with coverage reporting enabled.test:view:coverage:folder: New script for generating coverage reports for tests in a specific folder. Accepts a folder path as an argument and generates both text-summary and lcov coverage reports.test:view:ci: New script optimized for CI environments. Runs tests with iOS platform targeting, coverage reporting in JSON format, and force exit for clean CI runs. Supports sharding via--shardparameter.Jest Configuration (
jest.config.view.js)testTimeout: 30000for longer-running component-view testsforceExit: trueto ensure clean test executionmaxWorkers: 1to prevent race conditions in component-view testsCI/CD Improvements (
.github/workflows/ci.yml)test:view:ciscript with shard support (--shard=${{ matrix.shard }}/2)Testing Framework Enhancements
stateFixture.ts: AddedwithMinimalTokensController()method to properly initialize TokensController state for tests that depend on token data (e.g., BridgeTokenSelector, useTokensWithBalance). Supports multiple chainIds (defaults to mainnet '0x1').mocks.ts: Added BridgeController mocks (updateBridgeQuoteRequestParams,resetState,stopAllPolling) to support Bridge component testing.presets/bridge.ts: UpdatedinitialStateBridgepreset to includewithMinimalTokensController()for proper token state initialization.Documentation Updates
COMPONENT_VIEW_TEST_RULES.md: Added guidance to avoid fake timers (jest.useFakeTimers,jest.advanceTimersByTime,jest.useRealTimers) in component-view tests.component-view-testing.mdc: Updated rules to mention the no fake timers policy.tests/AGENTS.md: Updated documentation to reference the no fake timers guidance for component-view tests.Note
Medium Risk
Medium risk because CI workflow and Jest configuration changes can affect test stability/coverage reporting and potentially increase flakiness or runtime if sharding/merging is misconfigured, though production code paths are not modified.
Overview
Component-view tests now run faster and integrate into overall coverage. CI renames the component-view job to
cv-test, runs it in 2 shards, uploads per-shard JSON coverage, generates a merged HTML coverage artifact, and merges component-view coverage with unit-test coverage before Sonar.Component-view test infrastructure is hardened.
jest.config.view.jsadds a 30s timeout,forceExit, andmaxWorkers: 1;package.jsonintroduces a set oftest:view:*scripts including a CI-optimized runner.Bridge/Earn component-view coverage is expanded and made more deterministic.
BridgeView.view.test.tsxis refactored with shared token constants and adds regression tests (gas-included label, custom slippage propagation, token search returning duplicates, native-token display, no-crash/CTA visibility without quotes); the state fixture/preset is extended withwithMinimalTokensController()and Engine mocks addBridgeController.updateBridgeQuoteRequestParams. Earn CTA tests are updated to use version-gated flag shapes and stablefiatOrdersstate.Testing guidance is updated/enforced. Component-view rules now always apply and explicitly prohibit Jest fake timers (documented in both rule docs and
tests/AGENTS.md).Written by Cursor Bugbot for commit 09e104d. This will update automatically on new commits. Configure here.