Mocha to Vitest - Migration Recipe

verified codemod icon

This recipe is a set of codemods that will upgrade your project from using mocha to vitest.

Vitest
jscodeshift
Estimated time saving
5+ minutes/file
Change mode
Assistive
Applicability criteria

Mocha >= 9.0.0

Made by
Codemod.com
Codemod.com

Usage →

Codemod CLI:

intalling vs code extension tooltip icon
codemod mocha/vitest/recipe
copy CLI command icon

Codemod VS Code extension:

intalling vs code extension tooltip icon
vs code logo
Run in VS Code

Description

This recipe is a set of codemods that will upgrade your project from using mocha to vitest.

The recipe includes the following codemods:

NOTE: if you are not using vitest default .spec.* or .test.* file names, then you won't be able to run your tests upon migrating. To mitigate this and add your own set of globs, create vite.config.ts file in the root of your project and add the following configuration, replacing **/test/*.ts with your own globs:

import { configDefaults, defineConfig } from 'vitest/config';

export default defineConfig({
	test: {
		include: [...configDefaults.include, '**/test/*.ts'],
	},
});