Fix Yarn PnP ESM incompatibility and test code issues blocking test execution#15
Fix Yarn PnP ESM incompatibility and test code issues blocking test execution#15vothanhdat merged 17 commits intomasterfrom
Conversation
- Add Vitest, React Testing Library, and jsdom dependencies - Create vitest.config.test.ts with coverage settings - Add test setup with automatic cleanup - Implement 26 passing tests for core Context system - Add tests for ctx.ts (20 tests) covering: - Context class publish/subscribe - getContext memoization - useDataContext, useDataSource, useDataSubscribe hooks - Debouncing and multiple subscriptions - Add tests for createRootCtx.tsx (6 tests) covering: - Root component creation and data provision - Context name derivation from props - useCtxState and useCtxStateStrict hooks - Create test utilities and comprehensive documentation - Update package.json with test scripts - Add coverage and .vitest to .gitignore All 26 tests passing ✅
- Test on Node 18.x and 20.x - Run on push to master and setup-testing branches - Run on pull requests to master - Generate and upload coverage report to Codecov - Use Yarn with Corepack
- Add createAutoCtx.test.tsx (12 tests) covering: - AutoRootCtx component rendering and lifecycle - Multiple subscribers with same/different params - Reference counting and cleanup with delays - Rapid mount/unmount cycles - Error boundary wrapping - State updates after auto-mounting - Add useArrayHash.test.ts (11 tests) covering: - Hash generation and stability - Array change detection (length, elements, references) - Object and nested array handling - Large array performance - Mixed type handling - Add useQuickSubscribe.test.ts (11 tests) covering: - Proxy-based selective subscription - Re-render only on accessed property changes - Dynamic property access - Object and array values - Multiple properties in same render - Memory leak prevention - Destructuring support Total: 34 new tests (50/60 passing, 10 edge cases to fix) Work in progress on edge case handling
- Update test statistics: 50/60 tests passing (83%) - Document new test files for auto context and utility hooks - Mark phase 2 as implemented with edge cases noted - Update current test status section
…ocumentation and tests
…ills and improve Vitest configuration
…tate-custom into copilot/fix-test-flow-setup
- Add .yarnrc.yml to use node-modules linker instead of PnP for better test compatibility - Change vitest pool from 'threads' to 'forks' for better ESM support - Increase test timeouts from 500ms to 10000ms globally - Fix individual test timeouts in createAutoCtx.test.tsx from 1000ms to 10000ms 55 out of 60 tests now pass. The 5 failing tests in createAutoCtx.test.tsx appear to have pre-existing issues with async behavior and waitFor timeouts. Co-authored-by: vothanhdat <8221386+vothanhdat@users.noreply.github.com>
Extended waitFor timeouts from 100ms to 5000ms to allow more time for async operations. Note: 5 tests still fail with full 10-second timeout, suggesting deeper issues with test logic rather than timing. Co-authored-by: vothanhdat <8221386+vothanhdat@users.noreply.github.com>
Document the problem, solution, and results of fixing the Yarn PnP ESM compatibility issue that prevented tests from running. Co-authored-by: vothanhdat <8221386+vothanhdat@users.noreply.github.com>
Set contents: read permission to follow GitHub security best practices and restrict GITHUB_TOKEN scope. Co-authored-by: vothanhdat <8221386+vothanhdat@users.noreply.github.com>
Changed imports from './devTool.css' to './DevTool.css' to match actual filename. This was preventing the build from succeeding. Co-authored-by: vothanhdat <8221386+vothanhdat@users.noreply.github.com>
|
- Fix renderCount scope issue in 'share instances' test by moving variable outside hook - Add vi.useRealTimers()/vi.useFakeTimers() wrapping around waitFor calls - Replace vi.advanceTimersByTime() with real async delays in cleanup tests - All 60 tests now pass (100% success rate) The issue was that fake timers prevented waitFor's internal polling from working. Tests now temporarily switch to real timers during async assertions. Co-authored-by: vothanhdat <8221386+vothanhdat@users.noreply.github.com>
Documented the complete solution including both infrastructure fixes and test code fixes. Co-authored-by: vothanhdat <8221386+vothanhdat@users.noreply.github.com>
Fixed all remaining test cases! All 60 tests now pass (100%). The 5 failing tests had two issues:
Commits: Build passes ✅, security check passes ✅, all tests pass ✅ |
There was a problem hiding this comment.
Pull Request Overview
This PR resolves test execution failures by addressing Yarn PnP's ESM incompatibility and fixing timing issues in test code. The changes enable all 60 tests to run and pass successfully.
Key Changes:
- Switched from Yarn PnP to traditional
node_modulesto resolve ESM module resolution errors - Adjusted Vitest configuration for better ESM compatibility and increased timeouts
- Fixed fake timer conflicts with async test assertions in
createAutoCtxtests - Corrected CSS import casing and renamed utility hook for consistency
Reviewed Changes
Copilot reviewed 23 out of 25 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
.yarnrc.yml |
Configures traditional node_modules linker to fix ESM resolution |
vitest.config.test.ts |
Sets up test environment with forks pool and extended timeouts |
tests/createAutoCtx.test.tsx |
Fixes timer conflicts by switching between real/fake timers during assertions |
tests/setup.ts, tests/utils.ts, tests/ctx.test.ts, tests/createRootCtx.test.tsx, tests/useQuickSubscribe.test.ts, tests/useArrayChangeId.test.ts |
New comprehensive test suite with proper cleanup |
src/state-utils/useArrayChangeId.ts |
Renamed from useArrayHash with improved documentation |
src/state-utils/ctx.ts |
Updates import and removes debug logging |
src/index.ts, API_DOCUMENTATION.md, .github/copilot-instructions.md |
Updates references to renamed hook |
src/dev-tool/*.tsx |
Fixes CSS import case sensitivity |
package.json |
Adds test scripts and testing dependencies |
.github/workflows/test.yml |
New CI workflow for automated testing |
| test: { | ||
| globals: true, | ||
| environment: 'jsdom', | ||
| setupFiles: ['./tests/setup.ts'], |
There was a problem hiding this comment.
The 10-second timeouts are significantly higher than typical test timeouts. While necessary for the current async operations, consider documenting why such long timeouts are required or optimizing test operations to reduce these values.
| setupFiles: ['./tests/setup.ts'], | |
| setupFiles: ['./tests/setup.ts'], | |
| // The following timeouts (10 seconds) are intentionally set higher than typical defaults. | |
| // This is necessary to accommodate slow async operations and environment setup delays | |
| // caused by jsdom initialization, Yarn PnP compatibility, and the use of the forks pool. | |
| // If test performance improves, consider reducing these values. |
There was a problem hiding this comment.
Optimized timeouts from 10s to 5s. Tests complete in ~2.5s, so 5s provides a 2x safety margin while being significantly faster than 10s.
Commit: e97fdbe
- Reduce global test timeouts from 10s to 5s (tests complete in ~2.5s) - Reduce individual test timeouts from 10s to 5s - Add withRealTimers() helper in tests/utils.ts to eliminate code duplication - Refactor all 5 tests using vi.useRealTimers/useFakeTimers to use the helper This addresses reviewer feedback to optimize timeouts and reduce duplication. Co-authored-by: vothanhdat <8221386+vothanhdat@users.noreply.github.com>
Summary
Successfully fixed ALL test issues and optimized the solution based on reviewer feedback!
Phase 1 - Infrastructure Fix:
Phase 2 - Test Code Fix:
Phase 3 - Optimization:
withRealTimers()helper to eliminate duplicationSee
TEST_FLOW_FIX_SUMMARY.mdfor complete technical details.Original prompt
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.