Skip to content

chore(scope-manager): finish migrating to vitest #11111

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 9 commits into
base: main
Choose a base branch
from
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
2 changes: 2 additions & 0 deletions knip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ export default {
entry: [
'tests/**/*.{bench,test,test-d}.?(c|m)ts?(x)',
'tests/test-utils/serializers/index.ts',
'tests/test-utils/custom-matchers/custom-matchers.ts',
'tests/test-utils/custom-matchers/vitest-custom-matchers.d.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
9 changes: 5 additions & 4 deletions packages/scope-manager/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
],
"scripts": {
"build": "tsc -b tsconfig.build.json",
"clean": "rimraf dist/ _ts4.3/ coverage/",
"clean": "rimraf dist/ coverage/",
"clean-fixtures": "rimraf -g \"./src/**/fixtures/**/snapshots\"",
"format": "prettier --write \"./**/*.{ts,mts,cts,tsx,js,mjs,cjs,jsx,json,md,css}\" --ignore-path ../../.prettierignore",
"generate-lib": "npx nx generate-lib repo",
Expand All @@ -52,12 +52,13 @@
},
"devDependencies": {
"@typescript-eslint/typescript-estree": "8.31.1",
"@vitest/coverage-v8": "^3.1.1",
"@vitest/coverage-v8": "^3.1.2",
"@vitest/pretty-format": "^3.1.2",
"glob": "*",
"prettier": "^3.2.5",
"pretty-format": "*",
"rimraf": "*",
"typescript": "*",
"vitest": "^3.1.1"
"vitest": "^3.1.2"
},
"funding": {
"type": "opencollective",
Expand Down
12 changes: 4 additions & 8 deletions packages/scope-manager/tests/eslint-scope/arguments.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
import {
expectToBeFunctionScope,
expectToBeGlobalScope,
getRealVariables,
parseAndAnalyze,
} from '../test-utils';
import { ScopeType } from '../../src/index.js';
import { getRealVariables, parseAndAnalyze } from '../test-utils/index.js';

describe('arguments', () => {
it('arguments are correctly materialized', () => {
Expand All @@ -17,13 +13,13 @@ describe('arguments', () => {

let scope = scopeManager.scopes[0];
let variables = getRealVariables(scope.variables);
expectToBeGlobalScope(scope);
assert.isScopeOfType(scope, ScopeType.global);
expect(variables).toHaveLength(0);
expect(scope.references).toHaveLength(0);

scope = scopeManager.scopes[1];
variables = getRealVariables(scope.variables);
expectToBeFunctionScope(scope);
assert.isScopeOfType(scope, ScopeType.function);
expect(variables).toHaveLength(1);
expect(variables[0].name).toBe('arguments');
expect(scope.references).toHaveLength(1);
Expand Down
20 changes: 7 additions & 13 deletions packages/scope-manager/tests/eslint-scope/catch-scope.test.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
import {
expectToBeBlockScope,
expectToBeCatchScope,
expectToBeFunctionScope,
expectToBeGlobalScope,
getRealVariables,
parseAndAnalyze,
} from '../test-utils';
import { ScopeType } from '../../src/index.js';
import { getRealVariables, parseAndAnalyze } from '../test-utils/index.js';

describe('catch', () => {
it('creates scope', () => {
Expand All @@ -21,33 +15,33 @@ describe('catch', () => {

let scope = scopeManager.scopes[0];
let variables = getRealVariables(scope.variables);
expectToBeGlobalScope(scope);
assert.isScopeOfType(scope, ScopeType.global);
expect(variables).toHaveLength(0);
expect(scope.references).toHaveLength(0);

scope = scopeManager.scopes[1];
variables = getRealVariables(scope.variables);
expectToBeFunctionScope(scope);
assert.isScopeOfType(scope, ScopeType.function);
expect(variables).toHaveLength(1);
expect(variables[0].name).toBe('arguments');
expect(scope.references).toHaveLength(0);

scope = scopeManager.scopes[2];
variables = getRealVariables(scope.variables);
expectToBeBlockScope(scope);
assert.isScopeOfType(scope, ScopeType.block);
expect(variables).toHaveLength(0);
expect(scope.references).toHaveLength(0);

scope = scopeManager.scopes[3];
variables = getRealVariables(scope.variables);
expectToBeCatchScope(scope);
assert.isScopeOfType(scope, ScopeType.catch);
expect(variables).toHaveLength(1);
expect(variables[0].name).toBe('e');
expect(scope.references).toHaveLength(0);

scope = scopeManager.scopes[4];
variables = getRealVariables(scope.variables);
expectToBeBlockScope(scope);
assert.isScopeOfType(scope, ScopeType.block);
expect(variables).toHaveLength(0);
expect(scope.references).toHaveLength(0);
});
Expand Down
42 changes: 24 additions & 18 deletions packages/scope-manager/tests/eslint-scope/class-fields.test.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,18 @@
import {
expectToBeClassFieldInitializerScope,
expectToBeClassScope,
expectToBeGlobalScope,
expectToBeIdentifier,
parseAndAnalyze,
} from '../test-utils';
import { AST_NODE_TYPES } from '@typescript-eslint/types';

import { ScopeType } from '../../src/index.js';
import { parseAndAnalyze } from '../test-utils/index.js';

describe('Class fields', () => {
it('class C { f = g }', () => {
const { scopeManager } = parseAndAnalyze('class C { f = g }');

const globalScope = scopeManager.scopes[0];
expectToBeGlobalScope(globalScope);
assert.isScopeOfType(globalScope, ScopeType.global);

const classScope = globalScope.childScopes[0];
// should create a class scope
expectToBeClassScope(classScope);
assert.isScopeOfType(classScope, ScopeType.class);
// The class scope has no references
expect(classScope.references).toHaveLength(0);
// The class scope has only the variable 'C'; it doesn't have the field name 'f'.
Expand All @@ -24,9 +21,15 @@ describe('Class fields', () => {

const classFieldInitializerScope = classScope.childScopes[0];
// The class scope has a class-field-initializer scope.
expectToBeClassFieldInitializerScope(classFieldInitializerScope);
assert.isScopeOfType(
classFieldInitializerScope,
ScopeType.classFieldInitializer,
);
// The class-field-initializer scope's block is the node of the field initializer.
expectToBeIdentifier(classFieldInitializerScope.block);
assert.isNodeOfType(
classFieldInitializerScope.block,
AST_NODE_TYPES.Identifier,
);
expect(classFieldInitializerScope.block.name).toBe('g');
// The class-field-initializer scope's variableScope is itself.
expect(classFieldInitializerScope.variableScope).toBe(
Expand All @@ -43,11 +46,11 @@ describe('Class fields', () => {
const { scopeManager } = parseAndAnalyze('class C { f }');

const globalScope = scopeManager.scopes[0];
expectToBeGlobalScope(globalScope);
assert.isScopeOfType(globalScope, ScopeType.global);

const classScope = globalScope.childScopes[0];
// should create a class scope
expectToBeClassScope(classScope);
assert.isScopeOfType(classScope, ScopeType.class);
// The class scope has no references
expect(classScope.references).toHaveLength(0);
// The class scope has no child scopes; fields that don't have initializers don't create any class-field-initializer scopes.
Expand All @@ -61,11 +64,11 @@ describe('Class fields', () => {
const { scopeManager } = parseAndAnalyze('class C { [fname] }');

const globalScope = scopeManager.scopes[0];
expectToBeGlobalScope(globalScope);
assert.isScopeOfType(globalScope, ScopeType.global);

const classScope = globalScope.childScopes[0];
// should create a class scope
expectToBeClassScope(classScope);
assert.isScopeOfType(classScope, ScopeType.class);
// The class scope has only the reference `fname`.
expect(classScope.references).toHaveLength(1);
// The class scope has no child scopes; fields that don't have initializers don't create any class-field-initializer scopes.
Expand All @@ -76,18 +79,21 @@ describe('Class fields', () => {
const { scopeManager } = parseAndAnalyze('class C { [fname] = value }');

const globalScope = scopeManager.scopes[0];
expectToBeGlobalScope(globalScope);
assert.isScopeOfType(globalScope, ScopeType.global);

const classScope = globalScope.childScopes[0];
// should create a class scope
expectToBeClassScope(classScope);
assert.isScopeOfType(classScope, ScopeType.class);
// The class scope has only the reference `fname`; it doesn't have the reference 'value'.
expect(classScope.references).toHaveLength(1);
expect(classScope.references[0].identifier.name).toBe('fname');

const classFieldInitializerScope = classScope.childScopes[0];
// The class scope has a class-field-initializer scope.
expectToBeClassFieldInitializerScope(classFieldInitializerScope);
assert.isScopeOfType(
classFieldInitializerScope,
ScopeType.classFieldInitializer,
);
// The class-field-initializer scope has the reference 'value'.
expect(classFieldInitializerScope.references).toHaveLength(1);
expect(classFieldInitializerScope.references[0].identifier.name).toBe(
Expand Down
Loading