@lvce-editor/eslint-plugin-e2e 10.0.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 +136 -0
- package/package.json +13 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
const meta$1 = {
|
|
2
|
+
type: 'problem',
|
|
3
|
+
docs: {
|
|
4
|
+
description: 'Disallow direct click calls in E2E tests'
|
|
5
|
+
},
|
|
6
|
+
messages: {
|
|
7
|
+
noDirectClick: 'Do not call .click() directly in e2e tests. Use Command.execute(...) or the page object API instead.'
|
|
8
|
+
}
|
|
9
|
+
};
|
|
10
|
+
const isDirectClickCall = node => {
|
|
11
|
+
return node.callee.type === 'MemberExpression' && node.callee.property.type === 'Identifier' && node.callee.property.name === 'click';
|
|
12
|
+
};
|
|
13
|
+
const create$1 = context => {
|
|
14
|
+
return {
|
|
15
|
+
CallExpression(node) {
|
|
16
|
+
if (!isDirectClickCall(node)) {
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
context.report({
|
|
20
|
+
node: node.callee.property,
|
|
21
|
+
messageId: 'noDirectClick'
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
const noDirectClick = {
|
|
28
|
+
__proto__: null,
|
|
29
|
+
create: create$1,
|
|
30
|
+
meta: meta$1
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
const meta = {
|
|
34
|
+
type: 'problem',
|
|
35
|
+
docs: {
|
|
36
|
+
description: 'Disallow inline locator expressions inside expect calls'
|
|
37
|
+
},
|
|
38
|
+
messages: {
|
|
39
|
+
noInlineLocatorInExpect: 'Assign the locator to a variable before passing it to expect(...).'
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
const isCallExpressionNode = node => {
|
|
43
|
+
return typeof node === 'object' && node !== null && 'type' in node && node.type === 'CallExpression' && 'callee' in node && 'arguments' in node;
|
|
44
|
+
};
|
|
45
|
+
const isIdentifierNode = node => {
|
|
46
|
+
return typeof node === 'object' && node !== null && 'type' in node && node.type === 'Identifier' && 'name' in node;
|
|
47
|
+
};
|
|
48
|
+
const isMemberExpressionNode = node => {
|
|
49
|
+
return typeof node === 'object' && node !== null && 'type' in node && node.type === 'MemberExpression' && 'object' in node && 'property' in node && 'computed' in node;
|
|
50
|
+
};
|
|
51
|
+
const isChainExpressionNode = node => {
|
|
52
|
+
return typeof node === 'object' && node !== null && 'type' in node && node.type === 'ChainExpression' && 'expression' in node;
|
|
53
|
+
};
|
|
54
|
+
const isAwaitExpressionNode = node => {
|
|
55
|
+
return typeof node === 'object' && node !== null && 'type' in node && node.type === 'AwaitExpression' && 'argument' in node;
|
|
56
|
+
};
|
|
57
|
+
const isTsNonNullExpression = node => {
|
|
58
|
+
return typeof node === 'object' && node !== null && 'type' in node && node.type === 'TSNonNullExpression' && 'expression' in node;
|
|
59
|
+
};
|
|
60
|
+
const isLocatorCall = node => {
|
|
61
|
+
return isCallExpressionNode(node) && isIdentifierNode(node.callee) && node.callee.name === 'Locator';
|
|
62
|
+
};
|
|
63
|
+
const containsInlineLocatorCall = node => {
|
|
64
|
+
if (!node) {
|
|
65
|
+
return false;
|
|
66
|
+
}
|
|
67
|
+
if (isLocatorCall(node)) {
|
|
68
|
+
return true;
|
|
69
|
+
}
|
|
70
|
+
if (isCallExpressionNode(node)) {
|
|
71
|
+
return containsInlineLocatorCall(node.callee) || node.arguments.some(containsInlineLocatorCall);
|
|
72
|
+
}
|
|
73
|
+
if (isMemberExpressionNode(node)) {
|
|
74
|
+
return containsInlineLocatorCall(node.object) || node.computed && containsInlineLocatorCall(node.property);
|
|
75
|
+
}
|
|
76
|
+
if (isChainExpressionNode(node)) {
|
|
77
|
+
return containsInlineLocatorCall(node.expression);
|
|
78
|
+
}
|
|
79
|
+
if (isAwaitExpressionNode(node)) {
|
|
80
|
+
return containsInlineLocatorCall(node.argument);
|
|
81
|
+
}
|
|
82
|
+
if (isTsNonNullExpression(node)) {
|
|
83
|
+
return containsInlineLocatorCall(node.expression);
|
|
84
|
+
}
|
|
85
|
+
return false;
|
|
86
|
+
};
|
|
87
|
+
const isExpectCall = node => {
|
|
88
|
+
return node.callee.type === 'Identifier' && node.callee.name === 'expect';
|
|
89
|
+
};
|
|
90
|
+
const create = context => {
|
|
91
|
+
return {
|
|
92
|
+
CallExpression(node) {
|
|
93
|
+
if (!isExpectCall(node)) {
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
const [firstArgument] = node.arguments;
|
|
97
|
+
if (!containsInlineLocatorCall(firstArgument)) {
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
context.report({
|
|
101
|
+
node: firstArgument,
|
|
102
|
+
messageId: 'noInlineLocatorInExpect'
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
};
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
const noInlineLocatorInExpect = {
|
|
109
|
+
__proto__: null,
|
|
110
|
+
create,
|
|
111
|
+
meta
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
const plugin = {
|
|
115
|
+
meta: {
|
|
116
|
+
name: 'e2e',
|
|
117
|
+
version: '0.0.1'
|
|
118
|
+
},
|
|
119
|
+
rules: {
|
|
120
|
+
'no-direct-click': noDirectClick,
|
|
121
|
+
'no-inline-locator-in-expect': noInlineLocatorInExpect
|
|
122
|
+
},
|
|
123
|
+
configs: {}
|
|
124
|
+
};
|
|
125
|
+
const recommended = [{
|
|
126
|
+
files: ['**/e2e/**/*.ts'],
|
|
127
|
+
plugins: {
|
|
128
|
+
e2e: plugin
|
|
129
|
+
},
|
|
130
|
+
rules: {
|
|
131
|
+
'e2e/no-direct-click': 'error',
|
|
132
|
+
'e2e/no-inline-locator-in-expect': 'error'
|
|
133
|
+
}
|
|
134
|
+
}];
|
|
135
|
+
|
|
136
|
+
export { recommended as default };
|
package/package.json
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@lvce-editor/eslint-plugin-e2e",
|
|
3
|
+
"version": "10.0.0",
|
|
4
|
+
"main": "dist/index.js",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "git+https://github.com/lvce-editor/eslint-config.git"
|
|
8
|
+
},
|
|
9
|
+
"type": "module",
|
|
10
|
+
"keywords": [],
|
|
11
|
+
"license": "MIT",
|
|
12
|
+
"description": ""
|
|
13
|
+
}
|