Skip to content

Commit eeb1841

Browse files
authored
Add no page pause rule (#35)
1 parent 9b04295 commit eeb1841

File tree

4 files changed

+71
-0
lines changed

4 files changed

+71
-0
lines changed

README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,3 +79,22 @@ The rule accepts a non-required option which can be used to specify custom match
7979
]
8080
}
8181
```
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+

lib/index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ module.exports = {
1010
rules: {
1111
"no-empty-pattern": "off",
1212
"playwright/missing-playwright-await": "error",
13+
"playwright/no-page-pause": "warn",
1314
},
1415
},
1516
"jest-playwright": {
@@ -20,6 +21,7 @@ module.exports = {
2021
},
2122
rules: {
2223
"playwright/missing-playwright-await": "error",
24+
"playwright/no-page-pause": "warn",
2325
"jest/no-standalone-expect": [
2426
"error",
2527
{
@@ -46,5 +48,6 @@ module.exports = {
4648
},
4749
rules: {
4850
"missing-playwright-await": missingPlaywrightAwait,
51+
"no-page-pause": noPagePause,
4952
},
5053
};

lib/rules/no-page-pause.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
};

test/no-page-pause.spec.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
const { RuleTester } = require("eslint");
2+
const rule = require("../lib/rules/no-page-pause");
3+
4+
RuleTester.setDefaultConfig({
5+
parserOptions: {
6+
ecmaVersion: 2018,
7+
},
8+
});
9+
10+
const wrapInTest = (input) => `test('a', async () => { ${input} })`;
11+
12+
const invalid = (code) => ({
13+
code: wrapInTest(code),
14+
errors: [{ messageId: "noPagePause" }],
15+
});
16+
17+
const valid = (code) => ({
18+
code: wrapInTest(code),
19+
});
20+
21+
new RuleTester().run("no-page-pause", rule, {
22+
invalid: [invalid("await page.pause()")],
23+
valid: [
24+
valid("await page.click()"),
25+
valid("await expect(page).toBePaused()"),
26+
],
27+
});

0 commit comments

Comments
 (0)