Skip to content

chore(type-utils): finish migrating to vitest #11104

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

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
12 changes: 12 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,18 @@ export default tseslint.config(
},
settings: { vitest: { typecheck: true } },
},
{
files: ['packages/*/tests/**/vitest-custom-matchers.d.ts'],
name: 'vitest-custom-matchers-declaration-files',
rules: {
'@typescript-eslint/no-empty-object-type': [
'error',
{ allowInterfaces: 'with-single-extends' },
],

'@typescript-eslint/no-explicit-any': 'off',
},
},
// plugin rule tests
{
files: [
Expand Down
9 changes: 9 additions & 0 deletions knip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,15 @@ export default {
},
'packages/type-utils': {
ignore: ['tests/fixtures/**', 'typings/typescript.d.ts'],

vitest: {
config: ['vitest.config.mts'],
entry: [
'tests/**/*.{bench,test,test-d}.?(c|m)ts?(x)',
'tests/test-utils/custom-matchers/custom-matchers.ts',
'tests/test-utils/custom-matchers/vitest-custom-matchers.d.ts',
],
},
},
'packages/typescript-estree': {
entry: ['src/use-at-your-own-risk.ts'],
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@
"@typescript-eslint/types": "workspace:^",
"@typescript-eslint/typescript-estree": "workspace:^",
"@typescript-eslint/utils": "workspace:^",
"@vitest/coverage-v8": "^3.1.1",
"@vitest/coverage-v8": "^3.1.2",
"@vitest/eslint-plugin": "^1.1.43",
"console-fail-test": "^0.5.0",
"cross-fetch": "^4.0.0",
Expand Down Expand Up @@ -114,8 +114,8 @@
"tsx": "*",
"typescript": ">=4.8.4 <5.9.0",
"typescript-eslint": "workspace:^",
"vite": "^6.3.3",
"vitest": "^3.1.1",
"vite": "^6.3.4",
"vitest": "^3.1.2",
"yargs": "17.7.2"
},
"resolutions": {
Expand Down
4 changes: 2 additions & 2 deletions packages/ast-spec/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,13 @@
"@babel/eslint-parser": "*",
"@microsoft/api-extractor": "^7.47.11",
"@typescript-eslint/typescript-estree": "workspace:*",
"@vitest/coverage-v8": "^3.1.1",
"@vitest/coverage-v8": "^3.1.2",
"glob": "*",
"jest-diff": "^29.7.0",
"prettier": "^3.2.5",
"pretty-format": "*",
"rimraf": "*",
"typescript": "*",
"vitest": "^3.1.1"
"vitest": "^3.1.2"
}
}
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.1.1",
"@vitest/coverage-v8": "^3.1.2",
"rimraf": "*",
"vitest": "^3.1.1"
"vitest": "^3.1.2"
}
}
4 changes: 2 additions & 2 deletions packages/eslint-plugin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
"@types/natural-compare": "*",
"@typescript-eslint/rule-schema-to-typescript-types": "8.31.1",
"@typescript-eslint/rule-tester": "8.31.1",
"@vitest/coverage-v8": "^3.1.1",
"@vitest/coverage-v8": "^3.1.2",
"ajv": "^6.12.6",
"cross-fetch": "*",
"eslint": "*",
Expand All @@ -93,7 +93,7 @@
"tsx": "*",
"typescript": "*",
"unist-util-visit": "^5.0.0",
"vitest": "^3.1.1"
"vitest": "^3.1.2"
},
"peerDependencies": {
"@typescript-eslint/parser": "^8.0.0 || ^8.0.0-alpha.0",
Expand Down
4 changes: 2 additions & 2 deletions packages/integration-tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"check-types": "npx nx typecheck"
},
"devDependencies": {
"@vitest/coverage-v8": "^3.1.1",
"vitest": "^3.1.1"
"@vitest/coverage-v8": "^3.1.2",
"vitest": "^3.1.2"
}
}
4 changes: 2 additions & 2 deletions packages/parser/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,12 @@
"debug": "^4.3.4"
},
"devDependencies": {
"@vitest/coverage-v8": "^3.1.1",
"@vitest/coverage-v8": "^3.1.2",
"glob": "*",
"prettier": "^3.2.5",
"rimraf": "*",
"typescript": "*",
"vitest": "^3.1.1"
"vitest": "^3.1.2"
},
"funding": {
"type": "opencollective",
Expand Down
4 changes: 2 additions & 2 deletions packages/rule-schema-to-typescript-types/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@
"prettier": "^3.2.5"
},
"devDependencies": {
"@vitest/coverage-v8": "^3.1.1",
"@vitest/coverage-v8": "^3.1.2",
"typescript": "*",
"vitest": "^3.1.1"
"vitest": "^3.1.2"
},
"funding": {
"type": "opencollective",
Expand Down
6 changes: 3 additions & 3 deletions packages/rule-tester/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,16 +61,16 @@
"devDependencies": {
"@types/json-stable-stringify-without-jsonify": "^1.0.2",
"@types/lodash.merge": "4.6.9",
"@vitest/coverage-v8": "^3.1.1",
"chai": "^4.4.1",
"@vitest/coverage-v8": "^3.1.2",
"chai": "^5.2.0",
"eslint-visitor-keys": "^4.2.0",
"espree": "^10.3.0",
"esprima": "^4.0.1",
"mocha": "^10.4.0",
"sinon": "^16.1.3",
"source-map-support": "^0.5.21",
"typescript": "*",
"vitest": "^3.1.1"
"vitest": "^3.1.2"
},
"funding": {
"type": "opencollective",
Expand Down
4 changes: 2 additions & 2 deletions packages/scope-manager/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,12 @@
},
"devDependencies": {
"@typescript-eslint/typescript-estree": "8.31.1",
"@vitest/coverage-v8": "^3.1.1",
"@vitest/coverage-v8": "^3.1.2",
"glob": "*",
"prettier": "^3.2.5",
"pretty-format": "*",
"typescript": "*",
"vitest": "^3.1.1"
"vitest": "^3.1.2"
},
"funding": {
"type": "opencollective",
Expand Down
8 changes: 4 additions & 4 deletions packages/type-utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@
],
"scripts": {
"build": "tsc -b tsconfig.build.json",
"clean": "tsc -b tsconfig.build.json --clean",
"postclean": "rimraf dist/ coverage/",
"clean": "rimraf dist/ coverage/",
"format": "prettier --write \"./**/*.{ts,mts,cts,tsx,js,mjs,cjs,jsx,json,md,css}\" --ignore-path ../../.prettierignore",
"lint": "npx nx lint",
"test": "vitest --run --config=$INIT_CWD/vitest.config.mts",
Expand All @@ -56,12 +55,13 @@
},
"devDependencies": {
"@typescript-eslint/parser": "8.31.1",
"@vitest/coverage-v8": "^3.1.1",
"@vitest/coverage-v8": "^3.1.2",
"ajv": "^6.12.6",
"eslint": "*",
"prettier": "^3.2.5",
"rimraf": "*",
"typescript": "*",
"vitest": "^3.1.1"
"vitest": "^3.1.2"
},
"funding": {
"type": "opencollective",
Expand Down
24 changes: 17 additions & 7 deletions packages/type-utils/tests/TypeOrValueSpecifier.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,21 @@ describe('TypeOrValueSpecifier', () => {
[{ from: 'file', name: ['MyType', 42] }],
[{ from: 'file', name: ['MyType', 'MyType'] }],
[{ from: 'file', name: [] }],
[{ from: 'file', path: './filename.js' }],
[{ from: 'file', path: `${ROOT_DIR}/filename.js` }],
[{ from: 'file', name: 'MyType', path: 42 }],
[{ from: 'file', name: ['MyType', 'MyType'], path: './filename.js' }],
[{ from: 'file', name: [], path: './filename.js' }],
[
{
from: 'file',
name: ['MyType', 'MyType'],
path: `${ROOT_DIR}/filename.js`,
},
],
[{ from: 'file', name: [], path: `${ROOT_DIR}/filename.js` }],
[
{
from: 'file',
name: ['MyType', 'myValue'],
path: ['./filename.js', './another-file.js'],
path: [`${ROOT_DIR}/filename.js`, `${ROOT_DIR}/another-file.js`],
},
],
[{ from: 'file', name: 'MyType', unrelatedProperty: '' }],
Expand Down Expand Up @@ -122,7 +128,7 @@ describe('TypeOrValueSpecifier', () => {
{
from: 'package',
name: ['MyType', 'myValue'],
package: ['jquery', './another-file.js'],
package: ['jquery', `${ROOT_DIR}/another-file.js`],
},
],
[
Expand Down Expand Up @@ -293,14 +299,18 @@ describe('TypeOrValueSpecifier', () => {
],
[
'interface Foo {prop: string}; type Test = Foo;',
{ from: 'file', name: 'Foo', path: 'tests/fixtures/wrong-file.ts' },
{
from: 'file',
name: 'Foo',
path: `${ROOT_DIR}/tests/fixtures/wrong-file.ts`,
},
],
[
'interface Foo {prop: string}; type Test = Foo;',
{
from: 'file',
name: ['Foo', 'Bar'],
path: 'tests/fixtures/wrong-file.ts',
path: `${ROOT_DIR}/tests/fixtures/wrong-file.ts`,
},
],
] as const satisfies [string, TypeOrValueSpecifier][])(
Expand Down
3 changes: 1 addition & 2 deletions packages/type-utils/tests/containsAllTypesByName.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { parseForESLint } from '@typescript-eslint/parser';
import path from 'node:path';

import { containsAllTypesByName } from '../src';
import { expectToHaveParserServices } from './test-utils/expectToHaveParserServices';

describe(containsAllTypesByName, () => {
const rootDir = path.join(__dirname, 'fixtures');
Expand All @@ -18,7 +17,7 @@ describe(containsAllTypesByName, () => {
project: './tsconfig.json',
tsconfigRootDir: rootDir,
});
expectToHaveParserServices(services);
assert.toHaveParserServices(services);
const declaration = ast.body[0] as TSESTree.TSTypeAliasDeclaration;
return services.getTypeAtLocation(declaration.id);
}
Expand Down
3 changes: 1 addition & 2 deletions packages/type-utils/tests/discriminateAnyType.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { parseForESLint } from '@typescript-eslint/parser';
import path from 'node:path';

import { AnyType, discriminateAnyType } from '../src';
import { expectToHaveParserServices } from './test-utils/expectToHaveParserServices';

type GetNode = (ast: TSESTree.Program) => TSESTree.Node;

Expand All @@ -25,7 +24,7 @@ describe(discriminateAnyType, () => {
project: './tsconfig.json',
tsconfigRootDir: rootDir,
});
expectToHaveParserServices(services);
assert.toHaveParserServices(services);
const node = getNode(ast);
const type = services.getTypeAtLocation(getNode(ast));
return {
Expand Down
3 changes: 1 addition & 2 deletions packages/type-utils/tests/getTypeName.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { parseForESLint } from '@typescript-eslint/parser';
import path from 'node:path';

import { getTypeName } from '../src';
import { expectToHaveParserServices } from './test-utils/expectToHaveParserServices';

describe(getTypeName, () => {
function getTypes(code: string): { checker: ts.TypeChecker; type: ts.Type } {
Expand All @@ -18,7 +17,7 @@ describe(getTypeName, () => {
project: './tsconfig.json',
tsconfigRootDir: rootDir,
});
expectToHaveParserServices(services);
assert.toHaveParserServices(services);
const checker = services.program.getTypeChecker();
const declaration = ast.body[0] as TSESTree.TSTypeAliasDeclaration;

Expand Down
3 changes: 1 addition & 2 deletions packages/type-utils/tests/isSymbolFromDefaultLibrary.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { parseForESLint } from '@typescript-eslint/parser';
import path from 'node:path';

import { isSymbolFromDefaultLibrary } from '../src';
import { expectToHaveParserServices } from './test-utils/expectToHaveParserServices';

describe(isSymbolFromDefaultLibrary, () => {
const rootDir = path.join(__dirname, 'fixtures');
Expand All @@ -21,7 +20,7 @@ describe(isSymbolFromDefaultLibrary, () => {
project: './tsconfig.json',
tsconfigRootDir: rootDir,
});
expectToHaveParserServices(services);
assert.toHaveParserServices(services);
const declaration = ast.body[0] as TSESTree.TSTypeAliasDeclaration;
const type = services.getTypeAtLocation(declaration.id);
return { program: services.program, symbol: type.getSymbol() };
Expand Down
Loading