Migrate from Mocha/Sinon/Chai to Vitest#1404
Merged
Kocal merged 1 commit intosymfony:mainfrom Apr 6, 2026
Merged
Conversation
f2d9ccd to
44349e6
Compare
There was a problem hiding this comment.
Pull request overview
This PR migrates the repository’s test and lint tooling from Mocha/Sinon/Chai to Vitest, updating test files, adding Vitest configuration, and adjusting CI workflows to improve test execution consistency.
Changes:
- Added Vitest configuration files and updated
package.json/ESLint to run Vitest and lint Vitest globals. - Converted existing tests from Mocha/Sinon/Chai-style APIs to Vitest (including spies/mocks and assertion updates).
- Updated GitHub Actions workflows to enable dependency caching and adjust matrix metadata.
Reviewed changes
Copilot reviewed 51 out of 53 changed files in this pull request and generated 7 comments.
Show a summary per file
| File | Description |
|---|---|
| vitest.persistent-cache.config.js | Adds a dedicated Vitest config for persistent-cache tests. |
| vitest.config.js | Adds the main Vitest config (includes/excludes, setup files, timeouts). |
| test/WebpackConfig.js | Migrates WebpackConfig tests to Vitest imports/assertions. |
| test/vitest-setup.js | Adds Vitest setup to reset logger and restore mocks after each test. |
| test/vitest-global-setup.js | Adds global setup intended to clear temp dir before tests. |
| test/utils/string-escaper.js | Migrates string-escaper tests to Vitest. |
| test/utils/regexp-escaper.js | Migrates regexp-escaper tests to Vitest. |
| test/utils/package-up.js | Refactors tests to Vitest and uses it.each. |
| test/utils/get-vue-version.js | Replaces Sinon stubs with vi.spyOn and Vitest assertions. |
| test/utils/get-file-extension.js | Migrates get-file-extension tests to Vitest. |
| test/plugins/terser.js | Migrates terser plugin tests to Vitest. |
| test/plugins/notifier.js | Migrates notifier plugin tests to Vitest. |
| test/plugins/mini-css-extract.js | Migrates mini-css-extract plugin tests to Vitest. |
| test/plugins/manifest.js | Migrates manifest plugin tests to Vitest. |
| test/plugins/friendly-errors.js | Migrates friendly-errors plugin tests to Vitest. |
| test/plugins/forked-ts-types.js | Migrates forked TS types plugin tests to Vitest. |
| test/plugins/define.js | Migrates define plugin tests to Vitest. |
| test/persistent-cache/functional.js | Removes the Mocha-based persistent-cache functional suite. |
| test/package-helper.js | Migrates package-helper tests to Vitest. |
| test/logger.js | Migrates logger tests to Vitest. |
| test/loaders/vue.js | Migrates vue loader tests to Vitest. |
| test/loaders/typescript.js | Migrates TS loader tests to Vitest. |
| test/loaders/stylus.js | Replaces Sinon stubs with Vitest spies in stylus loader tests. |
| test/loaders/sass.js | Replaces Sinon stubs with Vitest spies in sass loader tests. |
| test/loaders/less.js | Replaces Sinon stubs with Vitest spies in less loader tests. |
| test/loaders/handlebars.js | Migrates handlebars loader tests to Vitest. |
| test/loaders/css.js | Migrates css loader tests to Vitest. |
| test/loaders/css-extract.js | Migrates css-extract loader tests to Vitest. |
| test/loaders/babel.js | Migrates babel loader tests to Vitest. |
| test/index.js | Migrates public API tests to Vitest and replaces Sinon spy usage. |
| test/helpers/setup.js | Refactors webpack runner helper to return structured results and mutes output. |
| test/helpers/logger-assert.js | Adds helper for asserting logger warning messages. |
| test/helpers/assert.js | Converts Assert helper to Vitest expect and exports Assert class. |
| test/friendly-errors/transformers/missing-loader.js | Migrates transformer tests to Vitest. |
| test/friendly-errors/transformers/missing-css-file.js | Migrates transformer tests to Vitest. |
| test/friendly-errors/formatters/missing-loader.js | Migrates formatter tests to Vitest. |
| test/friendly-errors/formatters/missing-css-file.js | Migrates formatter tests to Vitest. |
| test/config/validator.js | Migrates validator tests to Vitest. |
| test/config/path-util.js | Migrates path-util tests to Vitest. |
| test/config/parse-runtime.js | Migrates parse-runtime tests to Vitest. |
| test/config-generator.js | Migrates config-generator tests to Vitest. |
| test/bin/encore.js | Migrates bin smoke/functional tests to Vitest and async/await. |
| package.json | Replaces Mocha scripts with vitest run and swaps dev deps to Vitest ecosystem. |
| lib/logger.js | Refactors logger message storage typing/initialization. |
| eslint.config.js | Replaces Mocha ESLint plugin with Vitest ESLint plugin. |
| AGENTS.md | Updates contributor docs to reference Vitest commands. |
| .github/workflows/testing_apps.yml | Adds pkg manager metadata and enables dependency caching per test app. |
| .github/workflows/stable-tests.yml | Enables Yarn cache in Node setup. |
| .github/workflows/low-depends.yml | Enables Yarn cache in Node setup. |
| .github/workflows/lint.yaml | Enables Yarn cache in Node setup. |
| .github/workflows/high-depends.yml | Enables Yarn cache in Node setup. |
Comments suppressed due to low confidence (2)
test/vitest-global-setup.js:14
- Vitest
globalSetupexpects the referenced module to export a default function (optionally returning a teardown). Exporting a namedsetup()function here means the global setup will not run, soemptyTmpDir()won’t execute before the test suite.
test/helpers/setup.js:134 - In
runWebpack(), thecatchpath restoresprocess.stdout.writebut does not restoreconsole.log/console.warn. Ifvalidator()/configGenerator()throws beforecompiler.run()executes, subsequent tests will run withconsole.log/console.warnstill muted. Restore all overridden console methods in the catch block as well.
});
} catch (e) {
// Restore stdout and then re-throw the exception
process.stdout.write = stdoutWrite;
throw e;
}
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| expect(cssLoaderStub.mock.calls[0][1]).toBe(false); | ||
|
|
||
| cssLoader.getLoaders.restore(); | ||
| cssLoader.getLoaders; |
There was a problem hiding this comment.
cssLoader.getLoaders; is a no-op and does not restore the vi.spyOn(...). If you want per-test cleanup, call cssLoaderStub.mockRestore(); otherwise remove this statement and rely on the global vi.restoreAllMocks() setup.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This pull request migrates the project's testing framework from Mocha/Chai to Vitest, updates related dependencies, and improves the CI workflows for better package manager support and caching.
These changes modernize the project's testing stack, improve CI efficiency, and increase code clarity and maintainability.