Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 8f79ad0

Browse files
authored
chore(typescript-eslint): finish migrating to vitest (typescript-eslint#11137)
* update `vitest` to version 3.1.2 * chore(typescript-eslint): finish migrating to `vitest` * update `vitest` to version 3.1.3 * fix unit-tests
1 parent ff2a785 commit 8f79ad0

File tree

4 files changed

+258
-185
lines changed

4 files changed

+258
-185
lines changed

eslint.config.mjs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,7 @@ export default tseslint.config(
395395
},
396396
settings: { vitest: { typecheck: true } },
397397
},
398+
398399
{
399400
files: ['packages/*/tests/**/vitest-custom-matchers.d.ts'],
400401
name: 'vitest-custom-matchers-declaration-files',
@@ -407,6 +408,7 @@ export default tseslint.config(
407408
'@typescript-eslint/no-explicit-any': 'off',
408409
},
409410
},
411+
410412
// plugin rule tests
411413
{
412414
files: [

packages/typescript-eslint/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,7 @@
4343
],
4444
"scripts": {
4545
"build": "tsc -b tsconfig.build.json",
46-
"clean": "tsc -b tsconfig.build.json --clean",
47-
"postclean": "rimraf dist/ coverage/",
46+
"clean": "rimraf dist/ coverage/",
4847
"format": "prettier --write \"./**/*.{ts,mts,cts,tsx,js,mjs,cjs,jsx,json,md,css}\" --ignore-path ../../.prettierignore",
4948
"lint": "nx lint",
5049
"test": "vitest --run --config=$INIT_CWD/vitest.config.mts",

packages/typescript-eslint/tests/config-helper.test.ts

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { TSESLint } from '@typescript-eslint/utils';
22

3-
import tseslint from '../src/index';
3+
import tseslint from '../src/index.js';
44

55
describe('config helper', () => {
66
it('works without extends', () => {
@@ -10,7 +10,7 @@ describe('config helper', () => {
1010
ignores: ['ignored'],
1111
rules: { rule: 'error' },
1212
}),
13-
).toEqual([
13+
).toStrictEqual([
1414
{
1515
files: ['file'],
1616
ignores: ['ignored'],
@@ -25,7 +25,7 @@ describe('config helper', () => {
2525
extends: [{ rules: { rule1: 'error' } }, { rules: { rule2: 'error' } }],
2626
rules: { rule: 'error' },
2727
}),
28-
).toEqual([
28+
).toStrictEqual([
2929
{ rules: { rule1: 'error' } },
3030
{ rules: { rule2: 'error' } },
3131
{ rules: { rule: 'error' } },
@@ -40,7 +40,7 @@ describe('config helper', () => {
4040
ignores: ['common-ignored'],
4141
rules: { rule: 'error' },
4242
}),
43-
).toEqual([
43+
).toStrictEqual([
4444
{
4545
files: ['common-file'],
4646
ignores: ['common-ignored'],
@@ -62,7 +62,7 @@ describe('config helper', () => {
6262
it('throws error containing config name when some extensions are undefined', () => {
6363
const extension: TSESLint.FlatConfig.Config = { rules: { rule1: 'error' } };
6464

65-
expect(() =>
65+
expect(() => {
6666
tseslint.config(
6767
{
6868
extends: [extension],
@@ -79,8 +79,8 @@ describe('config helper', () => {
7979
name: 'my-config-2',
8080
rules: { rule: 'error' },
8181
},
82-
),
83-
).toThrow(
82+
);
83+
}).toThrow(
8484
'tseslint.config(): Config at index 1, named "my-config-2", contains non-object ' +
8585
'extensions at the following indices: 0, 2',
8686
);
@@ -89,7 +89,7 @@ describe('config helper', () => {
8989
it('throws error without config name when some extensions are undefined', () => {
9090
const extension: TSESLint.FlatConfig.Config = { rules: { rule1: 'error' } };
9191

92-
expect(() =>
92+
expect(() => {
9393
tseslint.config(
9494
{
9595
extends: [extension],
@@ -105,8 +105,8 @@ describe('config helper', () => {
105105
ignores: ['common-ignored'],
106106
rules: { rule: 'error' },
107107
},
108-
),
109-
).toThrow(
108+
);
109+
}).toThrow(
110110
'tseslint.config(): Config at index 1 (anonymous) contains non-object extensions at ' +
111111
'the following indices: 0, 2',
112112
);
@@ -121,7 +121,7 @@ describe('config helper', () => {
121121
name: 'my-config',
122122
rules: { rule: 'error' },
123123
}),
124-
).toEqual([
124+
).toStrictEqual([
125125
{
126126
files: ['common-file'],
127127
ignores: ['common-ignored'],
@@ -154,7 +154,7 @@ describe('config helper', () => {
154154
ignores: ['common-ignored'],
155155
rules: { rule: 'error' },
156156
}),
157-
).toEqual([
157+
).toStrictEqual([
158158
{
159159
files: ['common-file'],
160160
ignores: ['common-ignored'],
@@ -186,7 +186,7 @@ describe('config helper', () => {
186186
name: 'my-config',
187187
rules: { rule: 'error' },
188188
}),
189-
).toEqual([
189+
).toStrictEqual([
190190
{
191191
files: ['common-file'],
192192
ignores: ['common-ignored'],
@@ -217,7 +217,7 @@ describe('config helper', () => {
217217
[[[{ rules: { rule4: 'error' } }]]],
218218
[[[[{ rules: { rule5: 'error' } }]]]],
219219
),
220-
).toEqual([
220+
).toStrictEqual([
221221
{ rules: { rule1: 'error' } },
222222
{ rules: { rule2: 'error' } },
223223
{ rules: { rule3: 'error' } },
@@ -238,7 +238,7 @@ describe('config helper', () => {
238238
],
239239
rules: { rule: 'error' },
240240
}),
241-
).toEqual([
241+
).toStrictEqual([
242242
{ rules: { rule1: 'error' } },
243243
{ rules: { rule2: 'error' } },
244244
{ rules: { rule3: 'error' } },
@@ -254,7 +254,7 @@ describe('config helper', () => {
254254
ignores: ['ignored'],
255255
});
256256

257-
expect(configWithIgnores).toEqual([
257+
expect(configWithIgnores).toStrictEqual([
258258
{ ignores: ['ignored'], rules: { rule1: 'error' } },
259259
{ ignores: ['ignored'], rules: { rule2: 'error' } },
260260
]);
@@ -272,7 +272,7 @@ describe('config helper', () => {
272272
name: 'my-config',
273273
});
274274

275-
expect(configWithMetadata).toEqual([
275+
expect(configWithMetadata).toStrictEqual([
276276
{
277277
files: ['file'],
278278
ignores: ['ignored'],
@@ -301,7 +301,7 @@ describe('config helper', () => {
301301
extends: [{ rules: { rule1: 'error' } }, {}],
302302
ignores: ['ignored'],
303303
}),
304-
).toEqual([
304+
).toStrictEqual([
305305
{ ignores: ['ignored'], rules: { rule1: 'error' } },
306306
// Should not create global ignores
307307
{},
@@ -314,23 +314,23 @@ describe('config helper', () => {
314314
extends: [{ ignores: ['files/**/*'], name: 'global-ignore-stuff' }],
315315
ignores: ['ignored'],
316316
}),
317-
).toEqual([{ ignores: ['files/**/*'], name: 'global-ignore-stuff' }]);
317+
).toStrictEqual([{ ignores: ['files/**/*'], name: 'global-ignore-stuff' }]);
318318
});
319319

320320
it('throws error when extends is not an array', () => {
321-
expect(() =>
321+
expect(() => {
322322
tseslint.config({
323323
// @ts-expect-error purposely testing invalid values
324324
extends: 42,
325-
}),
326-
).toThrow(
325+
});
326+
}).toThrow(
327327
"tseslint.config(): Config at index 0 (anonymous) has an 'extends' property that is not an array.",
328328
);
329329
});
330330

331-
it.each([undefined, null, 'not a config object', 42])(
331+
it.for([[undefined], [null], ['not a config object'], [42]] as const)(
332332
'passes invalid arguments through unchanged',
333-
config => {
333+
([config], { expect }) => {
334334
expect(
335335
tseslint.config(
336336
// @ts-expect-error purposely testing invalid values
@@ -341,12 +341,12 @@ describe('config helper', () => {
341341
);
342342

343343
it('gives a special error message for string extends', () => {
344-
expect(() =>
344+
expect(() => {
345345
tseslint.config({
346346
// @ts-expect-error purposely testing invalid values
347347
extends: ['some-string'],
348-
}),
349-
).toThrow(
348+
});
349+
}).toThrow(
350350
'tseslint.config(): Config at index 0 (anonymous) has an \'extends\' array that contains a string ("some-string") at index 0. ' +
351351
"This is a feature of eslint's `defineConfig()` helper and is not supported by typescript-eslint. " +
352352
'Please provide a config object instead.',
@@ -360,17 +360,17 @@ describe('config helper', () => {
360360
extends: null,
361361
files: ['files'],
362362
}),
363-
).toEqual([{ files: ['files'] }]);
363+
).toStrictEqual([{ files: ['files'] }]);
364364
});
365365

366366
it('complains when given an object with an invalid name', () => {
367-
expect(() =>
367+
expect(() => {
368368
tseslint.config({
369369
extends: [],
370370
// @ts-expect-error purposely testing invalid values
371371
name: 42,
372-
}),
373-
).toThrow(
372+
});
373+
}).toThrow(
374374
"tseslint.config(): Config at index 0 has a 'name' property that is not a string.",
375375
);
376376
});

0 commit comments

Comments
 (0)