-
-
Notifications
You must be signed in to change notification settings - Fork 217
feat: migrate test suite from Mocha to Vitest #2815
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
- Replace Mocha with Vitest v3.2.4 across all test suites - Convert all assertions from assert.* to expect().* syntax - Migrate custom JSON snapshot system to Vitest's built-in snapshots - Remove ~200+ individual JSON files, replace with 3 .snap files - Add UPDATE_SNAPSHOTS env var support for snapshot updates - Fix all test imports and syntax for Vitest compatibility - Update TypeScript diagnostic snapshots for TS 5.8.2 - All 635 tests passing with 100% pass rate BREAKING CHANGE: Test framework changed from Mocha to Vitest. Run tests with 'pnpm test' or 'vitest' instead of mocha.
- No longer needed after migrating from Mocha to Vitest
- Add environment-based Svelte 5 alias configuration in vitest.config.ts - Simplify CI workflow for Svelte 5 testing using SVELTE_VERSION env var - Add svelte5 package alias for cleaner dependency management - Remove unnecessary workspace configuration files
- Svelte 5.38.0 as default 'svelte' dependency (current version) - Svelte 4.2.20 as 'svelte4' alias for backwards compatibility - Vitest workspace configuration runs tests against both versions - No runtime patching or installation needed - CI simplified to just run 'pnpm test:workspace'
- Create test-helpers module for centralized Svelte version detection - Update all tests to use consistent version checking - Fix HTML plugin test to handle both Svelte versions correctly - Workspace configuration now properly aliases svelte/svelte4 imports - Tests correctly detect runtime Svelte version via aliases
- Add dynamic isSvelte5Plus() function to avoid cached module-level values - Update all tests to use function calls instead of cached constants - Fix test expectations to handle Svelte 5 being the default - Unskip previously blocked test to check if upstream issue is fixed - Note: Vitest aliases only apply to test code, not source code
- Remove .npmrc with deprecated resolution-mode setting - Replace deprecated vitest workspace file with test.projects configuration - Fix deprecated Vitest timeout syntax using vi.setConfig() - Update resolve.alias configuration for proper Svelte version handling - Eliminate all deprecation warnings from test output - Maintain dual Svelte 4/5 testing capability
- Remove complex Vitest projects setup that wasn't working with aliases - Restore CI to use separate jobs for Svelte 4 and Svelte 5 testing - Clean up unsuccessful dual-version scripts and configurations - Maintain simple, reliable testing approach
The Position import was missing causing ReferenceError in diagnostic tests
Finalizes the testing framework migration by updating CI workflows to use simplified test commands and ensuring performance tests run sequentially to avoid conflicts.
Removes leftover index-vitest-snapshots.test.ts.snap from earlier migration attempt. The test suite now uses the standard index.test.ts.snap file.
Continuing the work done in #2711 Most of the changes come from the conversion of snapshots to vitest snapshots. I tooled around with trying to get svelte 4 and svelte 5 test to run simultaneously using an alias and vitest projects, but language-tools didn't seem to want to play nice with the alias. I can spend more time digging into that if desired. Happy to clean up/make changes as necessary, just let me know what I can do to help get this across the finish line. |
I don't think merging every expected JSON snapshot into one giant file is a good idea. It makes it very hard to trace the git diff, difficult to map the file back to its original input, and it'll easily cause git conflicts. I am also not sure about the "Dual Testing Setup" part, at least that the svelte5 install should be in devDependencies. The test timeout customisation shouldn't be removed either. |
Ok, I can organize these into files that (mostly) align with the files we had before using
This is an artifact from when I was trying to make both versions test in the same CI and context using vitest projects. I still think this can be made to work, but was having trouble with it. I'll remove the artifacts, my bad.
Will fix this as well and take another pass on unnecessary changes that slipped through. |
…ration - Switch from inline Vitest snapshots to toMatchFileSnapshot with clean JSON files - Restore default Svelte version from 5.x back to 4.x in language-server package - Remove unnecessary vitest setup file that wasn't in master - Set proper test timeout (25s) in vitest config to match original Mocha behavior - Clean up one-off comments and maintain sequential performance tests - Add snapshot files to prettierignore to handle JSON formatting All tests passing with improved snapshot organization for easier diffing.
…approach - Replace dynamic timeout adjustment with explicit performance assertions - Maintain adaptive time limits: fast machines get stricter limits, slow machines get generous limits - Use expect().toBeLessThan() for immediate clear failure messages instead of timeout errors - Clean up comments to focus on current implementation rather than comparisons Performance behavior is preserved while being more compatible with Vitest's testing model.
I wasn't able to exactly reproduce the same behavior as I couldn't find a way to dynamically set and get timeout in the test like mocha (if you're aware of one let me know), but I did my best to recreate the same regression proofing with expect. Let me know if you'd like to see another approach here. The other issues have been addressed, I believe. Edit: benchmark output is kinda odd in vite right now, I wrote some benchmarks but need to spend more time to understand how to make the output useful. will have to follow up with benchmarks. |
Summary
Completes a comprehensive migration of the entire test suite from Mocha to Vitest, modernizing our testing infrastructure across both the language server and svelte2tsx packages.
Changes Made
Core Testing Infrastructure
Multi-Version Svelte Support
Test Modernization
test-helpers.ts
for common setup patternsCompromises & Technical Decisions
it.sequential()
to prevent timing conflicts in CITesting & Validation