feat: implement Jest testing infrastructure and add initial unit test… - #83
Conversation
…s for wallet hooks and API endpoints.
|
@ABEEGOLD is attempting to deploy a commit to the Meshack Yaro's projects Team on Vercel. A member of the Team first needs to authorize it. |
The critical blocker is the missing testPathIgnorePatterns in jest.config.js. File: jest.config.js The jest.config.js is missing testPathIgnorePatterns, which is causing Jest to pick up compiled test files from .next/ during CI runs. This is why the test suite fails with errors like "Page /api/profile.test does not export a default function." Please update the config to: module.exports = { This ensures Jest only runs against your source test files (.test.ts in hooks/ and pages/api/) and ignores Next.js's build output. Why this matters: The CI is currently failing because Next.js compiles the source test files into Scope: General — test timing stability The useWallet.test.ts tests are triggering React warnings about state updates not wrapped in act(). While the tests currently pass, this indicates the async polling behavior may be tightly coupled to test timing.
Consider either:
1. Explicitly managing timers in the waitFor() callback, or
2. Using waitFor with an explicit timeout that aligns with the polling interval in useWallet.ts
This will eliminate the console warnings and make the tests more resilient to timing changes.
**Why this matters:** These warnings are usually harmless in passing tests, but they signal that the test is racing with asynchronous state updates. As the hook or polling logic evolves, this could become flaky. Addressing it now keeps the test suite stable and prevents future CI intermittency.
Overall Assessment:
- Code Quality: High — mocks are well-structured, tests are meaningful, configuration is sound
- Test Coverage: Excellent (>94% on target files as stated)
- Risk Level: Low on code, High on CI readiness (must be fixed before merge)
- Blocking Issue: Jest configuration must exclude .next/ directory and any other compiled output from test runs
- jest.config.js is missing testPathIgnorePatterns: Add a pattern to exclude .next/ and node_modules/ so compiled Next.js output isn't picked up by Jest. This is the direct cause of the CI failures. Update line 1–11 to include:
testPathIgnorePatterns: ['<rootDir>/.next/', '<rootDir>/node_modules/'],
- Possible race condition in useWallet polling test: The fake timer tests wrap state updates in act(), but polling may occur outside the test's control. Consider explicitly advancing timers in waitFor() callbacks or ensuring the polling interval aligns with manual timer advances to eliminate the console warnings.
Possible Improvements
- Document the mocking pattern in a testing guide: While the mock files include inline comments, a dedicated TESTING.md or docs/testing.md would help future contributors quickly understand how to use the Freighter and Soroban RPC mocks for new features. Reference it from the PR description or README.
- Add a .test. pattern to .eslintignore or similar: If not already present, test files should be excluded from strict linting rules that might apply to production code (e.g., no-unused-vars for test helpers).
- Consider snapshot tests for API response schemas: The profile and USDC price API tests are solid, but adding snapshot tests for the mock fallback payloads would catch unintended changes to the contract shape over time. |
…ts, and document testing guidelines
|
Hi @ABEEGOLD — thank you for this excellent and thorough contribution! This PR sets up a robust Jest + React Testing Library environment for our Next.js + TypeScript frontend, and you've gone above and beyond by providing reusable mocks for Freighter and Soroban RPC, comprehensive unit tests for critical hooks and API routes (notably useWallet, useAccount, profile and usdc-price), and wiring tests into CI. The documentation inside the mocks is helpful and the npm scripts make running tests straightforward. A couple of small, optional suggestions:
Overall this is a high-quality, well-documented change that materially improves our developer experience and confidence in on-chain/wallet-dependent code. Great work — approved once CI is green! |
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Closes #82