Mocha to Vitest - Migrate Configuration

verified codemod icon

Run this codemod to upgrade configuration files that need to be changed after migrating from mocha to vitest.

Vitest
Filemod
Estimated time saving
5+ minutes/file
Change mode
Autonomous
Applicability criteria

Mocha >= 9.0.0

Made by
Codemod.com
Codemod.com

Usage →

Codemod CLI:

intalling vs code extension tooltip icon
codemod mocha/vitest/migrate-configuration
copy CLI command icon

Codemod VS Code extension:

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

Description

Run this codemod to upgrade configuration files that need to be changed after migrating from mocha to vitest.

Example

package.json

Before

{
  "name": "package-name",
  "dependencies": {
    "mocha": "^10.2.0",
    "some-mocha-plugin": "^10.0.4"
  },
  "devDependencies": {
    "mocha": "^10.2.0",
    "@types/mocha": "^10.0.4"
  },
  "main": "./dist/index.cjs",
  "types": "/dist/index.d.ts",
  "scripts": {
    "build:cjs": "cjs-builder ./src/index.ts",
    "test": "mocha"
  },
  "mocha": {
    "config-key": "config-value"
  },
  "files": [
    "README.md",
    "config.json",
    "./dist/index.cjs",
    "./index.d.ts"
  ],
  "type": "module"
}

After

{
  "name": "package-name",
  "dependencies": {},
  "devDependencies": {
    "vitest": "^1.0.1",
    "@vitest/coverage-v8": "^1.0.1"
  },
  "main": "./dist/index.cjs",
  "types": "/dist/index.d.ts",
  "scripts": {
    "build:cjs": "cjs-builder ./src/index.ts",
    "test": "vitest run",
    "coverage": "vitest run --coverage"
  },
  "files": [
    "README.md",
    "config.json",
    "./dist/index.cjs",
    "./index.d.ts"
  ],
  "type": "module"
}

tsconfig.json

Before

{
  "compilerOptions": { "types": ["mocha"] },
  "include": [
    "./src/**/*.ts",
    "./src/**/*.js",
    "./test/**/*.ts",
    "./test/**/*.js"
  ]
}

After

{
  "compilerOptions": {},
  "include": [
    "./src/**/*.ts",
    "./src/**/*.js",
    "./test/**/*.ts",
    "./test/**/*.js"
  ]
}

.mocharc

Before

{
  "loader": ["ts-node/esm"],
  "full-trace": true,
  "failZero": false,
  "bail": true,
  "spec": "./**/test.ts",
  "timeout": 5000
}

After

Removed