Skip to content

feat(esm): Add vitest plugins and config to packages/testing#355

Merged
Tobbe merged 1 commit into
mainfrom
tobbe-esm-prep-testing-vitest
Aug 9, 2025
Merged

feat(esm): Add vitest plugins and config to packages/testing#355
Tobbe merged 1 commit into
mainfrom
tobbe-esm-prep-testing-vitest

Conversation

@Tobbe
Copy link
Copy Markdown
Member

@Tobbe Tobbe commented Aug 9, 2025

Yet another PR (12/n) for ESM support. See #349 for where this recent chain of PRs started

@Tobbe Tobbe added this to the next-release milestone Aug 9, 2025
@netlify
Copy link
Copy Markdown

netlify Bot commented Aug 9, 2025

Deploy Preview for cedarjs canceled.

Name Link
🔨 Latest commit f41c6c9
🔍 Latest deploy log https://app.netlify.com/projects/cedarjs/deploys/68978f6e1a3a3e0008dea384

Copy link
Copy Markdown
Contributor

@greptile-apps greptile-apps Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Edit Code Review Bot Settings | Greptile

Comment thread packages/testing/src/api/vitest/vite-plugin-track-db-imports.ts Outdated
Comment thread packages/testing/src/api/vitest/vite-plugin-track-db-imports.ts
Comment thread packages/testing/src/web/globRoutesImporter.ts
Comment thread packages/testing/src/web/MockRouter.tsx Outdated
Comment thread packages/testing/src/api/mockContext.ts
Comment thread packages/testing/src/api/mockContext.ts
@Tobbe Tobbe force-pushed the tobbe-esm-prep-testing-vitest branch from ea01592 to f41c6c9 Compare August 9, 2025 18:11
Tobbe added a commit that referenced this pull request Aug 9, 2025
Tobbe added a commit that referenced this pull request Aug 9, 2025
Tobbe added a commit that referenced this pull request Aug 9, 2025
Tobbe added a commit that referenced this pull request Aug 9, 2025
@Tobbe Tobbe merged commit 8691b6d into main Aug 9, 2025
50 checks passed
@Tobbe Tobbe deleted the tobbe-esm-prep-testing-vitest branch August 9, 2025 20:45
Tobbe added a commit that referenced this pull request Aug 9, 2025
This reverts commit 8691b6d.
Tobbe added a commit that referenced this pull request Aug 9, 2025
Tobbe added a commit that referenced this pull request Aug 9, 2025
Tobbe added a commit that referenced this pull request Aug 9, 2025
Tobbe added a commit that referenced this pull request Aug 9, 2025
Tobbe added a commit that referenced this pull request Aug 9, 2025
@Tobbe Tobbe restored the tobbe-esm-prep-testing-vitest branch August 9, 2025 22:53
Tobbe added a commit that referenced this pull request Aug 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant