eslint-plugin-playwright 0.5.2 → 0.8.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/README.md +29 -2
- package/lib/index.js +4 -0
- package/lib/rules/missing-playwright-await.js +28 -21
- package/lib/rules/no-page-pause.js +22 -0
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -43,7 +43,7 @@ This plugin bundles two configurations to work with both `@playwright/test` or `
|
|
|
43
43
|
|
|
44
44
|
### `missing-playwright-await` 🔧
|
|
45
45
|
|
|
46
|
-
|
|
46
|
+
Identify false positives when async Playwright APIs are not properly awaited.
|
|
47
47
|
|
|
48
48
|
#### Example
|
|
49
49
|
|
|
@@ -51,17 +51,25 @@ Example of **incorrect** code for this rule:
|
|
|
51
51
|
|
|
52
52
|
```js
|
|
53
53
|
expect(page).toMatchText("text");
|
|
54
|
+
|
|
55
|
+
test.step("clicks the button", async () => {
|
|
56
|
+
await page.click("button");
|
|
57
|
+
});
|
|
54
58
|
```
|
|
55
59
|
|
|
56
60
|
Example of **correct** code for this rule:
|
|
57
61
|
|
|
58
62
|
```js
|
|
59
63
|
await expect(page).toMatchText("text");
|
|
64
|
+
|
|
65
|
+
await test.step("clicks the button", async () => {
|
|
66
|
+
await page.click("button");
|
|
67
|
+
});
|
|
60
68
|
```
|
|
61
69
|
|
|
62
70
|
#### Options
|
|
63
71
|
|
|
64
|
-
The rule accepts a non-required option which can be used to specify custom matchers which this rule should also warn about. This is useful when creating your own async matchers.
|
|
72
|
+
The rule accepts a non-required option which can be used to specify custom matchers which this rule should also warn about. This is useful when creating your own async `expect` matchers.
|
|
65
73
|
|
|
66
74
|
```json
|
|
67
75
|
{
|
|
@@ -71,3 +79,22 @@ The rule accepts a non-required option which can be used to specify custom match
|
|
|
71
79
|
]
|
|
72
80
|
}
|
|
73
81
|
```
|
|
82
|
+
### `no-page-pause`
|
|
83
|
+
|
|
84
|
+
Prevent usage of `page.pause()`.
|
|
85
|
+
|
|
86
|
+
#### Example
|
|
87
|
+
|
|
88
|
+
Example of **incorrect** code for this rule:
|
|
89
|
+
|
|
90
|
+
```js
|
|
91
|
+
await page.click('button');
|
|
92
|
+
await page.pause();
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
Example of **correct** code for this rule:
|
|
96
|
+
|
|
97
|
+
```js
|
|
98
|
+
await page.click('button');
|
|
99
|
+
```
|
|
100
|
+
|
package/lib/index.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
const missingPlaywrightAwait = require("./rules/missing-playwright-await");
|
|
2
|
+
const noPagePause = require("./rules/no-page-pause");
|
|
2
3
|
|
|
3
4
|
module.exports = {
|
|
4
5
|
configs: {
|
|
@@ -10,6 +11,7 @@ module.exports = {
|
|
|
10
11
|
rules: {
|
|
11
12
|
"no-empty-pattern": "off",
|
|
12
13
|
"playwright/missing-playwright-await": "error",
|
|
14
|
+
"playwright/no-page-pause": "warn",
|
|
13
15
|
},
|
|
14
16
|
},
|
|
15
17
|
"jest-playwright": {
|
|
@@ -20,6 +22,7 @@ module.exports = {
|
|
|
20
22
|
},
|
|
21
23
|
rules: {
|
|
22
24
|
"playwright/missing-playwright-await": "error",
|
|
25
|
+
"playwright/no-page-pause": "warn",
|
|
23
26
|
"jest/no-standalone-expect": [
|
|
24
27
|
"error",
|
|
25
28
|
{
|
|
@@ -46,5 +49,6 @@ module.exports = {
|
|
|
46
49
|
},
|
|
47
50
|
rules: {
|
|
48
51
|
"missing-playwright-await": missingPlaywrightAwait,
|
|
52
|
+
"no-page-pause": noPagePause,
|
|
49
53
|
},
|
|
50
54
|
};
|
|
@@ -1,18 +1,25 @@
|
|
|
1
|
-
function
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
function getMemberPartName(node, part) {
|
|
2
|
+
return node[part].type === "Identifier" ? node[part].name : undefined;
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
function getMemberExpressionNode(node, matchers) {
|
|
6
|
+
const propertyName = getMemberPartName(node, "property");
|
|
7
|
+
|
|
8
|
+
if (getMemberPartName(node, "object") === "test") {
|
|
9
|
+
return propertyName === "step" ? { node, type: "testStep" } : undefined;
|
|
4
10
|
}
|
|
11
|
+
|
|
12
|
+
return matchers.has(propertyName) ? { node, type: "expect" } : undefined;
|
|
5
13
|
}
|
|
6
14
|
|
|
7
|
-
function
|
|
8
|
-
const
|
|
15
|
+
function isValid(node) {
|
|
16
|
+
const grandparentType =
|
|
9
17
|
node.parent && node.parent.parent && node.parent.parent.type;
|
|
10
18
|
|
|
11
|
-
// Don't report on nodes which are already awaited or returned
|
|
12
19
|
return (
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
20
|
+
grandparentType === "AwaitExpression" ||
|
|
21
|
+
grandparentType === "ReturnStatement" ||
|
|
22
|
+
grandparentType === "ArrowFunctionExpression"
|
|
16
23
|
);
|
|
17
24
|
}
|
|
18
25
|
|
|
@@ -51,11 +58,11 @@ const playwrightTestMatchers = [
|
|
|
51
58
|
"toHaveCSS",
|
|
52
59
|
"toHaveId",
|
|
53
60
|
"toHaveJSProperty",
|
|
61
|
+
"toBeOK",
|
|
54
62
|
"toHaveText",
|
|
55
63
|
"toHaveTitle",
|
|
56
64
|
"toHaveURL",
|
|
57
65
|
"toHaveValue",
|
|
58
|
-
"toMatchSnapshot",
|
|
59
66
|
];
|
|
60
67
|
|
|
61
68
|
module.exports = {
|
|
@@ -70,28 +77,28 @@ module.exports = {
|
|
|
70
77
|
|
|
71
78
|
return {
|
|
72
79
|
MemberExpression(statement) {
|
|
73
|
-
const
|
|
74
|
-
if (!node || isValidExpect(node)) return;
|
|
80
|
+
const result = getMemberExpressionNode(statement, matchers);
|
|
75
81
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
}
|
|
82
|
+
if (result && !isValid(result.node)) {
|
|
83
|
+
context.report({
|
|
84
|
+
fix: (fixer) => fixer.insertTextBefore(result.node, "await "),
|
|
85
|
+
messageId: result.type,
|
|
86
|
+
node: result.node,
|
|
87
|
+
});
|
|
88
|
+
}
|
|
83
89
|
},
|
|
84
90
|
};
|
|
85
91
|
},
|
|
86
92
|
meta: {
|
|
87
93
|
docs: {
|
|
88
94
|
category: "Possible Errors",
|
|
89
|
-
description:
|
|
95
|
+
description: `Identify false positives when async Playwright APIs are not properly awaited.`,
|
|
90
96
|
recommended: true,
|
|
91
97
|
},
|
|
92
98
|
fixable: "code",
|
|
93
99
|
messages: {
|
|
94
|
-
|
|
100
|
+
expect: "'expect' matchers must be awaited or returned.",
|
|
101
|
+
testStep: "'test.step' must be awaited or returned.",
|
|
95
102
|
},
|
|
96
103
|
schema: [
|
|
97
104
|
{
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
module.exports = {
|
|
2
|
+
create(context) {
|
|
3
|
+
return {
|
|
4
|
+
MemberExpression(node) {
|
|
5
|
+
if (node.object.name === "page" && node.property.name === "pause") {
|
|
6
|
+
context.report({ messageId: "noPagePause", node });
|
|
7
|
+
}
|
|
8
|
+
},
|
|
9
|
+
};
|
|
10
|
+
},
|
|
11
|
+
meta: {
|
|
12
|
+
docs: {
|
|
13
|
+
category: "Possible Errors",
|
|
14
|
+
description: "Prevent usage of page.pause()",
|
|
15
|
+
recommended: true,
|
|
16
|
+
},
|
|
17
|
+
messages: {
|
|
18
|
+
noPagePause: "Unexpected use of page.pause().",
|
|
19
|
+
},
|
|
20
|
+
type: "problem",
|
|
21
|
+
},
|
|
22
|
+
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eslint-plugin-playwright",
|
|
3
3
|
"description": "ESLint plugin for Playwright testing.",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.8.0",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"repository": "https://github.com/playwright-community/eslint-plugin-playwright",
|
|
7
7
|
"author": "Max Schmitt <max@schmitt.mx>",
|
|
@@ -13,8 +13,8 @@
|
|
|
13
13
|
"test": "jest"
|
|
14
14
|
},
|
|
15
15
|
"devDependencies": {
|
|
16
|
-
"eslint": "^
|
|
17
|
-
"jest": "^27.
|
|
16
|
+
"eslint": "^8.4.1",
|
|
17
|
+
"jest": "^27.4.5"
|
|
18
18
|
},
|
|
19
19
|
"peerDependencies": {
|
|
20
20
|
"eslint": ">=7",
|