feat(esm): Add vitest plugins and config to packages/testing#355
Conversation
✅ Deploy Preview for cedarjs canceled.
|
There was a problem hiding this comment.
Greptile Summary
This PR adds comprehensive Vitest support to the CedarJS testing framework as part of ESM preparation work. The changes introduce new Vite plugins and configurations that enable testing with Vitest alongside the existing Jest support.
The core additions include:
API Testing Infrastructure: New vitest plugins in packages/testing/src/api/vitest/ that handle auto-imports of testing utilities, database import tracking, and API-specific configuration. A custom Vitest environment (CedarApiVitestEnv.ts) manages database setup, migrations, and test isolation. The setup file (vitest-api.setup.ts) provides comprehensive testing infrastructure including context mocking, database teardown, and scenario management.
Web Testing Infrastructure: New plugins in packages/testing/src/web/vitest/ that transform imports during testing - replacing router imports with MockRouter and auth imports with mocked versions. An auto-import plugin eliminates boilerplate by automatically injecting common testing utilities. A new globRoutesImporter.ts uses Vite's import.meta.glob to dynamically discover user routes at test runtime.
Dual Testing Framework Support: The MockProviders component now supports both Jest (using existing CommonJS require patterns) and Vitest (using new ESM import.meta.glob patterns). The MockRouter documentation clarifies how mocking works differently in each framework.
Build System Updates: TypeScript project references added to ensure proper build ordering between packages. The testing package's build process updated to handle ESM-only vitest exports while maintaining dual ESM/CJS support for other utilities. New package.json exports provide dedicated entry points for vitest functionality.
Integration: The main vite plugin conditionally applies testing plugins when mode === 'test', and the merged config supports Vitest with jsdom environment and proper SSR handling for the testing package.
This architecture maintains full backward compatibility with Jest while enabling modern Vitest testing, supporting the framework's transition to ESM-first development.
Confidence score: 3/5
- This PR introduces significant complexity across multiple packages with some concerning implementation details that could cause production issues
- Score reflects potential risks from missing dependencies, unsafe dynamic imports, SQL injection possibilities, and complex dual-framework support that could lead to subtle bugs
- Pay close attention to packages/testing/src/api/vitest/vite-plugin-auto-import.ts for missing dependency issues and packages/testing/src/api/vitest/vitest-api.setup.ts for database security concerns
21 files reviewed, 8 comments
6b0aac9 to
ea01592
Compare
ea01592 to
f41c6c9
Compare
Yet another PR (12/n) for ESM support. See #349 for where this recent chain of PRs started