1 | import { AST_NODE_TYPES, AST_TOKEN_TYPES } from '../ts-estree';
|
2 | import { ParserOptions } from './ParserOptions';
|
3 | import { Linter } from './Linter';
|
4 | import { RuleCreateFunction, RuleModule, SharedConfigurationSettings } from './Rule';
|
5 | interface ValidTestCase<TOptions extends Readonly<unknown[]>> {
|
6 | |
7 |
|
8 |
|
9 | readonly code: string;
|
10 | |
11 |
|
12 |
|
13 | readonly env?: Readonly<Record<string, boolean>>;
|
14 | |
15 |
|
16 |
|
17 | readonly filename?: string;
|
18 | |
19 |
|
20 |
|
21 | readonly globals?: Record<string, 'readonly' | 'writable' | 'off' | true>;
|
22 | |
23 |
|
24 |
|
25 | readonly options?: Readonly<TOptions>;
|
26 | |
27 |
|
28 |
|
29 | readonly parser?: string;
|
30 | |
31 |
|
32 |
|
33 | readonly parserOptions?: Readonly<ParserOptions>;
|
34 | |
35 |
|
36 |
|
37 | readonly settings?: Readonly<SharedConfigurationSettings>;
|
38 | |
39 |
|
40 |
|
41 | readonly only?: boolean;
|
42 | }
|
43 | interface SuggestionOutput<TMessageIds extends string> {
|
44 | |
45 |
|
46 |
|
47 | readonly messageId: TMessageIds;
|
48 | |
49 |
|
50 |
|
51 | readonly data?: Readonly<Record<string, unknown>>;
|
52 | |
53 |
|
54 |
|
55 |
|
56 | readonly output: string;
|
57 | }
|
58 | interface InvalidTestCase<TMessageIds extends string, TOptions extends Readonly<unknown[]>> extends ValidTestCase<TOptions> {
|
59 | |
60 |
|
61 |
|
62 | readonly errors: readonly TestCaseError<TMessageIds>[];
|
63 | |
64 |
|
65 |
|
66 | readonly output?: string | null;
|
67 | }
|
68 | interface TestCaseError<TMessageIds extends string> {
|
69 | |
70 |
|
71 |
|
72 | readonly column?: number;
|
73 | |
74 |
|
75 |
|
76 | readonly data?: Readonly<Record<string, unknown>>;
|
77 | |
78 |
|
79 |
|
80 | readonly endColumn?: number;
|
81 | |
82 |
|
83 |
|
84 | readonly endLine?: number;
|
85 | |
86 |
|
87 |
|
88 | readonly line?: number;
|
89 | |
90 |
|
91 |
|
92 | readonly messageId: TMessageIds;
|
93 | |
94 |
|
95 |
|
96 | readonly suggestions?: SuggestionOutput<TMessageIds>[] | null;
|
97 | |
98 |
|
99 |
|
100 | readonly type?: AST_NODE_TYPES | AST_TOKEN_TYPES;
|
101 | }
|
102 | interface RunTests<TMessageIds extends string, TOptions extends Readonly<unknown[]>> {
|
103 | readonly valid: readonly (ValidTestCase<TOptions> | string)[];
|
104 | readonly invalid: readonly InvalidTestCase<TMessageIds, TOptions>[];
|
105 | }
|
106 | interface RuleTesterConfig extends Linter.Config {
|
107 | readonly parser: string;
|
108 | readonly parserOptions?: Readonly<ParserOptions>;
|
109 | }
|
110 | declare class RuleTesterBase {
|
111 | |
112 |
|
113 |
|
114 |
|
115 | constructor(testerConfig?: RuleTesterConfig);
|
116 | /**
|
117 | * Adds a new rule test to execute.
|
118 | * @param ruleName The name of the rule to run.
|
119 | * @param rule The rule to test.
|
120 | * @param test The collection of tests to run.
|
121 | */
|
122 | run<TMessageIds extends string, TOptions extends Readonly<unknown[]>>(ruleName: string, rule: RuleModule<TMessageIds, TOptions>, tests: RunTests<TMessageIds, TOptions>): void;
|
123 | /**
|
124 | * If you supply a value to this property, the rule tester will call this instead of using the version defined on
|
125 | * the global namespace.
|
126 | * @param text a string describing the rule
|
127 | * @param callback the test callback
|
128 | */
|
129 | static describe?: (text: string, callback: () => void) => void;
|
130 | /**
|
131 | * If you supply a value to this property, the rule tester will call this instead of using the version defined on
|
132 | * the global namespace.
|
133 | * @param text a string describing the test case
|
134 | * @param callback the test callback
|
135 | */
|
136 | static it?: (text: string, callback: () => void) => void;
|
137 | /**
|
138 | * Define a rule for one particular run of tests.
|
139 | * @param name The name of the rule to define.
|
140 | * @param rule The rule definition.
|
141 | */
|
142 | defineRule<TMessageIds extends string, TOptions extends Readonly<unknown[]>>(name: string, rule: RuleModule<TMessageIds, TOptions> | RuleCreateFunction<TMessageIds, TOptions>): void;
|
143 | }
|
144 | declare const RuleTester_base: typeof RuleTesterBase;
|
145 | declare class RuleTester extends RuleTester_base {
|
146 | }
|
147 | export { InvalidTestCase, SuggestionOutput, RuleTester, RuleTesterConfig, RunTests, TestCaseError, ValidTestCase, };
|
148 |
|
\ | No newline at end of file |