Skip to content

chore(visitor-keys): migrate from jest to vitest #10773

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
900804d
Install `vitest`
aryaemami59 Feb 4, 2025
9e01b88
Rename `jest.config.js` to `vitest.config.mts`
aryaemami59 Feb 4, 2025
943cea4
chore(visitor-keys): migrate to `vitest`
aryaemami59 Feb 4, 2025
10b1fb1
Merge branch 'main' of https://github.com/typescript-eslint/typescrip…
aryaemami59 Mar 7, 2025
76b61ae
Update `vitest` to version 3.0.8
aryaemami59 Mar 7, 2025
9b31dc6
Remove `vitest/no-done-callback` as it is deprecated.
aryaemami59 Mar 7, 2025
78bd0b1
Fix Vitest config
aryaemami59 Mar 7, 2025
e6950ca
Include `vitest.config.mts` in `tsconfig.spec.json`
aryaemami59 Mar 8, 2025
37317ac
Add `vitest.config.mts` files to ESLint configuration
aryaemami59 Mar 8, 2025
1646f3d
Use `defineProject` instead of `defineConfig`
aryaemami59 Mar 10, 2025
fa20bb8
Simplify `workspace` and `coverage.exclude`
aryaemami59 Mar 10, 2025
7dbfcb0
Explicitly enable `resolveJsonModule`
aryaemami59 Mar 10, 2025
04a2e1a
Merge branch 'main' of https://github.com/typescript-eslint/typescrip…
aryaemami59 Mar 10, 2025
3ad8f00
Use `.replace` instead of `.split`
aryaemami59 Mar 10, 2025
3cecd1e
Type check `vitest.config.mts` files using project references.
aryaemami59 Mar 10, 2025
78aa2d5
Fix `@nx/vite/plugin` usage in `nx.json`
aryaemami59 Mar 10, 2025
9410d8b
Merge branch 'main' of https://github.com/typescript-eslint/typescrip…
aryaemami59 Mar 10, 2025
cc90c67
Update `@vitest/eslint-plugin` to version 1.1.37
aryaemami59 Mar 11, 2025
593c863
Fix Vitest config
aryaemami59 Mar 12, 2025
c05f436
Merge branch 'main' of https://github.com/typescript-eslint/typescrip…
aryaemami59 Mar 12, 2025
3dee53e
Merge branch 'main' of https://github.com/typescript-eslint/typescrip…
aryaemami59 Mar 15, 2025
6324278
Update `vite` to version 6.2.2
aryaemami59 Mar 15, 2025
008698e
Fix `typecheck` task
aryaemami59 Mar 16, 2025
c806ec9
Merge branch 'main' of https://github.com/typescript-eslint/typescrip…
aryaemami59 Mar 22, 2025
6600e84
Merge branch 'main' of https://github.com/typescript-eslint/typescrip…
aryaemami59 Mar 26, 2025
e8e1baf
Update `vitest` to version 3.0.9
aryaemami59 Mar 26, 2025
bd97ae0
Update `@vitest/eslint-plugin` to version 1.1.38
aryaemami59 Mar 26, 2025
86fa55b
Merge branch 'main' of https://github.com/typescript-eslint/typescrip…
aryaemami59 Mar 27, 2025
f36c314
Merge branch 'main' of https://github.com/typescript-eslint/typescrip…
aryaemami59 Mar 31, 2025
434d13f
Update `vitest` to version 3.1.1
aryaemami59 Mar 31, 2025
a90d7c3
Merge branch 'main' of https://github.com/typescript-eslint/typescrip…
aryaemami59 Mar 31, 2025
237a701
Merge branch 'main' of https://github.com/typescript-eslint/typescrip…
aryaemami59 Apr 2, 2025
53bf358
Move `nonIgnoredKeys` out of the `describe` block
aryaemami59 Apr 2, 2025
c81cbab
Update `@vitest/eslint-plugin` to version 1.1.39
aryaemami59 Apr 2, 2025
a61e8fc
Fix `knip` config
aryaemami59 Apr 3, 2025
94b1cd1
Update `vite` to version 6.2.5
aryaemami59 Apr 3, 2025
734dc65
Merge branch 'main' of https://github.com/typescript-eslint/typescrip…
aryaemami59 Apr 5, 2025
b497d0c
Merge branch 'main' of https://github.com/typescript-eslint/typescrip…
aryaemami59 Apr 7, 2025
e7ad033
Merge branch 'main' of https://github.com/typescript-eslint/typescrip…
aryaemami59 Apr 7, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ const restrictNamedDeclarations = {
const vitestFiles = [
'packages/eslint-plugin-internal/tests/**/*.test.{ts,tsx,cts,mts}',
'packages/typescript-eslint/tests/**/*.test.{ts,tsx,cts,mts}',
'packages/visitor-keys/tests/**/*.test.{ts,tsx,cts,mts}',
];

export default tseslint.config(
Expand Down
7 changes: 6 additions & 1 deletion knip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,14 @@ export default {
types: 'off',
unresolved: 'off',
},

vite: false,

Comment on lines +14 to +16
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It doesn't change the result but since we have vite in our devDependencies, the vite plugin for knip still infers that that this is a vite project which is not accurate, on top of that knip has to do a little bit less work which makes things a teeny tiny bit faster.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okie dokie, makes sense. I think as a followup once all projects are converted it might be good to look into removing both the devDependency and this project. Not a blocker for this PR IMO.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, We do need vite as a devDependency since We're using @nx/vite.

vitest: {
config: ['vitest.config.mts', 'packages/*/vitest.config.mts'],
config: ['vitest.config.mts'],
entry: ['tests/**/*.{bench,test,test-d}.?(c|m)ts?(x)'],
},

workspaces: {
'.': {
entry: ['tools/release/changelog-renderer.js', 'tools/scripts/**/*.mts'],
Expand Down
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@
"@typescript-eslint/types": "workspace:^",
"@typescript-eslint/typescript-estree": "workspace:^",
"@typescript-eslint/utils": "workspace:^",
"@vitest/coverage-v8": "^3.0.8",
"@vitest/eslint-plugin": "^1.1.37",
"@vitest/coverage-v8": "^3.1.1",
"@vitest/eslint-plugin": "^1.1.39",
"console-fail-test": "^0.5.0",
"cross-fetch": "^4.0.0",
"cspell": "^8.15.2",
Expand Down Expand Up @@ -126,8 +126,8 @@
"tsx": "*",
"typescript": ">=4.8.4 <5.9.0",
"typescript-eslint": "workspace:^",
"vite": "^6.2.2",
"vitest": "^3.0.8",
"vite": "^6.2.5",
"vitest": "^3.1.1",
"yargs": "17.7.2"
},
"resolutions": {
Expand Down
4 changes: 2 additions & 2 deletions packages/eslint-plugin-internal/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@
"prettier": "^3.2.5"
},
"devDependencies": {
"@vitest/coverage-v8": "^3.0.8",
"@vitest/coverage-v8": "^3.1.1",
"rimraf": "*",
"vitest": "^3.0.8"
"vitest": "^3.1.1"
}
}
4 changes: 2 additions & 2 deletions packages/typescript-eslint/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,12 @@
"typescript": ">=4.8.4 <5.9.0"
},
"devDependencies": {
"@vitest/coverage-v8": "^3.0.8",
"@vitest/coverage-v8": "^3.1.1",
"downlevel-dts": "*",
"prettier": "^3.2.5",
"rimraf": "*",
"typescript": "*",
"vitest": "^3.0.8"
"vitest": "^3.1.1"
},
"funding": {
"type": "opencollective",
Expand Down
7 changes: 0 additions & 7 deletions packages/visitor-keys/jest.config.js

This file was deleted.

10 changes: 5 additions & 5 deletions packages/visitor-keys/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,23 +41,23 @@
"build": "tsc -b tsconfig.build.json",
"postbuild": "downlevel-dts dist _ts4.3/dist --to=4.3",
"clean": "tsc -b tsconfig.build.json --clean",
"postclean": "rimraf dist && rimraf _ts3.4 && rimraf _ts4.3 && rimraf coverage",
"postclean": "rimraf dist/ _ts4.3/ coverage/",
"format": "prettier --write \"./**/*.{ts,mts,cts,tsx,js,mjs,cjs,jsx,json,md,css}\" --ignore-path ../../.prettierignore",
"lint": "npx nx lint",
"test": "jest",
"test": "vitest --run --config=$INIT_CWD/vitest.config.mts",
"check-types": "npx nx typecheck"
},
"dependencies": {
"@typescript-eslint/types": "8.29.1",
"eslint-visitor-keys": "^4.2.0"
},
"devDependencies": {
"@jest/types": "29.6.3",
"@vitest/coverage-v8": "^3.1.1",
"downlevel-dts": "*",
"jest": "29.7.0",
"prettier": "^3.2.5",
"rimraf": "*",
"typescript": "*"
"typescript": "*",
"vitest": "^3.1.1"
},
"funding": {
"type": "opencollective",
Expand Down
8 changes: 6 additions & 2 deletions packages/visitor-keys/project.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
{
"name": "visitor-keys",
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"type": "library",
"implicitDependencies": [],
"projectType": "library",
"root": "packages/visitor-keys",
"sourceRoot": "packages/visitor-keys/src",
"targets": {
"lint": {
"executor": "@nx/eslint:lint",
"outputs": ["{options.outputFile}"]
},
"test": {
"executor": "@nx/vite:test"
}
}
}
28 changes: 9 additions & 19 deletions packages/visitor-keys/tests/visitor-keys.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,31 +6,21 @@ const types = new Set(Object.keys(AST_NODE_TYPES));
const keys = new Set(Object.keys(visitorKeys));

describe('Every ast node type should have a visitor key defined', () => {
for (const type of types) {
it(type, () => {
expect(keys.has(type)).toBeTruthy();
});
}
it.for([...types])('%s', (type, { expect }) => {
expect(keys).toContain(type);
});
});

// these keys are defined by the base eslint module, and are not covered by our AST
const IGNORED_KEYS = new Set([
'ExperimentalRestProperty',
'ExperimentalSpreadProperty',
]);
describe('Every visitor key should have an ast node type defined', () => {
for (const key of keys) {
if (IGNORED_KEYS.has(key)) {
if (types.has(key)) {
it(`${key} should not be ignored as it has an AST_NODE_TYPE defined`, () => {
expect(true).toBeFalsy();
});
}
continue;
}

it(key, () => {
expect(types.has(key)).toBeTruthy();
});
}
const nonIgnoredKeys = [...keys].filter(key => !IGNORED_KEYS.has(key));

describe('Every visitor key should have an ast node type defined', () => {
it.for(nonIgnoredKeys)('%s', (key, { expect }) => {
expect(types).toContain(key);
});
});
2 changes: 1 addition & 1 deletion packages/visitor-keys/tsconfig.build.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"types": ["node"]
},
"include": ["src/**/*.ts"],
"exclude": ["jest.config.js", "src/**/*.spec.ts", "src/**/*.test.ts"],
"exclude": ["vitest.config.mts", "src/**/*.spec.ts", "src/**/*.test.ts"],
"references": [
{
"path": "../types/tsconfig.build.json"
Expand Down
9 changes: 7 additions & 2 deletions packages/visitor-keys/tsconfig.spec.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
"compilerOptions": {
"outDir": "../../dist/out-tsc/packages/visitor-keys",
"module": "NodeNext",
"types": ["jest", "node"]
"resolveJsonModule": true,
"types": ["node", "vitest/globals", "vitest/importMeta"]
},
"include": [
"jest.config.js",
"vitest.config.mts",
"package.json",
"src/**/*.test.ts",
"src/**/*.spec.ts",
"src/**/*.d.ts",
Expand All @@ -15,6 +17,9 @@
"references": [
{
"path": "./tsconfig.build.json"
},
{
"path": "../../tsconfig.spec.json"
}
]
}
21 changes: 21 additions & 0 deletions packages/visitor-keys/vitest.config.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import * as path from 'node:path';
import { defineProject, mergeConfig } from 'vitest/config';

import { vitestBaseConfig } from '../../vitest.config.base.mjs';
import packageJson from './package.json' with { type: 'json' };

const vitestConfig = mergeConfig(
vitestBaseConfig,

defineProject({
root: import.meta.dirname,

test: {
dir: path.join(import.meta.dirname, 'tests'),
name: packageJson.name.replace('@typescript-eslint/', ''),
root: import.meta.dirname,
},
}),
);

export default vitestConfig;
Loading