-
Notifications
You must be signed in to change notification settings - Fork 162
Expand file tree
/
Copy pathindex.ts
More file actions
193 lines (171 loc) · 3.92 KB
/
index.ts
File metadata and controls
193 lines (171 loc) · 3.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
export * from './compat';
export * from './types';
export * from './resolve-to-testing-library-fn';
const combineQueries = (
variants: readonly string[],
methods: readonly string[]
): string[] => {
const combinedQueries: string[] = [];
variants.forEach((variant) => {
const variantPrefix = variant.replace('By', '');
methods.forEach((method) => {
combinedQueries.push(`${variantPrefix}${method}`);
});
});
return combinedQueries;
};
const getDocsUrl = (ruleName: string): string =>
`https://github.com/testing-library/eslint-plugin-testing-library/tree/main/docs/rules/${ruleName}.md`;
const LIBRARY_MODULES = [
'@testing-library/dom',
'@testing-library/angular',
'@testing-library/react',
'@testing-library/preact',
'@testing-library/vue',
'@testing-library/svelte',
'@marko/testing-library',
'shadow-dom-testing-library',
] as const;
const USER_EVENT_MODULE = '@testing-library/user-event';
const OLD_LIBRARY_MODULES = [
'dom-testing-library',
'vue-testing-library',
'react-testing-library',
] as const;
const SYNC_QUERIES_VARIANTS = [
'getBy',
'getAllBy',
'queryBy',
'queryAllBy',
] as const;
const ASYNC_QUERIES_VARIANTS = ['findBy', 'findAllBy'] as const;
const ALL_QUERIES_VARIANTS = [
...SYNC_QUERIES_VARIANTS,
...ASYNC_QUERIES_VARIANTS,
] as const;
const ALL_QUERIES_METHODS = [
'ByLabelText',
'ByPlaceholderText',
'ByText',
'ByAltText',
'ByTitle',
'ByDisplayValue',
'ByRole',
'ByTestId',
// queries coming from 'shadow-dom-testing-library'
'ByShadowLabelText',
'ByShadowPlaceholderText',
'ByShadowText',
'ByShadowAltText',
'ByShadowTitle',
'ByShadowDisplayValue',
'ByShadowRole',
'ByShadowTestId',
] as const;
const SYNC_QUERIES_COMBINATIONS = combineQueries(
SYNC_QUERIES_VARIANTS,
ALL_QUERIES_METHODS
);
const ASYNC_QUERIES_COMBINATIONS = combineQueries(
ASYNC_QUERIES_VARIANTS,
ALL_QUERIES_METHODS
);
const ALL_QUERIES_COMBINATIONS = [
...SYNC_QUERIES_COMBINATIONS,
...ASYNC_QUERIES_COMBINATIONS,
] as const;
const ASYNC_UTILS = ['waitFor', 'waitForElementToBeRemoved'] as const;
const DEBUG_UTILS = [
'debug',
'logTestingPlaygroundURL',
'prettyDOM',
'logRoles',
'logDOM',
'prettyFormat',
] as const;
const EVENTS_SIMULATORS = ['fireEvent', 'userEvent'] as const;
const TESTING_FRAMEWORK_SETUP_HOOKS = ['beforeEach', 'beforeAll'] as const;
const PROPERTIES_RETURNING_NODES = [
'activeElement',
'children',
'childElementCount',
'firstChild',
'firstElementChild',
'fullscreenElement',
'lastChild',
'lastElementChild',
'nextElementSibling',
'nextSibling',
'parentElement',
'parentNode',
'pointerLockElement',
'previousElementSibling',
'previousSibling',
'rootNode',
'scripts',
] as const;
const METHODS_RETURNING_NODES = [
'closest',
'getElementById',
'getElementsByClassName',
'getElementsByName',
'getElementsByTagName',
'getElementsByTagNameNS',
'querySelector',
'querySelectorAll',
] as const;
const EVENT_HANDLER_METHODS = ['click', 'select', 'submit'] as const;
const USER_EVENT_METHODS = [
'clear',
'click',
'copy',
'cut',
'dblClick',
'deselectOptions',
'hover',
'keyboard',
'pointer',
'paste',
'selectOptions',
'tripleClick',
'type',
'unhover',
'upload',
'tab',
] as const;
const ALL_RETURNING_NODES = [
...PROPERTIES_RETURNING_NODES,
...METHODS_RETURNING_NODES,
] as const;
const PRESENCE_MATCHERS = [
'toBeOnTheScreen',
'toBeInTheDocument',
'toBeTruthy',
'toBeDefined',
] as const;
const ABSENCE_MATCHERS = ['toBeNull', 'toBeFalsy'] as const;
export {
ABSENCE_MATCHERS,
ALL_QUERIES_COMBINATIONS,
ALL_QUERIES_METHODS,
ALL_QUERIES_VARIANTS,
ALL_RETURNING_NODES,
ASYNC_QUERIES_COMBINATIONS,
ASYNC_QUERIES_VARIANTS,
ASYNC_UTILS,
combineQueries,
DEBUG_UTILS,
EVENT_HANDLER_METHODS,
EVENTS_SIMULATORS,
getDocsUrl,
LIBRARY_MODULES,
METHODS_RETURNING_NODES,
OLD_LIBRARY_MODULES,
PRESENCE_MATCHERS,
PROPERTIES_RETURNING_NODES,
SYNC_QUERIES_COMBINATIONS,
SYNC_QUERIES_VARIANTS,
TESTING_FRAMEWORK_SETUP_HOOKS,
USER_EVENT_METHODS,
USER_EVENT_MODULE,
};