Skip to content

Commit 2c29d7a

Browse files
authored
test: move to vitest (#269)
* feat: move `parser-options` to `vitest` * feat: move `crlf` to `vitest` * chore: update * feat: move `define-document-visitor` to `vitest` * feat: move `define-custom-blocks-visitor` to `vitest` * feat: move `parser-options-project` to `vitest` * feat: move `document-fragment` to `vitest` * fix: correct ParserServices type * feat: move `tokens` to `vitest` * refactor: use `replacer` in `test-utils` * chore: up * feat: enhance test-utils * refactor: move `variables-references` to `vitest` * feat: move `ast` to `vitest` * feat: move `index` to `vitest` * refactor: move all test to `vitest` * chore: enhance type definition * chore: uninstall mocha * test: update * chore: update * chore: update ci * fix: update something maybe wrong * chore: update, try fix ci * chore: up * ci: try fix * chore: up * ci: fix * chore: use vite^6 for node18 test * chore: update timeout config * chore: update * chore: flat diff * test: fix incorrect `fallback`
1 parent 62321db commit 2c29d7a

25 files changed

+638
-560
lines changed

.github/workflows/CI.yml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,8 @@ jobs:
5555
run: npm install -f
5656
- name: Install ESLint v${{ matrix.eslint }}
5757
run: node scripts/ci-install-eslint ${{ matrix.eslint }}
58-
- name: Build
59-
run: npm run -s build
6058
- name: Test
61-
run: npm run -s test:mocha
59+
run: npm run -s test
6260
test-for-old-eslint:
6361
name: Test
6462
strategy:
@@ -82,4 +80,4 @@ jobs:
8280
- name: Install ESLint v${{ matrix.eslint }}
8381
run: node scripts/ci-install-eslint ${{ matrix.eslint }}
8482
- name: Test
85-
run: npm run -s test:debug
83+
run: npm run -s test

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
/.nyc_output
21
/.temp
32
/coverage
43
node_modules

eslint.config.mjs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ const compat = new FlatCompat({
2222
export default [
2323
{
2424
ignores: [
25-
".nyc_output",
2625
".temp",
2726
"coverage",
2827
"**/node_modules",
@@ -64,7 +63,7 @@ export default [
6463
},
6564

6665
loggerFn: false,
67-
project: "tsconfig.json",
66+
project: ["tsconfig.json", "tsconfig.test.json"],
6867
},
6968
},
7069

package.json

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,12 @@
3030
"@eslint/js": "^9.19.0",
3131
"@types/debug": "^4.1.7",
3232
"@types/estree": "^1.0.0",
33-
"@types/mocha": "^9.0.0",
3433
"@types/node": "^18.8.4",
3534
"@types/semver": "^7.3.12",
3635
"@typescript-eslint/eslint-plugin": "^8.22.0",
3736
"@typescript-eslint/parser": "^8.22.0",
37+
"@vitest/coverage-v8": "^3.2.4",
38+
"@vitest/ui": "^3.2.4",
3839
"chokidar": "^3.5.2",
3940
"cross-spawn": "^7.0.3",
4041
"dts-bundle": "^0.7.3",
@@ -47,10 +48,7 @@
4748
"eslint-plugin-unicorn": "^57.0.0",
4849
"fs-extra": "^10.0.0",
4950
"jsonc-eslint-parser": "^2.0.3",
50-
"mocha": "^9.1.3",
5151
"npm-run-all": "^4.1.5",
52-
"nyc": "^15.1.0",
53-
"opener": "^1.5.2",
5452
"prettier": "^3.4.2",
5553
"rimraf": "^3.0.2",
5654
"rollup": "^2.60.0",
@@ -59,20 +57,19 @@
5957
"rollup-plugin-sourcemaps": "^0.6.3",
6058
"ts-node": "^10.9.2",
6159
"typescript": "~5.7.3",
60+
"vite": "^6.3.5",
61+
"vitest": "^3.2.4",
6262
"wait-on": "^6.0.0",
6363
"warun": "^1.0.0"
6464
},
6565
"scripts": {
6666
"prebuild": "npm run -s clean",
6767
"build": "tsc --module es2015 && rollup -c -o index.js && dts-bundle --name vue-eslint-parser --main .temp/index.d.ts --out ../index.d.ts",
68-
"clean": "rimraf .nyc_output .temp coverage index.*",
69-
"coverage": "opener ./coverage/lcov-report/index.html",
68+
"clean": "rimraf .temp index.*",
69+
"coverage": "vitest --coverage --ui",
7070
"lint": "eslint src test package.json",
71-
"pretest": "run-s build lint",
72-
"test": "npm run -s test:mocha",
73-
"test:mocha": "mocha --require ts-node/register \"test/*.js\" --reporter dot --timeout 60000",
74-
"test:cover": "nyc mocha \"test/*.js\" --reporter dot --timeout 60000",
75-
"test:debug": "mocha --require ts-node/register/transpile-only \"test/*.js\" --reporter dot --timeout 60000",
71+
"test": "vitest",
72+
"test:cover": "vitest --coverage",
7673
"update-fixtures": "ts-node --transpile-only scripts/update-fixtures-ast.js && ts-node --transpile-only scripts/update-fixtures-document-fragment.js",
7774
"preversion": "npm test",
7875
"version": "npm run -s build",
@@ -81,9 +78,7 @@
8178
"watch": "run-p watch:*",
8279
"watch:tsc": "tsc --module es2015 --watch",
8380
"watch:rollup": "wait-on .temp/index.js && rollup -c -o index.js --watch",
84-
"watch:test": "wait-on index.js && warun index.js \"test/*.js\" \"test/fixtures/ast/*/*.json\" \"test/fixtures/*\" --debounce 1000 --no-initial -- nyc mocha \"test/*.js\" --reporter dot --timeout 10000",
85-
"watch:update-ast": "wait-on index.js && warun index.js \"test/fixtures/ast/*/*.vue\" -- ts-node scripts/update-fixtures-ast.js",
86-
"watch:coverage-report": "wait-on coverage/lcov-report/index.html && opener coverage/lcov-report/index.html"
81+
"watch:update-ast": "wait-on index.js && warun index.js \"test/fixtures/ast/*/*.vue\" -- ts-node scripts/update-fixtures-ast.js"
8782
},
8883
"repository": {
8984
"type": "git",

scripts/ci-install-eslint.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ function sh(command) {
3030

3131
// Install ESLint of the requested version
3232
await sh(`npm install eslint@${requestedVersionSpec} -f`)
33+
if (Number(requestedVersion) < 9)
34+
await sh(`npm install @types/eslint -D -f`)
3335

3436
// Install ESLint submodule of the requested version
3537
// const installedVersion = require("eslint/package.json").version

src/ast/nodes.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import type { ParseError } from "./errors"
88
import type { HasLocation } from "./locations"
99
import type { Token } from "./tokens"
1010
import type { TSESTree } from "@typescript-eslint/utils"
11+
import type { ParserServices } from "../parser-services"
1112

1213
//------------------------------------------------------------------------------
1314
// Common
@@ -70,7 +71,7 @@ export type ESLintNode =
7071
*/
7172
export interface ESLintExtendedProgram {
7273
ast: ESLintProgram
73-
services?: {}
74+
services?: ParserServices
7475
visitorKeys?: { [type: string]: string[] }
7576
scopeManager?: ScopeManager
7677
}

src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ export function parseForESLint(
8484
* @param options The parser options.
8585
* @returns The parsing result.
8686
*/
87-
export function parse(code: string, options: any): AST.ESLintProgram {
87+
export function parse(code: string, options?: any): AST.ESLintProgram {
8888
return parseForESLint(code, options).ast
8989
}
9090

src/parser-services.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ export interface ParserServices {
8383
| ((lang: string | null, customBlock: VElement) => boolean)
8484
create: CustomBlockVisitorFactory
8585
},
86-
scriptVisitor: { [key: string]: (...args: any) => void },
86+
scriptVisitor?: { [key: string]: (...args: any) => void },
8787
): { [key: string]: (...args: any) => void }
8888

8989
/**
@@ -262,7 +262,7 @@ export function define(
262262
| ((lang: string | null, customBlock: VElement) => boolean)
263263
create: CustomBlockVisitorFactory
264264
},
265-
scriptVisitor: { [key: string]: (...args: any) => void },
265+
scriptVisitor?: { [key: string]: (...args: any) => void },
266266
): { [key: string]: (...args: any) => void } {
267267
if (scriptVisitor == null) {
268268
scriptVisitor = {} //eslint-disable-line no-param-reassign

0 commit comments

Comments
 (0)