Upgrade to Vitest and enhance testing framework#336
Conversation
…ariables - Removed Jest imports from service tests and replaced with Vitest configuration. - Added Vitest configuration file to set up aliases and test environment. - Configured TypeScript to recognize Vitest globals. - Created setup file for Vitest to load environment variables from .env files.
…d mock implementations
…, and utility functions
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
PR Reviewer Guide 🔍Here are some key observations to aid the review process:
|
PR Code Suggestions ✨Explore these optional code suggestions:
|
||||||||||||||||
Summary of ChangesJest → Vitest MigrationFull migration from Jest to Vitest across 71 test files (1,531 tests passing, 5 skipped). Key infrastructure changes:
Test Quality AuditSystematic domain-by-domain audit covering sponsors, proposals, dashboard, tickets, openbadges, and remaining domains. Changes fall into three categories: Deleted (tautological / no source imports):
New test files (134 tests):
Expanded existing tests:
PR Review FixesAddressed code review suggestions:
Testing GuidelinesAdded comprehensive Testing Guidelines section to Stats
|
…rCRMForm and SponsorCard stories
User description
Transition from Jest to Vitest for testing framework, including configuration updates and improved test coverage for various components. Cleaned up unnecessary spaces in environment variable assignments and mock implementations. Added comprehensive tests for proposal validation, video handling, and utility functions. Removed outdated tests and introduced new utility functions for ticket calculations.
PR Type
Tests, Enhancement
Description
Complete migration from Jest to Vitest testing framework across 50+ test files with updated imports, mock declarations, and environment directives
Added comprehensive test coverage for proposal validation, video handling, business utilities, and schema validation with 130+ new test cases
Enhanced test infrastructure with new Vitest configuration files (
vitest.config.ts,vitest.setup.ts) and updated ESLint configurationImproved test utilities including new helper functions (
makeTier(),makeProposal(),createMockTransaction()) to reduce boilerplate and improve maintainabilityUpdated dependencies in
package.jsonandpnpm-lock.yamlto replace Jest with Vitest and coverage toolsAdded testing guidelines documentation in
AGENTS.mdcovering Vitest best practices, test philosophy, and mocking strategiesRemoved outdated tests (6 test files deleted) and cleaned up unnecessary test fixtures and mock implementations
Diagram Walkthrough
File Walkthrough
43 files
config.test.ts
Migrate environment config tests from Jest to Vitesttests/lib/environment/config.test.ts
jest.resetModules()with Vitest equivalents(
vi.resetModules())jest.isolateModules()pattern to asyncimportFresh()helperfunction using dynamic imports
bulk.test.ts
Migrate sponsor CRM bulk operations tests to Vitesttests/lib/sponsor-crm/bulk.test.ts
vi.mock()callscreateMockTransaction()helper function to reduceduplication
jest.fn()calls tovi.fn()andjest.clearAllMocks()tovi.clearAllMocks()status, transaction failures, and assignee name resolution
utils.test.ts
Enhance sponsor utilities tests with Vitest and new test casestests/lib/sponsor/utils.test.ts
makeTier()helper function to reduce test fixtureboilerplate
groupSponsorsByTier()andgetDailySeed()functionsmissing prices, and input mutation
descriptions
validation.test.ts
Expand sponsor validation test coverage with Vitesttests/lib/sponsor/validation.test.ts
conference fields
fields
simultaneously
content checks
actions.test.ts
Migrate dashboard actions tests to Vitest with improved importstests/lib/dashboard/actions.test.ts
jest.mock()calls withvi.mock()andjest.fn()withvi.fn()require()to ES6importfor action functions (Vitesthoists mocks automatically)
jest.useFakeTimers()tovi.useFakeTimers()and related methodsjest.clearAllMocks()withvi.clearAllMocks()state.test.ts
Migrate conference state tests to Vitest environmenttests/lib/conference/state.test.ts
@jest-environment jsdomto@vitest-environment jsdomjest.*calls withvi.*equivalentsjest.useFakeTimers()→vi.useFakeTimers(),jest.setSystemTime()→vi.setSystemTime(), etc.chapter9-test-vector.test.ts
Clean up OpenBadges test imports and documentationtests/lib/openbadges/chapter9-test-vector.test.ts
schemas.test.ts
Add comprehensive proposal schema validation teststests/lib/proposal/schemas.test.ts
ProposalActionSchema,ProposalAdminCreateSchema,ProposalUpdateSchema,InvitationCreateSchema,InvitationResponseSchema,InvitationCancelSchema, andAudienceFeedbackSchematransformations, and edge cases
validation
business-utils.test.ts
Add proposal business utilities test coveragetests/lib/proposal/business-utils.test.ts
calculateAverageRating()covering undefined/emptyreviews, single/multiple reviews, and edge cases
getProposalSpeakerNames()covering single/multiplespeakers, references, and fallback behavior
makeProposal()andmakeReview()for testfixture creation
utils.test.ts
Add proposal utilities test coveragetests/lib/proposal/utils.test.ts
extractSpeakersFromProposal()covering filtering,references, and null handling
extractSpeakerIds()covering mixed input types and IDextraction
calculateReviewScore()covering average calculationsand missing fields
makeProposal()helper for consistent test fixture creationvalidation.test.ts
Add proposal form validation test coveragetests/lib/proposal/validation.test.ts
validateProposalForm()covering required fields,format validation, and capacity requirements
validateProposalForAdmin()covering speaker validationand combined errors
multiple simultaneous errors
makeValidProposal()helper and validation message constantsphase.test.ts
Migrate conference phase tests to Vitest environmenttests/lib/conference/phase.test.ts
@jest-environment jsdomto@vitest-environment jsdomjest.*calls withvi.*equivalentsjest.useFakeTimers()→vi.useFakeTimers(),jest.setSystemTime()→vi.setSystemTime(), etc.provider.test.ts
Migrate contract signing provider tests to Vitesttests/lib/contract-signing/provider.test.ts
@jest-environment nodeto@vitest-environment nodejest.fn()calls withvi.fn()for mock functionsjest.mock()withvi.mock()for module mockingjest.useFakeTimers()→vi.useFakeTimers(),jest.advanceTimersByTimeAsync()→vi.advanceTimersByTimeAsync(), etc.jest.clearAllMocks()withvi.clearAllMocks()grid-utils.test.ts
Migrate grid utils tests and add reflow function teststests/lib/dashboard/grid-utils.test.ts
@jest-environment jsdomto@vitest-environment jsdomreflowWidgetsForColumns()functioncovering desktop/tablet/mobile layouts
edge cases
weekly-update.test.ts
Migrate weekly update cron tests to Vitesttests/api/cron/weekly-update.test.ts
@jest-environment nodeto@vitest-environment nodesanity-client.ts
Migrate Sanity client mock to Vitesttests/mocks/sanity-client.ts
viimportjest.fn()calls tovi.fn()throughout the mock factoryclient.test.ts
Migrate Jest test to Vitest frameworktests/lib/slack/client.test.ts
viinstead of
jest)Object.definePropertytodirect property assignment for better Vitest compatibility
jest.fn()tovi.fn()andupdated type imports to use
MockedFunctionfromvitestjest.resetModules()andjest.restoreAllMocks()to Vitest equivalentsvideo-and-types.test.ts
Add tests for proposal video and format utilitiestests/lib/proposal/video-and-types.test.ts
type checking
getProposalVideoUrl,hasProposalVideo, andisWorkshopFormatfunctionsmultiple recordings, and various format types
delete.test.ts
Migrate sponsor CRM delete tests to Vitesttests/lib/sponsor-crm/delete.test.ts
jest.mock()calls withvi.mock()jest.fn()tovi.fn()jest.clearAllMocks()tovi.clearAllMocks()inbeforeEachhookutils.test.ts
Migrate ticket utils tests and add new utility teststests/lib/tickets/utils.test.ts
@jest-environment jsdomto@vitest-environment jsdom@jest/globalscalculateSponsorTicketsandcreateDefaultAnalysisutility functions with comprehensive edge casecoverage
default analysis structure
delete.test.ts
Migrate sponsor delete tests to Vitesttests/lib/sponsor/delete.test.ts
jest.mock()calls withvi.mock()jest.fn()tovi.fn()jest.clearAllMocks()tovi.clearAllMocks()inbeforeEachhookcontract-reminders.test.ts
Migrate contract reminders cron test to Vitesttests/api/cron/contract-reminders.test.ts
@jest-environment nodeto@vitest-environment nodejest.mock()andjest.fn()callswith Vitest equivalents
jest.clearAllMocks()tovi.clearAllMocks()inbeforeEachhookadobe-sign.test.ts
Migrate Adobe Sign webhook test to Vitesttests/api/webhooks/adobe-sign.test.ts
@jest-environment nodeto@vitest-environment nodejest.mock()andjest.fn()callswith Vitest equivalents
jest.clearAllMocks()tovi.clearAllMocks()andjest.spyOn()tovi.spyOn()weeklyUpdate.test.ts
Migrate Slack weekly update test to Vitesttests/lib/slack/weeklyUpdate.test.ts
@jest-environment nodeto@vitest-environment nodejestreferences withviequivalents
Object.definePropertytodirect property assignment
jest.MockedFunctiontoMockedFunctionfrom
vitestnotify.test.ts
Migrate Slack notify test to Vitesttests/lib/slack/notify.test.ts
@jest-environment nodeto@vitest-environment nodejest.mock()andjest.fn()callswith Vitest equivalents
jest.MockedFunctiontoMockedFunctionfrom
vitestjest.restoreAllMocks()tovi.restoreAllMocks()andjest.spyOn()tovi.spyOn()registration.test.ts
Migrate sponsor CRM registration test to Vitesttests/lib/sponsor-crm/registration.test.ts
jest.mock()andjest.fn()callswith Vitest equivalents
jest.MocktoMockfromvitestjest.clearAllMocks()tovi.clearAllMocks()validation.test.ts
Migrate attachment validation test to Vitesttests/lib/attachment/validation.test.ts
@jest/globals@jest-environment jsdomto@vitest-environment jsdomUint8Arrayfor better performanceclient.test.ts
Migrate Adobe Sign client test to Vitesttests/lib/adobe-sign/client.test.ts
@jest-environment nodeto@vitest-environment nodejest.fn()withvi.fn()jest.MockedFunctiontoMockedFunctionfrom
vitestjest.resetModules()tovi.resetModules()next-auth.ts
Update next-auth mock for Vitesttests/mocks/next-auth.ts
viimportjest.fn()calls tovi.fn()throughout the mockimplementation
openbadges.test.ts
Migrate openbadges test to Vitesttests/lib/openbadges/openbadges.test.ts
jest.unmock()calls withvi.unmock()describe,it,expectimports from@jest/globalssanity-image-url.ts
Update Sanity image URL mock for Vitesttests/mocks/sanity-image-url.ts
viimportjest.fn()calls tovi.fn()in the mock implementationpublic.test.ts
Migrate ticket public test to Vitesttests/lib/tickets/public.test.ts
jest.mock()calls withvi.mock()jest.fn()tovi.fn()placement-utils.test.ts
Migrate dashboard placement utils test to Vitesttests/lib/dashboard/placement-utils.test.ts
@jest-environment jsdomto@vitest-environment jsdom@jest/globalsutils-deduplication.test.ts
Migrate ticket deduplication test to Vitesttests/lib/tickets/utils-deduplication.test.ts
@jest-environment jsdomto@vitest-environment jsdom@jest/globalswidget-registry.test.ts
Migrate dashboard widget registry test to Vitesttests/lib/dashboard/widget-registry.test.ts
@jest-environment jsdomto@vitest-environment jsdom@jest/globalspresets.test.ts
Migrate dashboard presets test to Vitesttests/lib/dashboard/presets.test.ts
@jest-environment jsdomto@vitest-environment jsdom@jest/globalsutils.test.ts
Migrate speaker utils test to Vitesttests/lib/speaker/utils.test.ts
@jest-environment jsdomto@vitest-environment jsdom@jest/globalstime.test.ts
Migrate time utilities test to Vitesttests/lib/time.test.ts
@jest-environment jsdomto@vitest-environment jsdom@jest/globalsprocessor.test.ts
Migrate ticket processor test to Vitesttests/lib/tickets/processor.test.ts
@jest-environment nodeto@vitest-environment node@jest/globalsContractSigningPage.test.tsx
Migrate contract signing page test to Vitesttests/components/sponsor/ContractSigningPage.test.tsx
@jest-environment jsdomto@vitest-environment jsdomjest.mock()andjest.fn()callswith Vitest equivalents
@testing-library/jest-domimport (now handled byvitest.setup.ts)require()workaroundSponsorContractView.test.tsx
Migrate sponsor contract view test to Vitesttests/components/admin/sponsor-crm/SponsorContractView.test.tsx
@jest-environment jsdomto@vitest-environment jsdomjest.mock()andjest.fn()callswith Vitest equivalents
@testing-library/jest-domimport (now handled byvitest.setup.ts)require()workaroundBoardViewSwitcher.test.tsx
Migrate board view switcher test to Vitesttests/components/admin/sponsor-crm/BoardViewSwitcher.test.tsx
@jest-environment jsdomto@vitest-environment jsdomjest.fn()withvi.fn()@testing-library/jest-domimport (now handled byvitest.setup.ts)OrganizerSignatureCapture.test.tsx
Migrate organizer signature capture test to Vitesttests/components/admin/sponsor-crm/OrganizerSignatureCapture.test.tsx
@jest-environment jsdomto@vitest-environment jsdomjest.mock()andjest.fn()callswith Vitest equivalents
@testing-library/jest-domimport (now handled byvitest.setup.ts)require()workaround3 files
vitest.config.ts
Add Vitest configuration filevitest.config.ts
nodewith jsdom support via environmentdirective
@,jose,@noble/ed25519,next-auth,next-sanity, and other dependenciesvitest.setup.ts
Add Vitest setup configuration filevitest.setup.ts
.env,.env.local,and
.env.testfileseslint.config.js
Update ESLint config for Vitest fileseslint.config.js
vitest.config.tsandvitest.setup.tsinstead of Jest equivalents2 files
noble-ed25519.ts
Update noble-ed25519 mock documentationtests/mocks/noble-ed25519.ts
@noble/ed25519v3 is pure ESMAGENTS.md
Add comprehensive testing guidelines documentationAGENTS.md
@testing-library/reactreal source code validation
practices for mocking
performance considerations
2 files
package.json
Update package.json for Vitest migrationpackage.json
vitest run,vitest, etc.)@jest/globals,jest,jest-environment-jsdom,ts-jest)vitest,@vitest/coverage-v8)pnpm-lock.yaml
Migrate testing framework from Jest to Vitest with coverage supportpnpm-lock.yaml
@jest/globals,jest,jest-environment-jsdom,ts-jest) from devDependenciesvitest@4.0.18) and coverage tool(
@vitest/coverage-v8@4.0.18) as devDependenciesinclude
vitestinstead of Jest-related packages(
handlebars,bs-logger,neo-async,uglify-js,lodash.memoize)@vitest/mocker,@vitest/runner,@vitest/snapshot,tinybench,tinyexec,why-is-node-running)43 files
Greptile Summary
This PR successfully migrates the testing framework from Jest to Vitest across 94 files. The migration is comprehensive and well-executed:
Core Changes:
jest,ts-jest,jest-environment-jsdom,@jest/globals)vitest,@vitest/coverage-v8)package.jsonto use Vitest commandsvitest.config.tswith proper module aliases for mocking external dependenciesvitest.setup.tsby removing TextEncoder/TextDecoder polyfills (Vitest provides these natively)Test File Updates:
@jest-environment jsdomto@vitest-environment jsdomdocblocksjest.fn()withvi.fn()throughout mocksjest.mock()tovi.mock()andjest.unmock()tovi.unmock()describe,it,expectfrom@jest/globals(now globals via Vitest)jest.isolateModules()tovi.resetModules()+ dynamic imports patternNew Test Coverage:
validation.test.ts)video-and-types.test.ts)calculateSponsorTickets,createDefaultAnalysis)Documentation:
AGENTS.mdwith extensive Vitest testing guidelinesThe migration follows Vitest best practices and maintains all existing test coverage while improving the testing infrastructure.
Confidence Score: 5/5
Important Files Changed
Flowchart
flowchart TD A[Jest Testing Framework] --> B[Remove Dependencies] B --> C[jest, ts-jest, jest-environment-jsdom] A --> D[Add Vitest] D --> E[vitest and coverage-v8] D --> F[Create vitest.config.ts] F --> G[Module Aliases for Mocks] G --> H[jose, noble-ed25519, uuid, next-auth, next-sanity] D --> I[Update Test Scripts] I --> J[test: vitest run] I --> K[test:debug: vitest run verbose] I --> L[test:watch: vitest] D --> M[Migrate All Tests] M --> N[70+ Test Files] N --> O[jest.fn to vi.fn] N --> P[jest.mock to vi.mock] N --> Q[Environment docblocks] N --> R[Module isolation pattern] D --> S[Add New Tests] S --> T[Proposal Validation] S --> U[Video Handling] S --> V[Ticket Utils] D --> W[Update Documentation] W --> X[AGENTS.md Testing Guidelines] W --> Y[ESLint and Knip Config] D --> Z[Vitest Benefits] Z --> AA[Native ESM Support] Z --> AB[Faster Execution] Z --> AC[Built-in Globals]Last reviewed commit: 1a735d8
Context used:
dashboard- AGENTS.md (source)