Skip to content

refactor: Include test files in type checking #1022

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
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: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"types": "index.d.ts",
"scripts": {
"prebuild": "del-cli dist",
"build": "tsc",
"build": "tsc -p ./tsconfig.build.json",
"generate-all": "pnpm run --parallel \"/^generate:.*/\"",
"generate-all:check": "pnpm run generate-all && git diff --exit-code",
"generate:configs": "ts-node tools/generate-configs",
Expand Down
2 changes: 1 addition & 1 deletion tests/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ it('should export configs that refer to actual rules', () => {
'flat/marko',
]);
const allConfigRules = Object.values(allConfigs)
.map((config) => Object.keys(config.rules))
.map((config) => Object.keys(config.rules ?? {}))
.reduce((previousValue, currentValue) => [
...previousValue,
...currentValue,
Expand Down
25 changes: 16 additions & 9 deletions tests/lib/rules/no-wait-for-side-effects.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import rule, { RULE_NAME } from '../../../lib/rules/no-wait-for-side-effects';
import { InvalidTestCase } from '@typescript-eslint/rule-tester';

import rule, {
RULE_NAME,
type MessageIds,
} from '../../../lib/rules/no-wait-for-side-effects';
import { createRuleTester } from '../test-utils';

const ruleTester = createRuleTester();
Expand Down Expand Up @@ -118,7 +123,7 @@ ruleTester.run(RULE_NAME, rule, {
code: `
import { waitFor } from '${testingFramework}';
import { notUserEvent } from 'somewhere-else';

waitFor(() => {
await notUserEvent.click(button)
})
Expand Down Expand Up @@ -736,7 +741,7 @@ ruleTester.run(RULE_NAME, rule, {
expect(b).toEqual('b')
}).then(() => {
userEvent.click(button) // Side effects are allowed inside .then()
expect(b).toEqual('b')
expect(b).toEqual('b')
})
`,
errors: [{ line: 4, column: 11, messageId: 'noSideEffectsWaitFor' }],
Expand Down Expand Up @@ -808,9 +813,10 @@ ruleTester.run(RULE_NAME, rule, {
} as const,
]),

...SUPPORTED_TESTING_FRAMEWORKS.flatMap((testingFramework) => [
{
code: `
...SUPPORTED_TESTING_FRAMEWORKS.flatMap<InvalidTestCase<MessageIds, []>>(
(testingFramework) => [
{
code: `
import { waitFor } from '${testingFramework}';
import userEvent from '@testing-library/user-event'

Expand All @@ -820,8 +826,9 @@ ruleTester.run(RULE_NAME, rule, {
});
});
`,
errors: [{ line: 7, column: 13, messageId: 'noSideEffectsWaitFor' }],
},
]),
errors: [{ line: 7, column: 13, messageId: 'noSideEffectsWaitFor' }],
},
]
),
],
});
58 changes: 30 additions & 28 deletions tests/lib/rules/prefer-find-by.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ ruleTester.run(RULE_NAME, rule, {
},
]),
invalid: SUPPORTED_TESTING_FRAMEWORKS.flatMap((testingFramework) => [
...createScenario((waitMethod: string, queryMethod: string) => ({
...createScenario((waitMethod, queryMethod) => ({
code: `
import {${waitMethod}, screen} from '${testingFramework}';
it('tests', async () => {
Expand Down Expand Up @@ -353,7 +353,7 @@ ruleTester.run(RULE_NAME, rule, {
output: null,
},
// presence matchers
...createScenario((waitMethod: string, queryMethod: string) => ({
...createScenario((waitMethod, queryMethod) => ({
code: `
import {${waitMethod}} from '${testingFramework}';
it('tests', async () => {
Expand Down Expand Up @@ -382,7 +382,7 @@ ruleTester.run(RULE_NAME, rule, {
})
`,
})),
...createScenario((waitMethod: string, queryMethod: string) => ({
...createScenario((waitMethod, queryMethod) => ({
code: `
import {${waitMethod}} from '${testingFramework}';
it('tests', async () => {
Expand Down Expand Up @@ -411,7 +411,7 @@ ruleTester.run(RULE_NAME, rule, {
})
`,
})),
...createScenario((waitMethod: string, queryMethod: string) => ({
...createScenario((waitMethod, queryMethod) => ({
code: `
import {${waitMethod}} from '${testingFramework}';
it('tests', async () => {
Expand Down Expand Up @@ -440,7 +440,7 @@ ruleTester.run(RULE_NAME, rule, {
})
`,
})),
...createScenario((waitMethod: string, queryMethod: string) => ({
...createScenario((waitMethod, queryMethod) => ({
code: `
import {${waitMethod}} from '${testingFramework}';
it('tests', async () => {
Expand Down Expand Up @@ -469,7 +469,7 @@ ruleTester.run(RULE_NAME, rule, {
})
`,
})),
...createScenario((waitMethod: string, queryMethod: string) => ({
...createScenario((waitMethod, queryMethod) => ({
code: `
import {${waitMethod}} from '${testingFramework}';
it('tests', async () => {
Expand Down Expand Up @@ -498,7 +498,7 @@ ruleTester.run(RULE_NAME, rule, {
})
`,
})),
...createScenario((waitMethod: string, queryMethod: string) => ({
...createScenario((waitMethod, queryMethod) => ({
code: `
import {${waitMethod}} from '${testingFramework}';
it('tests', async () => {
Expand Down Expand Up @@ -527,7 +527,7 @@ ruleTester.run(RULE_NAME, rule, {
})
`,
})),
...createScenario((waitMethod: string, queryMethod: string) => ({
...createScenario((waitMethod, queryMethod) => ({
code: `
import {${waitMethod}} from '${testingFramework}';
it('tests', async () => {
Expand Down Expand Up @@ -556,7 +556,7 @@ ruleTester.run(RULE_NAME, rule, {
})
`,
})),
...createScenario((waitMethod: string, queryMethod: string) => ({
...createScenario((waitMethod, queryMethod) => ({
code: `
import {${waitMethod}} from '${testingFramework}';
it('tests', async () => {
Expand All @@ -583,7 +583,7 @@ ruleTester.run(RULE_NAME, rule, {
})
`,
})),
...createScenario((waitMethod: string, queryMethod: string) => ({
...createScenario((waitMethod, queryMethod) => ({
code: `
import {${waitMethod}} from '${testingFramework}';
it('tests', async () => {
Expand All @@ -610,7 +610,7 @@ ruleTester.run(RULE_NAME, rule, {
})
`,
})),
...createScenario((waitMethod: string, queryMethod: string) => ({
...createScenario((waitMethod, queryMethod) => ({
code: `
import {${waitMethod}} from '${testingFramework}';
it('tests', async () => {
Expand All @@ -637,7 +637,7 @@ ruleTester.run(RULE_NAME, rule, {
})
`,
})),
...createScenario((waitMethod: string, queryMethod: string) => ({
...createScenario((waitMethod, queryMethod) => ({
code: `
import {${waitMethod}} from '${testingFramework}';
it('tests', async () => {
Expand All @@ -664,7 +664,7 @@ ruleTester.run(RULE_NAME, rule, {
})
`,
})),
...createScenario((waitMethod: string, queryMethod: string) => ({
...createScenario((waitMethod, queryMethod) => ({
code: `
import {${waitMethod}} from '${testingFramework}';
it('tests', async () => {
Expand Down Expand Up @@ -693,7 +693,7 @@ ruleTester.run(RULE_NAME, rule, {
})),
// Issue #579, https://github.com/testing-library/eslint-plugin-testing-library/issues/579
// findBy can have two sets of options: await screen.findByText('text', queryOptions, waitForOptions)
...createScenario((waitMethod: string, queryMethod: string) => ({
...createScenario((waitMethod, queryMethod) => ({
code: `import {${waitMethod}} from '${testingFramework}';
const button = await ${waitMethod}(() => screen.${queryMethod}('Count is: 0'), { timeout: 100, interval: 200 })
`,
Expand All @@ -714,8 +714,9 @@ ruleTester.run(RULE_NAME, rule, {
)}('Count is: 0', { timeout: 100, interval: 200 })
`,
})),
...ASYNC_QUERIES_COMBINATIONS.map((queryMethod) => ({
code: `
...ASYNC_QUERIES_COMBINATIONS.map<InvalidTestCase<MessageIds, []>>(
(queryMethod) => ({
code: `
import {waitFor} from '${testingFramework}';
it('tests', async () => {
await waitFor(async () => {
Expand All @@ -724,24 +725,25 @@ ruleTester.run(RULE_NAME, rule, {
})
})
`,
errors: [
{
messageId: 'preferFindBy',
data: {
queryVariant: getFindByQueryVariant(queryMethod),
queryMethod: queryMethod.split('By')[1],
prevQuery: queryMethod,
waitForMethodName: 'waitFor',
errors: [
{
messageId: 'preferFindBy',
data: {
queryVariant: getFindByQueryVariant(queryMethod),
queryMethod: queryMethod.split('By')[1],
prevQuery: queryMethod,
waitForMethodName: 'waitFor',
},
},
},
],
output: `
],
output: `
import {waitFor} from '${testingFramework}';
it('tests', async () => {
const button = await screen.${queryMethod}("button", { name: "Submit" })
expect(button).toBeInTheDocument()
})
`,
})),
})
),
]),
});
4 changes: 4 additions & 0 deletions tsconfig.build.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"extends": "./tsconfig.json",
"exclude": ["./tests/**/*.ts"]
}
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@
"outDir": "dist",
"sourceMap": false
},
"include": ["./lib/**/*.ts"]
"include": ["./lib/**/*.ts", "./tests/**/*.ts"]
}