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

Skip to content

chore(typescript-eslint): finish migrating to vitest #11137

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
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
2 changes: 2 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,7 @@ export default tseslint.config(
},
settings: { vitest: { typecheck: true } },
},

{
files: ['packages/*/tests/**/vitest-custom-matchers.d.ts'],
name: 'vitest-custom-matchers-declaration-files',
Expand All @@ -403,6 +404,7 @@ export default tseslint.config(
'@typescript-eslint/no-explicit-any': 'off',
},
},

// plugin rule tests
{
files: [
Expand Down
3 changes: 1 addition & 2 deletions packages/typescript-eslint/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,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": "nx lint",
"test": "vitest --run --config=$INIT_CWD/vitest.config.mts",
Expand Down
62 changes: 31 additions & 31 deletions packages/typescript-eslint/tests/config-helper.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { TSESLint } from '@typescript-eslint/utils';

import tseslint from '../src/index';
import tseslint from '../src/index.js';

describe('config helper', () => {
it('works without extends', () => {
Expand All @@ -10,7 +10,7 @@ describe('config helper', () => {
ignores: ['ignored'],
rules: { rule: 'error' },
}),
).toEqual([
).toStrictEqual([
{
files: ['file'],
ignores: ['ignored'],
Expand All @@ -25,7 +25,7 @@ describe('config helper', () => {
extends: [{ rules: { rule1: 'error' } }, { rules: { rule2: 'error' } }],
rules: { rule: 'error' },
}),
).toEqual([
).toStrictEqual([
{ rules: { rule1: 'error' } },
{ rules: { rule2: 'error' } },
{ rules: { rule: 'error' } },
Expand All @@ -40,7 +40,7 @@ describe('config helper', () => {
ignores: ['common-ignored'],
rules: { rule: 'error' },
}),
).toEqual([
).toStrictEqual([
{
files: ['common-file'],
ignores: ['common-ignored'],
Expand All @@ -62,7 +62,7 @@ describe('config helper', () => {
it('throws error containing config name when some extensions are undefined', () => {
const extension: TSESLint.FlatConfig.Config = { rules: { rule1: 'error' } };

expect(() =>
expect(() => {
tseslint.config(
{
extends: [extension],
Expand All @@ -79,8 +79,8 @@ describe('config helper', () => {
name: 'my-config-2',
rules: { rule: 'error' },
},
),
).toThrow(
);
}).toThrow(
'tseslint.config(): Config at index 1, named "my-config-2", contains non-object ' +
'extensions at the following indices: 0, 2',
);
Expand All @@ -89,7 +89,7 @@ describe('config helper', () => {
it('throws error without config name when some extensions are undefined', () => {
const extension: TSESLint.FlatConfig.Config = { rules: { rule1: 'error' } };

expect(() =>
expect(() => {
tseslint.config(
{
extends: [extension],
Expand All @@ -105,8 +105,8 @@ describe('config helper', () => {
ignores: ['common-ignored'],
rules: { rule: 'error' },
},
),
).toThrow(
);
}).toThrow(
'tseslint.config(): Config at index 1 (anonymous) contains non-object extensions at ' +
'the following indices: 0, 2',
);
Expand All @@ -121,7 +121,7 @@ describe('config helper', () => {
name: 'my-config',
rules: { rule: 'error' },
}),
).toEqual([
).toStrictEqual([
{
files: ['common-file'],
ignores: ['common-ignored'],
Expand Down Expand Up @@ -154,7 +154,7 @@ describe('config helper', () => {
ignores: ['common-ignored'],
rules: { rule: 'error' },
}),
).toEqual([
).toStrictEqual([
{
files: ['common-file'],
ignores: ['common-ignored'],
Expand Down Expand Up @@ -186,7 +186,7 @@ describe('config helper', () => {
name: 'my-config',
rules: { rule: 'error' },
}),
).toEqual([
).toStrictEqual([
{
files: ['common-file'],
ignores: ['common-ignored'],
Expand Down Expand Up @@ -217,7 +217,7 @@ describe('config helper', () => {
[[[{ rules: { rule4: 'error' } }]]],
[[[[{ rules: { rule5: 'error' } }]]]],
),
).toEqual([
).toStrictEqual([
{ rules: { rule1: 'error' } },
{ rules: { rule2: 'error' } },
{ rules: { rule3: 'error' } },
Expand All @@ -238,7 +238,7 @@ describe('config helper', () => {
],
rules: { rule: 'error' },
}),
).toEqual([
).toStrictEqual([
{ rules: { rule1: 'error' } },
{ rules: { rule2: 'error' } },
{ rules: { rule3: 'error' } },
Expand All @@ -254,7 +254,7 @@ describe('config helper', () => {
ignores: ['ignored'],
});

expect(configWithIgnores).toEqual([
expect(configWithIgnores).toStrictEqual([
{ ignores: ['ignored'], rules: { rule1: 'error' } },
{ ignores: ['ignored'], rules: { rule2: 'error' } },
]);
Expand All @@ -272,7 +272,7 @@ describe('config helper', () => {
name: 'my-config',
});

expect(configWithMetadata).toEqual([
expect(configWithMetadata).toStrictEqual([
{
files: ['file'],
ignores: ['ignored'],
Expand Down Expand Up @@ -301,7 +301,7 @@ describe('config helper', () => {
extends: [{ rules: { rule1: 'error' } }, {}],
ignores: ['ignored'],
}),
).toEqual([
).toStrictEqual([
{ ignores: ['ignored'], rules: { rule1: 'error' } },
// Should not create global ignores
{},
Expand All @@ -314,23 +314,23 @@ describe('config helper', () => {
extends: [{ ignores: ['files/**/*'], name: 'global-ignore-stuff' }],
ignores: ['ignored'],
}),
).toEqual([{ ignores: ['files/**/*'], name: 'global-ignore-stuff' }]);
).toStrictEqual([{ ignores: ['files/**/*'], name: 'global-ignore-stuff' }]);
});

it('throws error when extends is not an array', () => {
expect(() =>
expect(() => {
tseslint.config({
// @ts-expect-error purposely testing invalid values
extends: 42,
}),
).toThrow(
});
}).toThrow(
"tseslint.config(): Config at index 0 (anonymous) has an 'extends' property that is not an array.",
);
});

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

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

it('complains when given an object with an invalid name', () => {
expect(() =>
expect(() => {
tseslint.config({
extends: [],
// @ts-expect-error purposely testing invalid values
name: 42,
}),
).toThrow(
});
}).toThrow(
"tseslint.config(): Config at index 0 has a 'name' property that is not a string.",
);
});
Expand Down
Loading