Skip to content

Commit 665577c

Browse files
authored
refactor: Include test files in type checking (#1022)
1 parent 36facf1 commit 665577c

File tree

6 files changed

+53
-40
lines changed

6 files changed

+53
-40
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
"types": "index.d.ts",
3535
"scripts": {
3636
"prebuild": "del-cli dist",
37-
"build": "tsc",
37+
"build": "tsc -p ./tsconfig.build.json",
3838
"generate-all": "pnpm run --parallel \"/^generate:.*/\"",
3939
"generate-all:check": "pnpm run generate-all && git diff --exit-code",
4040
"generate:configs": "ts-node tools/generate-configs",

tests/index.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ it('should export configs that refer to actual rules', () => {
6161
'flat/marko',
6262
]);
6363
const allConfigRules = Object.values(allConfigs)
64-
.map((config) => Object.keys(config.rules))
64+
.map((config) => Object.keys(config.rules ?? {}))
6565
.reduce((previousValue, currentValue) => [
6666
...previousValue,
6767
...currentValue,

tests/lib/rules/no-wait-for-side-effects.test.ts

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
import rule, { RULE_NAME } from '../../../lib/rules/no-wait-for-side-effects';
1+
import { InvalidTestCase } from '@typescript-eslint/rule-tester';
2+
3+
import rule, {
4+
RULE_NAME,
5+
type MessageIds,
6+
} from '../../../lib/rules/no-wait-for-side-effects';
27
import { createRuleTester } from '../test-utils';
38

49
const ruleTester = createRuleTester();
@@ -118,7 +123,7 @@ ruleTester.run(RULE_NAME, rule, {
118123
code: `
119124
import { waitFor } from '${testingFramework}';
120125
import { notUserEvent } from 'somewhere-else';
121-
126+
122127
waitFor(() => {
123128
await notUserEvent.click(button)
124129
})
@@ -736,7 +741,7 @@ ruleTester.run(RULE_NAME, rule, {
736741
expect(b).toEqual('b')
737742
}).then(() => {
738743
userEvent.click(button) // Side effects are allowed inside .then()
739-
expect(b).toEqual('b')
744+
expect(b).toEqual('b')
740745
})
741746
`,
742747
errors: [{ line: 4, column: 11, messageId: 'noSideEffectsWaitFor' }],
@@ -808,9 +813,10 @@ ruleTester.run(RULE_NAME, rule, {
808813
} as const,
809814
]),
810815

811-
...SUPPORTED_TESTING_FRAMEWORKS.flatMap((testingFramework) => [
812-
{
813-
code: `
816+
...SUPPORTED_TESTING_FRAMEWORKS.flatMap<InvalidTestCase<MessageIds, []>>(
817+
(testingFramework) => [
818+
{
819+
code: `
814820
import { waitFor } from '${testingFramework}';
815821
import userEvent from '@testing-library/user-event'
816822
@@ -820,8 +826,9 @@ ruleTester.run(RULE_NAME, rule, {
820826
});
821827
});
822828
`,
823-
errors: [{ line: 7, column: 13, messageId: 'noSideEffectsWaitFor' }],
824-
},
825-
]),
829+
errors: [{ line: 7, column: 13, messageId: 'noSideEffectsWaitFor' }],
830+
},
831+
]
832+
),
826833
],
827834
});

tests/lib/rules/prefer-find-by.test.ts

Lines changed: 30 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ ruleTester.run(RULE_NAME, rule, {
191191
},
192192
]),
193193
invalid: SUPPORTED_TESTING_FRAMEWORKS.flatMap((testingFramework) => [
194-
...createScenario((waitMethod: string, queryMethod: string) => ({
194+
...createScenario((waitMethod, queryMethod) => ({
195195
code: `
196196
import {${waitMethod}, screen} from '${testingFramework}';
197197
it('tests', async () => {
@@ -353,7 +353,7 @@ ruleTester.run(RULE_NAME, rule, {
353353
output: null,
354354
},
355355
// presence matchers
356-
...createScenario((waitMethod: string, queryMethod: string) => ({
356+
...createScenario((waitMethod, queryMethod) => ({
357357
code: `
358358
import {${waitMethod}} from '${testingFramework}';
359359
it('tests', async () => {
@@ -382,7 +382,7 @@ ruleTester.run(RULE_NAME, rule, {
382382
})
383383
`,
384384
})),
385-
...createScenario((waitMethod: string, queryMethod: string) => ({
385+
...createScenario((waitMethod, queryMethod) => ({
386386
code: `
387387
import {${waitMethod}} from '${testingFramework}';
388388
it('tests', async () => {
@@ -411,7 +411,7 @@ ruleTester.run(RULE_NAME, rule, {
411411
})
412412
`,
413413
})),
414-
...createScenario((waitMethod: string, queryMethod: string) => ({
414+
...createScenario((waitMethod, queryMethod) => ({
415415
code: `
416416
import {${waitMethod}} from '${testingFramework}';
417417
it('tests', async () => {
@@ -440,7 +440,7 @@ ruleTester.run(RULE_NAME, rule, {
440440
})
441441
`,
442442
})),
443-
...createScenario((waitMethod: string, queryMethod: string) => ({
443+
...createScenario((waitMethod, queryMethod) => ({
444444
code: `
445445
import {${waitMethod}} from '${testingFramework}';
446446
it('tests', async () => {
@@ -469,7 +469,7 @@ ruleTester.run(RULE_NAME, rule, {
469469
})
470470
`,
471471
})),
472-
...createScenario((waitMethod: string, queryMethod: string) => ({
472+
...createScenario((waitMethod, queryMethod) => ({
473473
code: `
474474
import {${waitMethod}} from '${testingFramework}';
475475
it('tests', async () => {
@@ -498,7 +498,7 @@ ruleTester.run(RULE_NAME, rule, {
498498
})
499499
`,
500500
})),
501-
...createScenario((waitMethod: string, queryMethod: string) => ({
501+
...createScenario((waitMethod, queryMethod) => ({
502502
code: `
503503
import {${waitMethod}} from '${testingFramework}';
504504
it('tests', async () => {
@@ -527,7 +527,7 @@ ruleTester.run(RULE_NAME, rule, {
527527
})
528528
`,
529529
})),
530-
...createScenario((waitMethod: string, queryMethod: string) => ({
530+
...createScenario((waitMethod, queryMethod) => ({
531531
code: `
532532
import {${waitMethod}} from '${testingFramework}';
533533
it('tests', async () => {
@@ -556,7 +556,7 @@ ruleTester.run(RULE_NAME, rule, {
556556
})
557557
`,
558558
})),
559-
...createScenario((waitMethod: string, queryMethod: string) => ({
559+
...createScenario((waitMethod, queryMethod) => ({
560560
code: `
561561
import {${waitMethod}} from '${testingFramework}';
562562
it('tests', async () => {
@@ -583,7 +583,7 @@ ruleTester.run(RULE_NAME, rule, {
583583
})
584584
`,
585585
})),
586-
...createScenario((waitMethod: string, queryMethod: string) => ({
586+
...createScenario((waitMethod, queryMethod) => ({
587587
code: `
588588
import {${waitMethod}} from '${testingFramework}';
589589
it('tests', async () => {
@@ -610,7 +610,7 @@ ruleTester.run(RULE_NAME, rule, {
610610
})
611611
`,
612612
})),
613-
...createScenario((waitMethod: string, queryMethod: string) => ({
613+
...createScenario((waitMethod, queryMethod) => ({
614614
code: `
615615
import {${waitMethod}} from '${testingFramework}';
616616
it('tests', async () => {
@@ -637,7 +637,7 @@ ruleTester.run(RULE_NAME, rule, {
637637
})
638638
`,
639639
})),
640-
...createScenario((waitMethod: string, queryMethod: string) => ({
640+
...createScenario((waitMethod, queryMethod) => ({
641641
code: `
642642
import {${waitMethod}} from '${testingFramework}';
643643
it('tests', async () => {
@@ -664,7 +664,7 @@ ruleTester.run(RULE_NAME, rule, {
664664
})
665665
`,
666666
})),
667-
...createScenario((waitMethod: string, queryMethod: string) => ({
667+
...createScenario((waitMethod, queryMethod) => ({
668668
code: `
669669
import {${waitMethod}} from '${testingFramework}';
670670
it('tests', async () => {
@@ -693,7 +693,7 @@ ruleTester.run(RULE_NAME, rule, {
693693
})),
694694
// Issue #579, https://github.com/testing-library/eslint-plugin-testing-library/issues/579
695695
// findBy can have two sets of options: await screen.findByText('text', queryOptions, waitForOptions)
696-
...createScenario((waitMethod: string, queryMethod: string) => ({
696+
...createScenario((waitMethod, queryMethod) => ({
697697
code: `import {${waitMethod}} from '${testingFramework}';
698698
const button = await ${waitMethod}(() => screen.${queryMethod}('Count is: 0'), { timeout: 100, interval: 200 })
699699
`,
@@ -714,8 +714,9 @@ ruleTester.run(RULE_NAME, rule, {
714714
)}('Count is: 0', { timeout: 100, interval: 200 })
715715
`,
716716
})),
717-
...ASYNC_QUERIES_COMBINATIONS.map((queryMethod) => ({
718-
code: `
717+
...ASYNC_QUERIES_COMBINATIONS.map<InvalidTestCase<MessageIds, []>>(
718+
(queryMethod) => ({
719+
code: `
719720
import {waitFor} from '${testingFramework}';
720721
it('tests', async () => {
721722
await waitFor(async () => {
@@ -724,24 +725,25 @@ ruleTester.run(RULE_NAME, rule, {
724725
})
725726
})
726727
`,
727-
errors: [
728-
{
729-
messageId: 'preferFindBy',
730-
data: {
731-
queryVariant: getFindByQueryVariant(queryMethod),
732-
queryMethod: queryMethod.split('By')[1],
733-
prevQuery: queryMethod,
734-
waitForMethodName: 'waitFor',
728+
errors: [
729+
{
730+
messageId: 'preferFindBy',
731+
data: {
732+
queryVariant: getFindByQueryVariant(queryMethod),
733+
queryMethod: queryMethod.split('By')[1],
734+
prevQuery: queryMethod,
735+
waitForMethodName: 'waitFor',
736+
},
735737
},
736-
},
737-
],
738-
output: `
738+
],
739+
output: `
739740
import {waitFor} from '${testingFramework}';
740741
it('tests', async () => {
741742
const button = await screen.${queryMethod}("button", { name: "Submit" })
742743
expect(button).toBeInTheDocument()
743744
})
744745
`,
745-
})),
746+
})
747+
),
746748
]),
747749
});

tsconfig.build.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"extends": "./tsconfig.json",
3+
"exclude": ["./tests/**/*.ts"]
4+
}

tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,5 @@
1616
"outDir": "dist",
1717
"sourceMap": false
1818
},
19-
"include": ["./lib/**/*.ts"]
19+
"include": ["./lib/**/*.ts", "./tests/**/*.ts"]
2020
}

0 commit comments

Comments
 (0)