Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 60c7848

Browse files
authored
Migrate from Mocha to Vitest (#2789)
1 parent 02890f3 commit 60c7848

File tree

7 files changed

+59
-36
lines changed

7 files changed

+59
-36
lines changed

‎.vscode/launch.json‎

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,17 @@
55
"type": "node",
66
"request": "launch",
77
"name": "Start testing",
8-
"program": "${workspaceFolder}/node_modules/.bin/mocha",
9-
"args": ["${file}", "--watch"],
8+
"program": "${workspaceFolder}/node_modules/.bin/vitest",
9+
"args": ["run", "${file}", "--reporter=verbose"],
10+
"console": "integratedTerminal"
11+
},
12+
{
13+
"type": "node",
14+
"request": "launch",
15+
"name": "Start testing (watch)",
16+
"program": "${workspaceFolder}/node_modules/.bin/vitest",
17+
"args": ["${file}", "--reporter=verbose"],
1018
"console": "integratedTerminal"
1119
}
1220
]
13-
}
21+
}

‎eslint.config.mjs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ export default typegen([
7777
globals: {
7878
...globals.es6,
7979
...globals.node,
80-
...globals.mocha
80+
...globals.vitest
8181
}
8282
},
8383
linterOptions: {

‎package.json‎

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@
77
"scripts": {
88
"new": "node tools/new-rule.js",
99
"start": "npm run test:base -- --watch --growl",
10-
"test:base": "mocha \"tests/lib/**/*.js\" --reporterdot",
11-
"test": "nyc npm run test:base -- \"tests/integrations/*.js\" --timeout 60000",
12-
"test:integrations": "mocha \"tests/integrations/*.js\" --timeout 60000",
13-
"debug": "mocha --inspect \"tests/lib/**/*.js\" --reporterdot --timeout 60000",
10+
"test:base": "vitest run --reporter=dot tests/lib",
11+
"test": "vitest run",
12+
"test:integrations": "vitest run tests/integrations",
13+
"debug": "vitest run --inspect --no-file-parallelism --reporter=dot tests/lib",
1414
"cover": "npm run cover:test && npm run cover:report",
15-
"cover:test": "nyc npm run test:base -- --timeout 60000",
16-
"cover:report": "nyc report --reporter=html",
15+
"cover:test": "vitest run --coverage --reporter=dot tests/lib",
16+
"cover:report": "echo 'HTML coverage report available at ./coverage/index.html'",
1717
"lint": "eslint . && markdownlint \"**/*.md\"",
1818
"lint:fix": "eslint . --fix && markdownlint \"**/*.md\" --fix",
1919
"tsc": "tsc",
@@ -87,6 +87,7 @@
8787
"@types/xml-name-validator": "^4.0.3",
8888
"@typescript-eslint/parser": "^8.35.1",
8989
"@typescript-eslint/types": "^8.35.1",
90+
"@vitest/coverage-v8": "^3.2.4",
9091
"assert": "^2.1.0",
9192
"env-cmd": "^10.1.0",
9293
"esbuild": "^0.24.0",
@@ -106,8 +107,6 @@
106107
"globals": "^15.14.0",
107108
"jsdom": "^22.0.0",
108109
"markdownlint-cli": "^0.42.0",
109-
"mocha": "^10.7.3",
110-
"nyc": "^17.1.0",
111110
"pathe": "^1.1.2",
112111
"prettier": "^3.3.3",
113112
"typescript": "^5.7.2",

‎tests/.eslintrc.json‎

Lines changed: 0 additions & 5 deletions
This file was deleted.

‎tests/integrations/eslint-plugin-import.js‎

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,12 @@ const cp = require('child_process')
99
const path = require('path')
1010
const semver = require('semver')
1111

12+
const PLUGIN_DIR = path.join(__dirname, 'eslint-plugin-import')
1213
const ESLINT = `.${path.sep}node_modules${path.sep}.bin${path.sep}eslint`
1314

1415
describe('Integration with eslint-plugin-import', () => {
15-
let originalCwd
16-
17-
before(() => {
18-
originalCwd = process.cwd()
19-
process.chdir(path.join(__dirname, 'eslint-plugin-import'))
20-
cp.execSync('npm i', { stdio: 'inherit' })
21-
})
22-
after(() => {
23-
process.chdir(originalCwd)
16+
beforeAll(() => {
17+
cp.execSync('npm i', { cwd: PLUGIN_DIR, stdio: 'inherit' })
2418
})
2519

2620
// https://github.com/vuejs/eslint-plugin-vue/issues/21#issuecomment-308957697
@@ -41,6 +35,6 @@ describe('Integration with eslint-plugin-import', () => {
4135
return
4236
}
4337

44-
cp.execSync(`${ESLINT} a.vue`, { stdio: 'inherit' })
38+
cp.execSync(`${ESLINT} a.vue`, { cwd: PLUGIN_DIR,stdio: 'inherit' })
4539
})
4640
})

‎tests/integrations/flat-config.js‎

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,12 @@ const cp = require('child_process')
55
const path = require('path')
66
const semver = require('semver')
77

8+
const TARGET_DIR = path.join(__dirname, 'flat-config')
89
const ESLINT = `.${path.sep}node_modules${path.sep}.bin${path.sep}eslint`
910

1011
describe('Integration with flat config', () => {
11-
let originalCwd
12-
13-
before(() => {
14-
originalCwd = process.cwd()
15-
process.chdir(path.join(__dirname, 'flat-config'))
16-
cp.execSync('npm i -f', { stdio: 'inherit' })
17-
})
18-
after(() => {
19-
process.chdir(originalCwd)
12+
beforeAll(() => {
13+
cp.execSync('npm i -f', { cwd: TARGET_DIR, stdio: 'inherit' })
2014
})
2115

2216
it('should lint without errors', () => {
@@ -33,6 +27,7 @@ describe('Integration with flat config', () => {
3327

3428
const result = JSON.parse(
3529
cp.execSync(`${ESLINT} a.vue --format=json`, {
30+
cwd: TARGET_DIR,
3631
encoding: 'utf8'
3732
})
3833
)

‎vitest.config.ts‎

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
2+
import { defineConfig } from 'vitest/config';
3+
export default defineConfig({
4+
test: {
5+
include: [
6+
'tests/lib/**/*.js',
7+
'tests/integrations/**/*.js'
8+
],
9+
exclude: [
10+
'**/node_modules/**',
11+
'**/dist/**',
12+
'tests/fixtures/**',
13+
'tests/integrations/flat-config/eslint.config.js',
14+
'tests/lib/rules/no-unsupported-features/utils.js'
15+
],
16+
testTimeout: 60_000,
17+
globals: true,
18+
coverage: {
19+
provider: 'v8',
20+
include: ['lib/**/*.js'],
21+
exclude: [
22+
'tests/**',
23+
'dist/**',
24+
'tools/**',
25+
'node_modules/**'
26+
],
27+
reporter: ['text', 'lcov', 'json-summary', 'html'],
28+
all: true,
29+
reportsDirectory: './coverage'
30+
},
31+
},
32+
});

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /