eslint-plugin-playwright 0.15.2 → 0.16.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 +26 -0
- package/lib/index.js +2 -0
- package/lib/rules/expect-expect.js +19 -1
- package/lib/rules/no-raw-locators.js +29 -0
- package/lib/utils/ast.js +1 -1
- package/lib/utils/misc.js +9 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -47,6 +47,32 @@ This plugin bundles two configurations to work with both `@playwright/test` or
|
|
|
47
47
|
}
|
|
48
48
|
```
|
|
49
49
|
|
|
50
|
+
## Global Settings
|
|
51
|
+
|
|
52
|
+
The plugin reads global settings from your ESLint configuration's shared data
|
|
53
|
+
under the `playwright` key. It supports the following settings:
|
|
54
|
+
|
|
55
|
+
- `additionalAssertFunctionNames`: an array of function names to treat as
|
|
56
|
+
assertion functions for the case of rules like `expect-expect`, which enforces
|
|
57
|
+
the presence of at least one assertion per test case. This allows such rules
|
|
58
|
+
to recognise custom assertion functions as valid assertions. The global
|
|
59
|
+
setting applies to all modules. The
|
|
60
|
+
[`expect-expect` rule accepts an option by the same name](./rules/expect-expect.md#additionalassertfunctionnames)
|
|
61
|
+
to enable per-module configuration (.e.g, for module-specific custom assert
|
|
62
|
+
functions).
|
|
63
|
+
|
|
64
|
+
You can configure these settings like so:
|
|
65
|
+
|
|
66
|
+
```json
|
|
67
|
+
{
|
|
68
|
+
"settings": {
|
|
69
|
+
"playwright": {
|
|
70
|
+
"additionalAssertFunctionNames": ["assertCustomCondition"]
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
```
|
|
75
|
+
|
|
50
76
|
## List of Supported Rules
|
|
51
77
|
|
|
52
78
|
✔: Enabled in the recommended configuration.\
|
package/lib/index.js
CHANGED
|
@@ -11,6 +11,7 @@ const no_nested_step_1 = require("./rules/no-nested-step");
|
|
|
11
11
|
const no_networkidle_1 = require("./rules/no-networkidle");
|
|
12
12
|
const no_nth_methods_1 = require("./rules/no-nth-methods");
|
|
13
13
|
const no_page_pause_1 = require("./rules/no-page-pause");
|
|
14
|
+
const no_raw_locators_1 = require("./rules/no-raw-locators");
|
|
14
15
|
const no_restricted_matchers_1 = require("./rules/no-restricted-matchers");
|
|
15
16
|
const no_skipped_test_1 = require("./rules/no-skipped-test");
|
|
16
17
|
const no_useless_await_1 = require("./rules/no-useless-await");
|
|
@@ -101,6 +102,7 @@ module.exports = {
|
|
|
101
102
|
'no-networkidle': no_networkidle_1.default,
|
|
102
103
|
'no-nth-methods': no_nth_methods_1.default,
|
|
103
104
|
'no-page-pause': no_page_pause_1.default,
|
|
105
|
+
'no-raw-locators': no_raw_locators_1.default,
|
|
104
106
|
'no-restricted-matchers': no_restricted_matchers_1.default,
|
|
105
107
|
'no-skipped-test': no_skipped_test_1.default,
|
|
106
108
|
'no-useless-await': no_useless_await_1.default,
|
|
@@ -1,9 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const ast_1 = require("../utils/ast");
|
|
4
|
+
const misc_1 = require("../utils/misc");
|
|
5
|
+
function isAssertionCall(node, additionalAssertFunctionNames) {
|
|
6
|
+
return ((0, ast_1.isExpectCall)(node) ||
|
|
7
|
+
additionalAssertFunctionNames.find((name) => (0, ast_1.isIdentifier)(node.callee, name)));
|
|
8
|
+
}
|
|
4
9
|
exports.default = {
|
|
5
10
|
create(context) {
|
|
6
11
|
const unchecked = [];
|
|
12
|
+
const additionalAssertFunctionNames = (0, misc_1.getAdditionalAssertFunctionNames)(context);
|
|
7
13
|
function checkExpressions(nodes) {
|
|
8
14
|
for (const node of nodes) {
|
|
9
15
|
const index = node.type === 'CallExpression' ? unchecked.indexOf(node) : -1;
|
|
@@ -18,7 +24,7 @@ exports.default = {
|
|
|
18
24
|
if ((0, ast_1.isTest)(node, ['fixme', 'only', 'skip'])) {
|
|
19
25
|
unchecked.push(node);
|
|
20
26
|
}
|
|
21
|
-
else if ((
|
|
27
|
+
else if (isAssertionCall(node, additionalAssertFunctionNames)) {
|
|
22
28
|
checkExpressions(context.getAncestors());
|
|
23
29
|
}
|
|
24
30
|
},
|
|
@@ -39,6 +45,18 @@ exports.default = {
|
|
|
39
45
|
messages: {
|
|
40
46
|
noAssertions: 'Test has no assertions',
|
|
41
47
|
},
|
|
48
|
+
schema: [
|
|
49
|
+
{
|
|
50
|
+
additionalProperties: false,
|
|
51
|
+
properties: {
|
|
52
|
+
additionalAssertFunctionNames: {
|
|
53
|
+
items: [{ type: 'string' }],
|
|
54
|
+
type: 'array',
|
|
55
|
+
},
|
|
56
|
+
},
|
|
57
|
+
type: 'object',
|
|
58
|
+
},
|
|
59
|
+
],
|
|
42
60
|
type: 'problem',
|
|
43
61
|
},
|
|
44
62
|
};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const ast_1 = require("../utils/ast");
|
|
4
|
+
exports.default = {
|
|
5
|
+
create(context) {
|
|
6
|
+
return {
|
|
7
|
+
CallExpression(node) {
|
|
8
|
+
if (node.callee.type !== 'MemberExpression')
|
|
9
|
+
return;
|
|
10
|
+
const method = (0, ast_1.getStringValue)(node.callee.property);
|
|
11
|
+
if ((0, ast_1.isPageMethod)(node, 'locator') || method === 'locator') {
|
|
12
|
+
context.report({ messageId: 'noRawLocator', node });
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
};
|
|
16
|
+
},
|
|
17
|
+
meta: {
|
|
18
|
+
docs: {
|
|
19
|
+
category: 'Best Practices',
|
|
20
|
+
description: 'Disallows the usage of raw locators',
|
|
21
|
+
recommended: false,
|
|
22
|
+
url: 'https://github.com/playwright-community/eslint-plugin-playwright/tree/main/docs/rules/no-raw-locators.md',
|
|
23
|
+
},
|
|
24
|
+
messages: {
|
|
25
|
+
noRawLocator: 'Usage of raw locator detected. Use methods like .getByRole() or .getByText() instead of raw locators.',
|
|
26
|
+
},
|
|
27
|
+
type: 'suggestion',
|
|
28
|
+
},
|
|
29
|
+
};
|
package/lib/utils/ast.js
CHANGED
|
@@ -95,7 +95,7 @@ function isTestHook(node) {
|
|
|
95
95
|
exports.isTestHook = isTestHook;
|
|
96
96
|
const expectSubCommands = new Set(['soft', 'poll']);
|
|
97
97
|
function getExpectType(node) {
|
|
98
|
-
if (isIdentifier(node.callee,
|
|
98
|
+
if (isIdentifier(node.callee, /(^expect|Expect)$/)) {
|
|
99
99
|
return 'standalone';
|
|
100
100
|
}
|
|
101
101
|
if (node.callee.type === 'MemberExpression' &&
|
package/lib/utils/misc.js
CHANGED
|
@@ -1,8 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getAmountData = void 0;
|
|
3
|
+
exports.getAdditionalAssertFunctionNames = exports.getAmountData = void 0;
|
|
4
4
|
const getAmountData = (amount) => ({
|
|
5
5
|
amount: amount.toString(),
|
|
6
6
|
s: amount === 1 ? '' : 's',
|
|
7
7
|
});
|
|
8
8
|
exports.getAmountData = getAmountData;
|
|
9
|
+
function getAdditionalAssertFunctionNames(context) {
|
|
10
|
+
const globalSettings = context.settings.playwright?.additionalAssertFunctionNames ??
|
|
11
|
+
[];
|
|
12
|
+
const ruleSettings = context.options[0]
|
|
13
|
+
?.additionalAssertFunctionNames ?? [];
|
|
14
|
+
return [...globalSettings, ...ruleSettings];
|
|
15
|
+
}
|
|
16
|
+
exports.getAdditionalAssertFunctionNames = getAdditionalAssertFunctionNames;
|
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.16.0",
|
|
5
5
|
"packageManager": "pnpm@8.4.0",
|
|
6
6
|
"main": "lib/index.js",
|
|
7
7
|
"repository": "https://github.com/playwright-community/eslint-plugin-playwright",
|