Movatterモバイル変換


[0]ホーム

URL:


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

chore(parser): migrate fromjest tovitest#10775

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 ourterms of service andprivacy 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 fromall commits
Commits
Show all changes
33 commits
Select commitHold shift + click to select a range
be86f32
Install `vitest`
aryaemami59Feb 3, 2025
676a6e8
Rename `jest.config.js` to `vitest.config.mts`
aryaemami59Feb 3, 2025
c4edfc3
chore(parser): migrate to `vitest`
aryaemami59Feb 3, 2025
74c34cf
Update `vitest` to version 3.0.8
aryaemami59Mar 7, 2025
3f4c980
Fix Vitest config
aryaemami59Mar 7, 2025
fd48d75
Include `vitest.config.mts` in `tsconfig.spec.json`
aryaemami59Mar 8, 2025
6a54a41
Add `vitest.config.mts` files to ESLint configuration
aryaemami59Mar 8, 2025
7e0dbde
Use `defineProject` instead of `defineConfig`
aryaemami59Mar 10, 2025
4a53aeb
Explicitly enable `resolveJsonModule`
aryaemami59Mar 10, 2025
d1fde12
Use `.replace` instead of `.split`
aryaemami59Mar 10, 2025
c23e047
Type check `vitest.config.mts` files using project references.
aryaemami59Mar 10, 2025
5b31d33
Fix Vitest config
aryaemami59Mar 12, 2025
d20e135
Fix `typecheck` task
aryaemami59Mar 16, 2025
bc70a51
Update `vitest` to version 3.0.9
aryaemami59Mar 26, 2025
158fe4e
Update `@vitest/eslint-plugin` to version 1.1.38
aryaemami59Mar 26, 2025
5538fac
Update `vitest` to version 3.1.1
aryaemami59Mar 31, 2025
793b981
Switch to `it.for`
aryaemami59Apr 2, 2025
a548c5c
Update `@vitest/eslint-plugin` to version 1.1.39
aryaemami59Apr 2, 2025
92e872d
Fix `knip` config
aryaemami59Apr 3, 2025
94daf56
Update `vite` to version 6.2.5
aryaemami59Apr 3, 2025
d0c9582
Merge branch 'main' of https://github.com/typescript-eslint/typescrip…
aryaemami59Apr 7, 2025
602bd41
Fix ESLint config
aryaemami59Apr 7, 2025
091ca59
Merge branch 'main' of https://github.com/typescript-eslint/typescrip…
aryaemami59Apr 7, 2025
9927f4d
Merge branch 'main' of https://github.com/typescript-eslint/typescrip…
aryaemami59Apr 10, 2025
c2cf955
Update `vite` to version 6.2.6
aryaemami59Apr 10, 2025
7eb7099
Update `@vitest/eslint-plugin` to version 1.1.40
aryaemami59Apr 10, 2025
ec7ea6d
Merge branch 'main' of https://github.com/typescript-eslint/typescrip…
aryaemami59Apr 10, 2025
8a430b4
Fix `parser` tests
aryaemami59Apr 10, 2025
7da9605
Update `@vitest/eslint-plugin` to version 1.1.42
aryaemami59Apr 10, 2025
2a78738
Merge branch 'main' of https://github.com/typescript-eslint/typescrip…
aryaemami59Apr 10, 2025
d90fde4
Enable the new `vitest/prefer-describe-function-title` rule
aryaemami59Apr 11, 2025
fe66cfd
Merge branch 'main' of https://github.com/typescript-eslint/typescrip…
aryaemami59Apr 11, 2025
eae45b1
Use `vitestPlugin.configs.env`
aryaemami59Apr 11, 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
10 changes: 4 additions & 6 deletionseslint.config.mjs
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -33,6 +33,8 @@ 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}',
'packages/parser/tests/lib/**/*.test.{ts,tsx,cts,mts}',
'packages/parser/tests/test-utils/**/*.{ts,tsx,cts,mts}',
];

