@lvce-editor/eslint-plugin-e2e 10.0.0 → 10.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +109 -20
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const meta$
|
|
1
|
+
const meta$2 = {
|
|
2
2
|
type: 'problem',
|
|
3
3
|
docs: {
|
|
4
4
|
description: 'Disallow direct click calls in E2E tests'
|
|
@@ -10,7 +10,7 @@ const meta$1 = {
|
|
|
10
10
|
const isDirectClickCall = node => {
|
|
11
11
|
return node.callee.type === 'MemberExpression' && node.callee.property.type === 'Identifier' && node.callee.property.name === 'click';
|
|
12
12
|
};
|
|
13
|
-
const create$
|
|
13
|
+
const create$2 = context => {
|
|
14
14
|
return {
|
|
15
15
|
CallExpression(node) {
|
|
16
16
|
if (!isDirectClickCall(node)) {
|
|
@@ -26,11 +26,11 @@ const create$1 = context => {
|
|
|
26
26
|
|
|
27
27
|
const noDirectClick = {
|
|
28
28
|
__proto__: null,
|
|
29
|
-
create: create$
|
|
30
|
-
meta: meta$
|
|
29
|
+
create: create$2,
|
|
30
|
+
meta: meta$2
|
|
31
31
|
};
|
|
32
32
|
|
|
33
|
-
const meta = {
|
|
33
|
+
const meta$1 = {
|
|
34
34
|
type: 'problem',
|
|
35
35
|
docs: {
|
|
36
36
|
description: 'Disallow inline locator expressions inside expect calls'
|
|
@@ -39,26 +39,26 @@ const meta = {
|
|
|
39
39
|
noInlineLocatorInExpect: 'Assign the locator to a variable before passing it to expect(...).'
|
|
40
40
|
}
|
|
41
41
|
};
|
|
42
|
-
const isCallExpressionNode = node => {
|
|
42
|
+
const isCallExpressionNode$1 = node => {
|
|
43
43
|
return typeof node === 'object' && node !== null && 'type' in node && node.type === 'CallExpression' && 'callee' in node && 'arguments' in node;
|
|
44
44
|
};
|
|
45
|
-
const isIdentifierNode = node => {
|
|
45
|
+
const isIdentifierNode$1 = node => {
|
|
46
46
|
return typeof node === 'object' && node !== null && 'type' in node && node.type === 'Identifier' && 'name' in node;
|
|
47
47
|
};
|
|
48
|
-
const isMemberExpressionNode = node => {
|
|
48
|
+
const isMemberExpressionNode$1 = node => {
|
|
49
49
|
return typeof node === 'object' && node !== null && 'type' in node && node.type === 'MemberExpression' && 'object' in node && 'property' in node && 'computed' in node;
|
|
50
50
|
};
|
|
51
|
-
const isChainExpressionNode = node => {
|
|
51
|
+
const isChainExpressionNode$1 = node => {
|
|
52
52
|
return typeof node === 'object' && node !== null && 'type' in node && node.type === 'ChainExpression' && 'expression' in node;
|
|
53
53
|
};
|
|
54
|
-
const isAwaitExpressionNode = node => {
|
|
54
|
+
const isAwaitExpressionNode$1 = node => {
|
|
55
55
|
return typeof node === 'object' && node !== null && 'type' in node && node.type === 'AwaitExpression' && 'argument' in node;
|
|
56
56
|
};
|
|
57
57
|
const isTsNonNullExpression = node => {
|
|
58
58
|
return typeof node === 'object' && node !== null && 'type' in node && node.type === 'TSNonNullExpression' && 'expression' in node;
|
|
59
59
|
};
|
|
60
60
|
const isLocatorCall = node => {
|
|
61
|
-
return isCallExpressionNode(node) && isIdentifierNode(node.callee) && node.callee.name === 'Locator';
|
|
61
|
+
return isCallExpressionNode$1(node) && isIdentifierNode$1(node.callee) && node.callee.name === 'Locator';
|
|
62
62
|
};
|
|
63
63
|
const containsInlineLocatorCall = node => {
|
|
64
64
|
if (!node) {
|
|
@@ -67,16 +67,16 @@ const containsInlineLocatorCall = node => {
|
|
|
67
67
|
if (isLocatorCall(node)) {
|
|
68
68
|
return true;
|
|
69
69
|
}
|
|
70
|
-
if (isCallExpressionNode(node)) {
|
|
70
|
+
if (isCallExpressionNode$1(node)) {
|
|
71
71
|
return containsInlineLocatorCall(node.callee) || node.arguments.some(containsInlineLocatorCall);
|
|
72
72
|
}
|
|
73
|
-
if (isMemberExpressionNode(node)) {
|
|
73
|
+
if (isMemberExpressionNode$1(node)) {
|
|
74
74
|
return containsInlineLocatorCall(node.object) || node.computed && containsInlineLocatorCall(node.property);
|
|
75
75
|
}
|
|
76
|
-
if (isChainExpressionNode(node)) {
|
|
76
|
+
if (isChainExpressionNode$1(node)) {
|
|
77
77
|
return containsInlineLocatorCall(node.expression);
|
|
78
78
|
}
|
|
79
|
-
if (isAwaitExpressionNode(node)) {
|
|
79
|
+
if (isAwaitExpressionNode$1(node)) {
|
|
80
80
|
return containsInlineLocatorCall(node.argument);
|
|
81
81
|
}
|
|
82
82
|
if (isTsNonNullExpression(node)) {
|
|
@@ -84,13 +84,13 @@ const containsInlineLocatorCall = node => {
|
|
|
84
84
|
}
|
|
85
85
|
return false;
|
|
86
86
|
};
|
|
87
|
-
const isExpectCall = node => {
|
|
87
|
+
const isExpectCall$1 = node => {
|
|
88
88
|
return node.callee.type === 'Identifier' && node.callee.name === 'expect';
|
|
89
89
|
};
|
|
90
|
-
const create = context => {
|
|
90
|
+
const create$1 = context => {
|
|
91
91
|
return {
|
|
92
92
|
CallExpression(node) {
|
|
93
|
-
if (!isExpectCall(node)) {
|
|
93
|
+
if (!isExpectCall$1(node)) {
|
|
94
94
|
return;
|
|
95
95
|
}
|
|
96
96
|
const [firstArgument] = node.arguments;
|
|
@@ -106,6 +106,93 @@ const create = context => {
|
|
|
106
106
|
};
|
|
107
107
|
|
|
108
108
|
const noInlineLocatorInExpect = {
|
|
109
|
+
__proto__: null,
|
|
110
|
+
create: create$1,
|
|
111
|
+
meta: meta$1
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
const meta = {
|
|
115
|
+
type: 'problem',
|
|
116
|
+
docs: {
|
|
117
|
+
description: 'Disallow inline nth locator expressions inside expect calls'
|
|
118
|
+
},
|
|
119
|
+
messages: {
|
|
120
|
+
noInlineNthInExpect: 'Assign the nth locator to a variable before passing it to expect(...).'
|
|
121
|
+
}
|
|
122
|
+
};
|
|
123
|
+
const isCallExpressionNode = node => {
|
|
124
|
+
return typeof node === 'object' && node !== null && 'type' in node && node.type === 'CallExpression' && 'callee' in node && 'arguments' in node;
|
|
125
|
+
};
|
|
126
|
+
const isIdentifierNode = node => {
|
|
127
|
+
return typeof node === 'object' && node !== null && 'type' in node && node.type === 'Identifier' && 'name' in node;
|
|
128
|
+
};
|
|
129
|
+
const isMemberExpressionNode = node => {
|
|
130
|
+
return typeof node === 'object' && node !== null && 'type' in node && node.type === 'MemberExpression' && 'object' in node && 'property' in node && 'computed' in node;
|
|
131
|
+
};
|
|
132
|
+
const isChainExpressionNode = node => {
|
|
133
|
+
return typeof node === 'object' && node !== null && 'type' in node && node.type === 'ChainExpression' && 'expression' in node;
|
|
134
|
+
};
|
|
135
|
+
const isAwaitExpressionNode = node => {
|
|
136
|
+
return typeof node === 'object' && node !== null && 'type' in node && node.type === 'AwaitExpression' && 'argument' in node;
|
|
137
|
+
};
|
|
138
|
+
const isTsAsExpressionNode = node => {
|
|
139
|
+
return typeof node === 'object' && node !== null && 'type' in node && node.type === 'TSAsExpression' && 'expression' in node;
|
|
140
|
+
};
|
|
141
|
+
const isTsNonNullExpressionNode = node => {
|
|
142
|
+
return typeof node === 'object' && node !== null && 'type' in node && node.type === 'TSNonNullExpression' && 'expression' in node;
|
|
143
|
+
};
|
|
144
|
+
const isNthCall = node => {
|
|
145
|
+
return isCallExpressionNode(node) && isMemberExpressionNode(node.callee) && !node.callee.computed && isIdentifierNode(node.callee.property) && node.callee.property.name === 'nth';
|
|
146
|
+
};
|
|
147
|
+
const containsInlineNthCall = node => {
|
|
148
|
+
if (!node) {
|
|
149
|
+
return false;
|
|
150
|
+
}
|
|
151
|
+
if (isNthCall(node)) {
|
|
152
|
+
return true;
|
|
153
|
+
}
|
|
154
|
+
if (isCallExpressionNode(node)) {
|
|
155
|
+
return containsInlineNthCall(node.callee) || node.arguments.some(containsInlineNthCall);
|
|
156
|
+
}
|
|
157
|
+
if (isMemberExpressionNode(node)) {
|
|
158
|
+
return containsInlineNthCall(node.object) || node.computed && containsInlineNthCall(node.property);
|
|
159
|
+
}
|
|
160
|
+
if (isChainExpressionNode(node)) {
|
|
161
|
+
return containsInlineNthCall(node.expression);
|
|
162
|
+
}
|
|
163
|
+
if (isAwaitExpressionNode(node)) {
|
|
164
|
+
return containsInlineNthCall(node.argument);
|
|
165
|
+
}
|
|
166
|
+
if (isTsAsExpressionNode(node)) {
|
|
167
|
+
return containsInlineNthCall(node.expression);
|
|
168
|
+
}
|
|
169
|
+
if (isTsNonNullExpressionNode(node)) {
|
|
170
|
+
return containsInlineNthCall(node.expression);
|
|
171
|
+
}
|
|
172
|
+
return false;
|
|
173
|
+
};
|
|
174
|
+
const isExpectCall = node => {
|
|
175
|
+
return node.callee.type === 'Identifier' && node.callee.name === 'expect';
|
|
176
|
+
};
|
|
177
|
+
const create = context => {
|
|
178
|
+
return {
|
|
179
|
+
CallExpression(node) {
|
|
180
|
+
if (!isExpectCall(node)) {
|
|
181
|
+
return;
|
|
182
|
+
}
|
|
183
|
+
const [firstArgument] = node.arguments;
|
|
184
|
+
if (!containsInlineNthCall(firstArgument)) {
|
|
185
|
+
return;
|
|
186
|
+
}
|
|
187
|
+
context.report({
|
|
188
|
+
node: firstArgument,
|
|
189
|
+
messageId: 'noInlineNthInExpect'
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
};
|
|
193
|
+
};
|
|
194
|
+
|
|
195
|
+
const noInlineNthInExpect = {
|
|
109
196
|
__proto__: null,
|
|
110
197
|
create,
|
|
111
198
|
meta
|
|
@@ -118,7 +205,8 @@ const plugin = {
|
|
|
118
205
|
},
|
|
119
206
|
rules: {
|
|
120
207
|
'no-direct-click': noDirectClick,
|
|
121
|
-
'no-inline-locator-in-expect': noInlineLocatorInExpect
|
|
208
|
+
'no-inline-locator-in-expect': noInlineLocatorInExpect,
|
|
209
|
+
'no-inline-nth-in-expect': noInlineNthInExpect
|
|
122
210
|
},
|
|
123
211
|
configs: {}
|
|
124
212
|
};
|
|
@@ -129,7 +217,8 @@ const recommended = [{
|
|
|
129
217
|
},
|
|
130
218
|
rules: {
|
|
131
219
|
'e2e/no-direct-click': 'error',
|
|
132
|
-
'e2e/no-inline-locator-in-expect': 'error'
|
|
220
|
+
'e2e/no-inline-locator-in-expect': 'error',
|
|
221
|
+
'e2e/no-inline-nth-in-expect': 'error'
|
|
133
222
|
}
|
|
134
223
|
}];
|
|
135
224
|
|