Skip to content

Migrate from Mocha/Sinon/Chai to Vitest#1404

Merged
Kocal merged 1 commit intosymfony:mainfrom
Kocal:migrate-to-vitest
Apr 6, 2026
Merged

Migrate from Mocha/Sinon/Chai to Vitest#1404
Kocal merged 1 commit intosymfony:mainfrom
Kocal:migrate-to-vitest

Conversation

@Kocal
Copy link
Copy Markdown
Member

@Kocal Kocal commented Apr 3, 2026

Q A
Bug fix? no
New feature? no
Deprecations? no
Issues Fix #...
License MIT

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.

@Kocal Kocal self-assigned this Apr 3, 2026
@carsonbot carsonbot added the Status: Needs Review Needs to be reviewed label Apr 3, 2026
@Kocal Kocal force-pushed the migrate-to-vitest branch 4 times, most recently from f2d9ccd to 44349e6 Compare April 6, 2026 10:37
@Kocal Kocal requested a review from Copilot April 6, 2026 13:56
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

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 globalSetup expects the referenced module to export a default function (optionally returning a teardown). Exporting a named setup() function here means the global setup will not run, so emptyTmpDir() won’t execute before the test suite.
    test/helpers/setup.js:134
  • In runWebpack(), the catch path restores process.stdout.write but does not restore console.log/console.warn. If validator()/configGenerator() throws before compiler.run() executes, subsequent tests will run with console.log/console.warn still 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.

Comment thread package.json
Comment thread AGENTS.md Outdated
Comment thread test/loaders/stylus.js Outdated
expect(cssLoaderStub.mock.calls[0][1]).toBe(false);

cssLoader.getLoaders.restore();
cssLoader.getLoaders;
Copy link

Copilot AI Apr 6, 2026

Choose a reason for hiding this comment

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

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.

Copilot uses AI. Check for mistakes.
Comment thread test/loaders/sass.js Outdated
Comment thread test/loaders/less.js Outdated
Comment thread vitest.persistent-cache.config.js Outdated
Comment thread test/helpers/setup.js Outdated
@Kocal Kocal force-pushed the migrate-to-vitest branch from 0d13cc5 to bdebcca Compare April 6, 2026 14:14
@Kocal Kocal merged commit 406cafa into symfony:main Apr 6, 2026
@Kocal Kocal deleted the migrate-to-vitest branch April 6, 2026 14:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Status: Needs Review Needs to be reviewed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants