1
1
import type { Linter } from 'eslint'
2
2
3
3
export type Awaitable < T > = Promise < T > | T
4
- export interface ValidTestCaseBase extends CompatConfigOptions , RuleTesterBehaviorOptions {
4
+ export interface ValidTestCaseBase < RuleOptions = any > extends CompatConfigOptions , RuleTesterBehaviorOptions {
5
5
name ?: string
6
6
description ?: string
7
7
code : string
8
- options ?: any
8
+ options ?: RuleOptions
9
9
filename ?: string
10
10
only ?: boolean
11
11
skip ?: boolean
@@ -29,7 +29,7 @@ export interface TestCaseError extends Partial<Linter.LintMessage> {
29
29
type ?: string
30
30
}
31
31
32
- export interface InvalidTestCaseBase extends ValidTestCaseBase {
32
+ export interface InvalidTestCaseBase < RuleOptions = any > extends ValidTestCaseBase < RuleOptions > {
33
33
/**
34
34
* Expected errors.
35
35
* If a number is provided, it asserts that the number of errors is equal to the number provided.
@@ -49,10 +49,10 @@ export interface NormalizedTestCase extends InvalidTestCaseBase {
49
49
code : string
50
50
}
51
51
52
- export type InvalidTestCase = InvalidTestCaseBase | string
53
- export type ValidTestCase = ValidTestCaseBase | string
52
+ export type InvalidTestCase < RuleOptions = any > = InvalidTestCaseBase < RuleOptions > | string
53
+ export type ValidTestCase < RuleOptions = any > = ValidTestCaseBase < RuleOptions > | string
54
54
55
- export type TestCase = ValidTestCase | InvalidTestCase
55
+ export type TestCase < RuleOptions = any > = ValidTestCase < RuleOptions > | InvalidTestCase < RuleOptions >
56
56
57
57
export interface TestExecutionResult extends Linter . FixReport {
58
58
/**
@@ -73,23 +73,23 @@ export interface CompatConfigOptions {
73
73
74
74
export type RuleModule = any // to allow any rule module
75
75
76
- export interface RuleTester {
76
+ export interface RuleTester < RuleOptions = any > {
77
77
/**
78
78
* Run a single test case
79
79
*/
80
- each : ( arg : TestCase ) => Promise < { testcase : NormalizedTestCase , result : TestExecutionResult } >
80
+ each : ( arg : TestCase < RuleOptions > ) => Promise < { testcase : NormalizedTestCase , result : TestExecutionResult } >
81
81
/**
82
82
* Run a single valid test case
83
83
*/
84
- valid : ( arg : ValidTestCase ) => Promise < { testcase : NormalizedTestCase , result : TestExecutionResult } >
84
+ valid : ( arg : ValidTestCase < RuleOptions > ) => Promise < { testcase : NormalizedTestCase , result : TestExecutionResult } >
85
85
/**
86
86
* Run a single invalid test case
87
87
*/
88
- invalid : ( arg : InvalidTestCase ) => Promise < { testcase : NormalizedTestCase , result : TestExecutionResult } >
88
+ invalid : ( arg : InvalidTestCase < RuleOptions > ) => Promise < { testcase : NormalizedTestCase , result : TestExecutionResult } >
89
89
/**
90
90
* ESLint's RuleTester style test runner, that runs multiple test cases
91
91
*/
92
- run : ( options : TestCasesOptions ) => Promise < void >
92
+ run : ( options : TestCasesOptions < RuleOptions > ) => Promise < void >
93
93
}
94
94
95
95
export interface RuleTesterBehaviorOptions {
@@ -137,9 +137,9 @@ export interface RuleTesterInitOptions extends CompatConfigOptions, RuleTesterBe
137
137
defaultFilenames ?: Partial < DefaultFilenames >
138
138
}
139
139
140
- export interface TestCasesOptions {
141
- valid ?: ( ValidTestCase | string ) [ ]
142
- invalid ?: ( InvalidTestCase | string ) [ ]
140
+ export interface TestCasesOptions < RuleOptions = any > {
141
+ valid ?: ( ValidTestCase < RuleOptions > | string ) [ ]
142
+ invalid ?: ( InvalidTestCase < RuleOptions > | string ) [ ]
143
143
/**
144
144
* Callback to be called after each test case
145
145
*/
0 commit comments