export default tseslint.config(
Expand DownExpand Up@@ -379,18 +381,13 @@ export default tseslint.config(
// define the vitest globals for all test files
{
files: vitestFiles,
languageOptions: {
globals: {
...vitestPlugin.environments.env.globals,
},
},
...vitestPlugin.configs.env,
},
// test file specific configuration
{
files: [
'packages/*/tests/**/*.test.{ts,tsx,cts,mts}',
'packages/*/tests/**/test.{ts,tsx,cts,mts}',
'packages/parser/tests/**/*.{ts,tsx,cts,mts}',
'packages/integration-tests/tools/integration-test-base.ts',
'packages/integration-tests/tools/pack-packages.ts',
],
Expand DownExpand Up@@ -440,6 +437,7 @@ export default tseslint.config(
'vitest/no-identical-title': 'error',
'vitest/no-test-prefixes': 'error',
'vitest/no-test-return-statement': 'error',
'vitest/prefer-describe-function-title': 'error',
'vitest/prefer-each': 'error',
'vitest/prefer-spy-on': 'error',
'vitest/prefer-to-be': 'error',
Expand Down
5 changes: 5 additions & 0 deletionsknip.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -65,6 +65,11 @@ export default {
},
'packages/parser': {
ignore: ['tests/fixtures/**'],

vitest: {
config: ['vitest.config.mts'],
entry: ['tests/lib/**/*.{bench,test,test-d}.?(c|m)ts?(x)'],
},
},
'packages/rule-tester': {
ignore: ['typings/eslint.d.ts'],
Expand Down
4 changes: 2 additions & 2 deletionspackage.json
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -90,7 +90,7 @@
"@typescript-eslint/typescript-estree": "workspace:^",
"@typescript-eslint/utils": "workspace:^",
"@vitest/coverage-v8": "^3.1.1",
"@vitest/eslint-plugin": "^1.1.39",
"@vitest/eslint-plugin": "^1.1.42",
"console-fail-test": "^0.5.0",
"cross-fetch": "^4.0.0",
"cspell": "^8.15.2",
Expand DownExpand Up@@ -126,7 +126,7 @@
"tsx": "*",
"typescript": ">=4.8.4 <5.9.0",
"typescript-eslint": "workspace:^",
"vite": "^6.2.5",
"vite": "^6.2.6",
"vitest": "^3.1.1",
"yargs": "17.7.2"
},
Expand Down
8 changes: 0 additions & 8 deletionspackages/parser/jest.config.js
View file
Open in desktop

This file was deleted.

10 changes: 5 additions & 5 deletionspackages/parser/package.json
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -43,10 +43,10 @@
"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_ts4.3 && rimrafcoverage",
"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"
},
"peerDependencies": {
Expand All@@ -61,13 +61,13 @@
"debug": "^4.3.4"
},
"devDependencies": {
"@jest/types": "29.6.3",
"@vitest/coverage-v8": "^3.1.1",
"downlevel-dts": "*",
"glob": "*",
"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 deletionspackages/parser/project.json
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
{
"name": "parser",
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"type": "library",
"implicitDependencies": [],
"projectType": "library",
"root": "packages/parser",
"sourceRoot": "packages/parser/src",
"targets": {
"lint": {
"executor": "@nx/eslint:lint",
"outputs": ["{options.outputFile}"]
},
"test": {
"executor": "@nx/vite:test"
}
}
}
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
//Jest Snapshot v1, https://goo.gl/fbAQLP
//Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html

exports[`services fixtures/isolated-file.src 1`] = `
exports[`services>fixtures/isolated-file.src 1`] = `
{
"body": [
{
Expand Down
67 changes: 32 additions & 35 deletionspackages/parser/tests/lib/parser.test.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -9,7 +9,7 @@ import { parse, parseForESLint } from '../../src/parser';

describe('parser', () => {
beforeEach(() => {
jest.clearAllMocks();
vi.clearAllMocks();
});

it('parse() should return just the AST from parseForESLint()', () => {
Expand All@@ -24,7 +24,7 @@ describe('parser', () => {

it('parseAndGenerateServices() should be called with options', () => {
const code = 'const valid = true;';
const spy =jest.spyOn(typescriptESTree, 'parseAndGenerateServices');
const spy =vi.spyOn(typescriptESTree, 'parseAndGenerateServices');
const config: ParserOptions = {
ecmaFeatures: {
globalReturn: false,
Expand All@@ -36,11 +36,10 @@ describe('parser', () => {
extraFileExtensions: ['.foo'],
filePath: './isolated-file.src.ts',
project: 'tsconfig.json',
tsconfigRootDir: path.resolve(__dirname, '../fixtures/services'),
tsconfigRootDir: path.join(__dirname, '..', 'fixtures', 'services'),
};
parseForESLint(code, config);
expect(spy).toHaveBeenCalledTimes(1);
expect(spy).toHaveBeenLastCalledWith(code, {
expect(spy).toHaveBeenCalledExactlyOnceWith(code, {
comment: true,
jsx: false,
loc: true,
Expand All@@ -52,9 +51,9 @@ describe('parser', () => {

it('overrides `errorOnTypeScriptSyntacticAndSemanticIssues: false` when provided `errorOnTypeScriptSyntacticAndSemanticIssues: false`', () => {
const code = 'const valid = true;';
const spy =jest.spyOn(typescriptESTree, 'parseAndGenerateServices');
const spy =vi.spyOn(typescriptESTree, 'parseAndGenerateServices');
parseForESLint(code, { errorOnTypeScriptSyntacticAndSemanticIssues: true });
expect(spy).toHaveBeenCalledWith(code, {
expect(spy).toHaveBeenCalledExactlyOnceWith(code, {
comment: true,
ecmaFeatures: {},
errorOnTypeScriptSyntacticAndSemanticIssues: false,
Expand All@@ -68,9 +67,9 @@ describe('parser', () => {

it('sets `loggerFn: false` on typescript-estree when provided `warnOnUnsupportedTypeScriptVersion: false`', () => {
const code = 'const valid = true;';
const spy =jest.spyOn(typescriptESTree, 'parseAndGenerateServices');
const spy =vi.spyOn(typescriptESTree, 'parseAndGenerateServices');
parseForESLint(code, { warnOnUnsupportedTypeScriptVersion: false });
expect(spy).toHaveBeenCalledWith(code, {
expect(spy).toHaveBeenCalledExactlyOnceWith(code, {
comment: true,
ecmaFeatures: {},
errorOnTypeScriptSyntacticAndSemanticIssues: false,
Expand All@@ -86,9 +85,9 @@ describe('parser', () => {

it('sets `loggerFn: false` on typescript-estree when provided `warnOnUnsupportedTypeScriptVersion: true`', () => {
const code = 'const valid = true;';
const spy =jest.spyOn(typescriptESTree, 'parseAndGenerateServices');
const spy =vi.spyOn(typescriptESTree, 'parseAndGenerateServices');
parseForESLint(code, { warnOnUnsupportedTypeScriptVersion: true });
expect(spy).toHaveBeenCalledWith(code, {
expect(spy).toHaveBeenCalledExactlyOnceWith(code, {
comment: true,
ecmaFeatures: {},
errorOnTypeScriptSyntacticAndSemanticIssues: false,
Expand All@@ -103,18 +102,17 @@ describe('parser', () => {

it('should call analyze() with inferred analyze options when no analyze options are provided', () => {
const code = 'const valid = true;';
const spy =jest.spyOn(scopeManager, 'analyze');
const spy =vi.spyOn(scopeManager, 'analyze');
const config: ParserOptions = {
errorOnTypeScriptSyntacticAndSemanticIssues: false,
filePath: 'isolated-file.src.ts',
project: 'tsconfig.json',
tsconfigRootDir: path.join(__dirname, '../fixtures/services'),
tsconfigRootDir: path.join(__dirname, '..', 'fixtures', 'services'),
};

parseForESLint(code, config);

expect(spy).toHaveBeenCalledTimes(1);
expect(spy).toHaveBeenLastCalledWith(expect.anything(), {
expect(spy).toHaveBeenCalledExactlyOnceWith(expect.anything(), {
globalReturn: undefined,
jsxFragmentName: undefined,
jsxPragma: undefined,
Expand All@@ -123,7 +121,7 @@ describe('parser', () => {
});
});

it.each([
it.for([
['esnext.full', ScriptTarget.ESNext],
['es2022.full', ScriptTarget.ES2022],
['es2021.full', ScriptTarget.ES2021],
Expand All@@ -135,32 +133,32 @@ describe('parser', () => {
['es6', ScriptTarget.ES2015],
['lib', ScriptTarget.ES5],
['lib', undefined],
])(
] as const)(
'calls analyze() with `lib: [%s]` when the compiler options target is %s',
(lib, target) => {
([lib, target], { expect }) => {
const code = 'const valid = true;';
const spy =jest.spyOn(scopeManager, 'analyze');
const spy =vi.spyOn(scopeManager, 'analyze');
const config: ParserOptions = {
filePath: 'isolated-file.src.ts',
project: 'tsconfig.json',
tsconfigRootDir: path.join(__dirname, '../fixtures/services'),
tsconfigRootDir: path.join(__dirname, '..', 'fixtures', 'services'),
};

jest
.spyOn(typescriptESTree, 'parseAndGenerateServices')
.mockReturnValueOnce({
ast: {},
services: {
program: {
getCompilerOptions: () => ({ target }),
},
vi.spyOn(
typescriptESTree,
'parseAndGenerateServices',
).mockReturnValueOnce({
ast: {},
services: {
program: {
getCompilerOptions: () => ({ target }),
},
} as typescriptESTree.ParseAndGenerateServicesResult<typescriptESTree.TSESTreeOptions>);
},
} as typescriptESTree.ParseAndGenerateServicesResult<typescriptESTree.TSESTreeOptions>);

parseForESLint(code, config);

expect(spy).toHaveBeenCalledTimes(1);
expect(spy).toHaveBeenLastCalledWith(
expect(spy).toHaveBeenCalledExactlyOnceWith(
expect.anything(),
expect.objectContaining({
lib: [lib],
Expand All@@ -171,7 +169,7 @@ describe('parser', () => {

it('calls analyze() with the provided analyze options when analyze options are provided', () => {
const code = 'const valid = true;';
const spy =jest.spyOn(scopeManager, 'analyze');
const spy =vi.spyOn(scopeManager, 'analyze');
const config: ParserOptions = {
ecmaFeatures: {
globalReturn: false,
Expand All@@ -187,13 +185,12 @@ describe('parser', () => {
extraFileExtensions: ['.foo'],
filePath: 'isolated-file.src.ts',
project: 'tsconfig.json',
tsconfigRootDir: path.join(__dirname, '../fixtures/services'),
tsconfigRootDir: path.join(__dirname, '..', 'fixtures', 'services'),
};

parseForESLint(code, config);

expect(spy).toHaveBeenCalledTimes(1);
expect(spy).toHaveBeenLastCalledWith(expect.anything(), {
expect(spy).toHaveBeenCalledExactlyOnceWith(expect.anything(), {
globalReturn: false,
jsxFragmentName: 'Bar',
jsxPragma: 'Foo',
Expand Down
38 changes: 23 additions & 15 deletionspackages/parser/tests/lib/services.test.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
import { createProgram } from '@typescript-eslint/typescript-estree';
import * as glob from 'glob';
import fs from 'node:fs';
import fs from 'node:fs/promises';
import path from 'node:path';

import type { ParserOptions } from '../../src/parser';
Expand All@@ -15,7 +15,14 @@ import {
// Setup
//------------------------------------------------------------------------------

const FIXTURES_DIR = './tests/fixtures/services';
const FIXTURES_DIR = path.join(
__dirname,
'..',
'..',
'tests',
'fixtures',
'services',
);
const testFiles = glob.sync(`**/*.src.ts`, {
cwd: FIXTURES_DIR,
});
Expand All@@ -32,18 +39,19 @@ function createConfig(filename: string): ParserOptions {
// Tests
//------------------------------------------------------------------------------

describe('services', () => {
const program = createProgram(path.resolve(FIXTURES_DIR, 'tsconfig.json'));
testFiles.forEach(filename => {
const code = fs.readFileSync(path.join(FIXTURES_DIR, filename), 'utf8');
const config = createConfig(filename);
const snapshotName = formatSnapshotName(filename, FIXTURES_DIR, '.ts');
it(snapshotName, createSnapshotTestBlock(code, config));
it(`${snapshotName} services`, () => {
testServices(code, config);
});
it(`${snapshotName} services with provided program`, () => {
testServices(code, { ...config, program });
});
const program = createProgram(path.resolve(FIXTURES_DIR, 'tsconfig.json'));

describe.for(testFiles)('services', async filename => {
const code = await fs.readFile(path.join(FIXTURES_DIR, filename), {
encoding: 'utf-8',
});
const config = createConfig(filename);
const snapshotName = formatSnapshotName(filename, FIXTURES_DIR, '.ts');
it(snapshotName, createSnapshotTestBlock(code, config));
it(`${snapshotName} services`, () => {
testServices(code, config);
});
it(`${snapshotName} services with provided program`, () => {
testServices(code, { ...config, program });
});
});
Loading

[8]ページ先頭

©2009-2025 Movatter.jp