diff --git a/.vscode/launch.json b/.vscode/launch.json index 2fa4db9b2..171c80066 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -5,9 +5,17 @@ "type": "node", "request": "launch", "name": "Start testing", - "program": "${workspaceFolder}/node_modules/.bin/mocha", - "args": ["${file}", "--watch"], + "program": "${workspaceFolder}/node_modules/.bin/vitest", + "args": ["run", "${file}", "--reporter=verbose"], + "console": "integratedTerminal" + }, + { + "type": "node", + "request": "launch", + "name": "Start testing (watch)", + "program": "${workspaceFolder}/node_modules/.bin/vitest", + "args": ["${file}", "--reporter=verbose"], "console": "integratedTerminal" } ] -} +} \ No newline at end of file diff --git a/eslint.config.mjs b/eslint.config.mjs index 9cd54f623..1de2500f4 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -77,7 +77,7 @@ export default typegen([ globals: { ...globals.es6, ...globals.node, - ...globals.mocha + ...globals.vitest } }, linterOptions: { diff --git a/package.json b/package.json index a473deb46..5bd188f01 100644 --- a/package.json +++ b/package.json @@ -7,13 +7,13 @@ "scripts": { "new": "node tools/new-rule.js", "start": "npm run test:base -- --watch --growl", - "test:base": "mocha \"tests/lib/**/*.js\" --reporter dot", - "test": "nyc npm run test:base -- \"tests/integrations/*.js\" --timeout 60000", - "test:integrations": "mocha \"tests/integrations/*.js\" --timeout 60000", - "debug": "mocha --inspect \"tests/lib/**/*.js\" --reporter dot --timeout 60000", + "test:base": "vitest run --reporter=dot tests/lib", + "test": "vitest run", + "test:integrations": "vitest run tests/integrations", + "debug": "vitest run --inspect --no-file-parallelism --reporter=dot tests/lib", "cover": "npm run cover:test && npm run cover:report", - "cover:test": "nyc npm run test:base -- --timeout 60000", - "cover:report": "nyc report --reporter=html", + "cover:test": "vitest run --coverage --reporter=dot tests/lib", + "cover:report": "echo 'HTML coverage report available at ./coverage/index.html'", "lint": "eslint . && markdownlint \"**/*.md\"", "lint:fix": "eslint . --fix && markdownlint \"**/*.md\" --fix", "tsc": "tsc", @@ -87,6 +87,7 @@ "@types/xml-name-validator": "^4.0.3", "@typescript-eslint/parser": "^8.35.1", "@typescript-eslint/types": "^8.35.1", + "@vitest/coverage-v8": "^3.2.4", "assert": "^2.1.0", "env-cmd": "^10.1.0", "esbuild": "^0.24.0", @@ -106,8 +107,6 @@ "globals": "^15.14.0", "jsdom": "^22.0.0", "markdownlint-cli": "^0.42.0", - "mocha": "^10.7.3", - "nyc": "^17.1.0", "pathe": "^1.1.2", "prettier": "^3.3.3", "typescript": "^5.7.2", diff --git a/tests/.eslintrc.json b/tests/.eslintrc.json deleted file mode 100644 index 7eeefc33b..000000000 --- a/tests/.eslintrc.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "env": { - "mocha": true - } -} diff --git a/tests/integrations/eslint-plugin-import.js b/tests/integrations/eslint-plugin-import.js index 4e26508ce..6f4be7acf 100644 --- a/tests/integrations/eslint-plugin-import.js +++ b/tests/integrations/eslint-plugin-import.js @@ -9,18 +9,12 @@ const cp = require('child_process') const path = require('path') const semver = require('semver') +const PLUGIN_DIR = path.join(__dirname, 'eslint-plugin-import') const ESLINT = `.${path.sep}node_modules${path.sep}.bin${path.sep}eslint` describe('Integration with eslint-plugin-import', () => { - let originalCwd - - before(() => { - originalCwd = process.cwd() - process.chdir(path.join(__dirname, 'eslint-plugin-import')) - cp.execSync('npm i', { stdio: 'inherit' }) - }) - after(() => { - process.chdir(originalCwd) + beforeAll(() => { + cp.execSync('npm i', { cwd: PLUGIN_DIR, stdio: 'inherit' }) }) // https://github.com/vuejs/eslint-plugin-vue/issues/21#issuecomment-308957697 @@ -41,6 +35,6 @@ describe('Integration with eslint-plugin-import', () => { return } - cp.execSync(`${ESLINT} a.vue`, { stdio: 'inherit' }) + cp.execSync(`${ESLINT} a.vue`, { cwd: PLUGIN_DIR, stdio: 'inherit' }) }) }) diff --git a/tests/integrations/flat-config.js b/tests/integrations/flat-config.js index df5190021..9dd2f2ad8 100644 --- a/tests/integrations/flat-config.js +++ b/tests/integrations/flat-config.js @@ -5,18 +5,12 @@ const cp = require('child_process') const path = require('path') const semver = require('semver') +const TARGET_DIR = path.join(__dirname, 'flat-config') const ESLINT = `.${path.sep}node_modules${path.sep}.bin${path.sep}eslint` describe('Integration with flat config', () => { - let originalCwd - - before(() => { - originalCwd = process.cwd() - process.chdir(path.join(__dirname, 'flat-config')) - cp.execSync('npm i -f', { stdio: 'inherit' }) - }) - after(() => { - process.chdir(originalCwd) + beforeAll(() => { + cp.execSync('npm i -f', { cwd: TARGET_DIR, stdio: 'inherit' }) }) it('should lint without errors', () => { @@ -33,6 +27,7 @@ describe('Integration with flat config', () => { const result = JSON.parse( cp.execSync(`${ESLINT} a.vue --format=json`, { + cwd: TARGET_DIR, encoding: 'utf8' }) ) diff --git a/vitest.config.ts b/vitest.config.ts new file mode 100644 index 000000000..eeef751d6 --- /dev/null +++ b/vitest.config.ts @@ -0,0 +1,32 @@ + +import { defineConfig } from 'vitest/config'; +export default defineConfig({ + test: { + include: [ + 'tests/lib/**/*.js', + 'tests/integrations/**/*.js' + ], + exclude: [ + '**/node_modules/**', + '**/dist/**', + 'tests/fixtures/**', + 'tests/integrations/flat-config/eslint.config.js', + 'tests/lib/rules/no-unsupported-features/utils.js' + ], + testTimeout: 60_000, + globals: true, + coverage: { + provider: 'v8', + include: ['lib/**/*.js'], + exclude: [ + 'tests/**', + 'dist/**', + 'tools/**', + 'node_modules/**' + ], + reporter: ['text', 'lcov', 'json-summary', 'html'], + all: true, + reportsDirectory: './coverage' + }, + }, +});