eslint-plugin-jest 24.1.1 → 24.1.5
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/CHANGELOG.md +29 -0
- package/README.md +0 -1
- package/docs/rules/expect-expect.md +1 -1
- package/docs/rules/no-hooks.md +0 -1
- package/lib/rules/consistent-test-it.js +2 -4
- package/lib/rules/lowercase-name.js +45 -31
- package/lib/rules/no-disabled-tests.js +1 -7
- package/lib/rules/no-test-prefixes.js +3 -7
- package/lib/rules/require-top-level-describe.js +1 -1
- package/lib/rules/utils.js +9 -12
- package/lib/rules/valid-describe.js +1 -1
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,32 @@
|
|
|
1
|
+
## [24.1.5](https://github.com/jest-community/eslint-plugin-jest/compare/v24.1.4...v24.1.5) (2021-02-17)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* **require-top-level-describe:** import function that actually exists ([#763](https://github.com/jest-community/eslint-plugin-jest/issues/763)) ([d10dc07](https://github.com/jest-community/eslint-plugin-jest/commit/d10dc07d9dc933fe9584b3e13704001527896859))
|
|
7
|
+
|
|
8
|
+
## [24.1.4](https://github.com/jest-community/eslint-plugin-jest/compare/v24.1.3...v24.1.4) (2021-02-16)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Bug Fixes
|
|
12
|
+
|
|
13
|
+
* **lowercase-name:** support `.each` methods ([#746](https://github.com/jest-community/eslint-plugin-jest/issues/746)) ([3d847b2](https://github.com/jest-community/eslint-plugin-jest/commit/3d847b2164425a2afb754569dbfff52411c95610))
|
|
14
|
+
* **require-top-level-describe:** handle `describe.each` properly ([#745](https://github.com/jest-community/eslint-plugin-jest/issues/745)) ([677be45](https://github.com/jest-community/eslint-plugin-jest/commit/677be4558a3954e364b0c4150678a4d3fd832337))
|
|
15
|
+
|
|
16
|
+
## [24.1.3](https://github.com/jest-community/eslint-plugin-jest/compare/v24.1.2...v24.1.3) (2020-11-12)
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
### Bug Fixes
|
|
20
|
+
|
|
21
|
+
* revert change causing regressions for test.each ([#713](https://github.com/jest-community/eslint-plugin-jest/issues/713)) ([7c8d75a](https://github.com/jest-community/eslint-plugin-jest/commit/7c8d75a4fcbd2c6ce005cf4f57d676c7c44ce0b2)), closes [#710](https://github.com/jest-community/eslint-plugin-jest/issues/710) [#711](https://github.com/jest-community/eslint-plugin-jest/issues/711)
|
|
22
|
+
|
|
23
|
+
## [24.1.2](https://github.com/jest-community/eslint-plugin-jest/compare/v24.1.1...v24.1.2) (2020-11-12)
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
### Bug Fixes
|
|
27
|
+
|
|
28
|
+
* **no-done-callback:** fix regression with it.each ([#708](https://github.com/jest-community/eslint-plugin-jest/issues/708)) ([2f032f8](https://github.com/jest-community/eslint-plugin-jest/commit/2f032f8d890e3717359d099b1e93e0cc6b52996a))
|
|
29
|
+
|
|
1
30
|
## [24.1.1](https://github.com/jest-community/eslint-plugin-jest/compare/v24.1.0...v24.1.1) (2020-11-12)
|
|
2
31
|
|
|
3
32
|
|
package/README.md
CHANGED
|
@@ -10,7 +10,6 @@
|
|
|
10
10
|
</div>
|
|
11
11
|
|
|
12
12
|
[](https://github.com/jest-community/eslint-plugin-jest/actions)
|
|
13
|
-
[](https://renovatebot.com/)
|
|
14
13
|
|
|
15
14
|
## Installation
|
|
16
15
|
|
|
@@ -74,7 +74,7 @@ test('returns sum', () => {
|
|
|
74
74
|
});
|
|
75
75
|
```
|
|
76
76
|
|
|
77
|
-
Since the string is compiled into
|
|
77
|
+
Since the string is compiled into a regular expression, you'll need to escape
|
|
78
78
|
special characters such as `$` with a double backslash:
|
|
79
79
|
|
|
80
80
|
```js
|
package/docs/rules/no-hooks.md
CHANGED
|
@@ -60,8 +60,6 @@ var _default = (0, _utils.createRule)({
|
|
|
60
60
|
describeNestingLevel++;
|
|
61
61
|
}
|
|
62
62
|
|
|
63
|
-
const funcNode = node.callee.type === _experimentalUtils.AST_NODE_TYPES.TaggedTemplateExpression ? node.callee.tag : node.callee;
|
|
64
|
-
|
|
65
63
|
if ((0, _utils.isTestCase)(node) && describeNestingLevel === 0 && !nodeName.includes(testKeyword)) {
|
|
66
64
|
const oppositeTestKeyword = getOppositeTestKeyword(testKeyword);
|
|
67
65
|
context.report({
|
|
@@ -71,7 +69,7 @@ var _default = (0, _utils.createRule)({
|
|
|
71
69
|
testKeyword,
|
|
72
70
|
oppositeTestKeyword
|
|
73
71
|
},
|
|
74
|
-
fix: buildFixer(
|
|
72
|
+
fix: buildFixer(node.callee, nodeName, testKeyword)
|
|
75
73
|
});
|
|
76
74
|
}
|
|
77
75
|
|
|
@@ -84,7 +82,7 @@ var _default = (0, _utils.createRule)({
|
|
|
84
82
|
testKeywordWithinDescribe,
|
|
85
83
|
oppositeTestKeyword
|
|
86
84
|
},
|
|
87
|
-
fix: buildFixer(
|
|
85
|
+
fix: buildFixer(node.callee, nodeName, testKeywordWithinDescribe)
|
|
88
86
|
});
|
|
89
87
|
}
|
|
90
88
|
},
|
|
@@ -11,22 +11,26 @@ var _utils = require("./utils");
|
|
|
11
11
|
|
|
12
12
|
const hasStringAsFirstArgument = node => node.arguments[0] && (0, _utils.isStringNode)(node.arguments[0]);
|
|
13
13
|
|
|
14
|
-
const
|
|
14
|
+
const findNodeNameAndArgument = node => {
|
|
15
|
+
if (!((0, _utils.isTestCase)(node) || (0, _utils.isDescribe)(node))) {
|
|
16
|
+
return null;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
if ((0, _utils.isEachCall)(node)) {
|
|
20
|
+
var _node$parent;
|
|
15
21
|
|
|
16
|
-
|
|
17
|
-
|
|
22
|
+
if (((_node$parent = node.parent) === null || _node$parent === void 0 ? void 0 : _node$parent.type) === _experimentalUtils.AST_NODE_TYPES.CallExpression && hasStringAsFirstArgument(node.parent)) {
|
|
23
|
+
return [node.callee.object.name, node.parent.arguments[0]];
|
|
24
|
+
}
|
|
18
25
|
|
|
19
|
-
if (allowedPrefixes.some(name => description.startsWith(name))) {
|
|
20
26
|
return null;
|
|
21
27
|
}
|
|
22
28
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
if (!firstCharacter || firstCharacter === firstCharacter.toLowerCase()) {
|
|
29
|
+
if (node.callee.type !== _experimentalUtils.AST_NODE_TYPES.Identifier || !hasStringAsFirstArgument(node)) {
|
|
26
30
|
return null;
|
|
27
31
|
}
|
|
28
32
|
|
|
29
|
-
return node.callee.name;
|
|
33
|
+
return [node.callee.name, node.arguments[0]];
|
|
30
34
|
};
|
|
31
35
|
|
|
32
36
|
var _default = (0, _utils.createRule)({
|
|
@@ -81,10 +85,6 @@ var _default = (0, _utils.createRule)({
|
|
|
81
85
|
let numberOfDescribeBlocks = 0;
|
|
82
86
|
return {
|
|
83
87
|
CallExpression(node) {
|
|
84
|
-
if (!isJestFunctionWithLiteralArg(node)) {
|
|
85
|
-
return;
|
|
86
|
-
}
|
|
87
|
-
|
|
88
88
|
if ((0, _utils.isDescribe)(node)) {
|
|
89
89
|
numberOfDescribeBlocks++;
|
|
90
90
|
|
|
@@ -93,26 +93,40 @@ var _default = (0, _utils.createRule)({
|
|
|
93
93
|
}
|
|
94
94
|
}
|
|
95
95
|
|
|
96
|
-
const
|
|
97
|
-
|
|
98
|
-
if (
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
});
|
|
96
|
+
const results = findNodeNameAndArgument(node);
|
|
97
|
+
|
|
98
|
+
if (!results) {
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
const [name, firstArg] = results;
|
|
103
|
+
const description = (0, _utils.getStringValue)(firstArg);
|
|
104
|
+
|
|
105
|
+
if (allowedPrefixes.some(name => description.startsWith(name))) {
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
const firstCharacter = description.charAt(0);
|
|
110
|
+
|
|
111
|
+
if (!firstCharacter || firstCharacter === firstCharacter.toLowerCase() || ignore.includes(name)) {
|
|
112
|
+
return;
|
|
115
113
|
}
|
|
114
|
+
|
|
115
|
+
context.report({
|
|
116
|
+
messageId: 'unexpectedLowercase',
|
|
117
|
+
node: node.arguments[0],
|
|
118
|
+
data: {
|
|
119
|
+
method: name
|
|
120
|
+
},
|
|
121
|
+
|
|
122
|
+
fix(fixer) {
|
|
123
|
+
const description = (0, _utils.getStringValue)(firstArg);
|
|
124
|
+
const rangeIgnoringQuotes = [firstArg.range[0] + 1, firstArg.range[1] - 1];
|
|
125
|
+
const newDescription = description.substring(0, 1).toLowerCase() + description.substring(1);
|
|
126
|
+
return [fixer.replaceTextRange(rangeIgnoringQuotes, newDescription)];
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
});
|
|
116
130
|
},
|
|
117
131
|
|
|
118
132
|
'CallExpression:exit'(node) {
|
|
@@ -50,9 +50,7 @@ var _default = (0, _utils.createRule)({
|
|
|
50
50
|
},
|
|
51
51
|
|
|
52
52
|
CallExpression(node) {
|
|
53
|
-
const functionName = (0, _utils.getNodeName)(node.callee);
|
|
54
|
-
|
|
55
|
-
if (node.callee.type === 'CallExpression') return;
|
|
53
|
+
const functionName = (0, _utils.getNodeName)(node.callee);
|
|
56
54
|
|
|
57
55
|
switch (functionName) {
|
|
58
56
|
case 'describe.skip':
|
|
@@ -66,10 +64,6 @@ var _default = (0, _utils.createRule)({
|
|
|
66
64
|
case 'it.concurrent.skip':
|
|
67
65
|
case 'test.skip':
|
|
68
66
|
case 'test.concurrent.skip':
|
|
69
|
-
case 'it.skip.each':
|
|
70
|
-
case 'test.skip.each':
|
|
71
|
-
case 'xit.each':
|
|
72
|
-
case 'xtest.each':
|
|
73
67
|
context.report({
|
|
74
68
|
messageId: 'skippedTest',
|
|
75
69
|
node
|
|
@@ -5,8 +5,6 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
|
|
8
|
-
var _experimentalUtils = require("@typescript-eslint/experimental-utils");
|
|
9
|
-
|
|
10
8
|
var _utils = require("./utils");
|
|
11
9
|
|
|
12
10
|
var _default = (0, _utils.createRule)({
|
|
@@ -33,7 +31,6 @@ var _default = (0, _utils.createRule)({
|
|
|
33
31
|
if (!nodeName || !(0, _utils.isDescribe)(node) && !(0, _utils.isTestCase)(node)) return;
|
|
34
32
|
const preferredNodeName = getPreferredNodeName(nodeName);
|
|
35
33
|
if (!preferredNodeName) return;
|
|
36
|
-
const funcNode = node.callee.type === _experimentalUtils.AST_NODE_TYPES.TaggedTemplateExpression ? node.callee.tag : node.callee;
|
|
37
34
|
context.report({
|
|
38
35
|
messageId: 'usePreferredName',
|
|
39
36
|
node: node.callee,
|
|
@@ -42,7 +39,7 @@ var _default = (0, _utils.createRule)({
|
|
|
42
39
|
},
|
|
43
40
|
|
|
44
41
|
fix(fixer) {
|
|
45
|
-
return [fixer.replaceText(
|
|
42
|
+
return [fixer.replaceText(node.callee, preferredNodeName)];
|
|
46
43
|
}
|
|
47
44
|
|
|
48
45
|
});
|
|
@@ -57,14 +54,13 @@ exports.default = _default;
|
|
|
57
54
|
|
|
58
55
|
function getPreferredNodeName(nodeName) {
|
|
59
56
|
const firstChar = nodeName.charAt(0);
|
|
60
|
-
const suffix = nodeName.endsWith('.each') ? '.each' : '';
|
|
61
57
|
|
|
62
58
|
if (firstChar === 'f') {
|
|
63
|
-
return `${nodeName.slice(1)
|
|
59
|
+
return `${nodeName.slice(1)}.only`;
|
|
64
60
|
}
|
|
65
61
|
|
|
66
62
|
if (firstChar === 'x') {
|
|
67
|
-
return `${nodeName.slice(1)
|
|
63
|
+
return `${nodeName.slice(1)}.skip`;
|
|
68
64
|
}
|
|
69
65
|
|
|
70
66
|
return null;
|
package/lib/rules/utils.js
CHANGED
|
@@ -4,7 +4,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.getNodeName = getNodeName;
|
|
7
|
-
exports.scopeHasLocalReference = exports.getJestFunctionArguments = exports.
|
|
7
|
+
exports.scopeHasLocalReference = exports.getJestFunctionArguments = exports.isEachCall = exports.isDescribe = exports.isTestCase = exports.getTestCallExpressionsFromDeclaredVariables = exports.isHook = exports.isFunction = exports.TestCaseProperty = exports.DescribeProperty = exports.HookName = exports.TestCaseName = exports.DescribeAlias = exports.parseExpectCall = exports.isParsedEqualityMatcherCall = exports.EqualityMatcher = exports.ModifierName = exports.isExpectMember = exports.isExpectCall = exports.getAccessorValue = exports.isSupportedAccessor = exports.hasOnlyOneArgument = exports.getStringValue = exports.isStringNode = exports.followTypeAssertionChain = exports.createRule = void 0;
|
|
8
8
|
|
|
9
9
|
var _path = require("path");
|
|
10
10
|
|
|
@@ -363,9 +363,6 @@ function getNodeName(node) {
|
|
|
363
363
|
}
|
|
364
364
|
|
|
365
365
|
switch (node.type) {
|
|
366
|
-
case _experimentalUtils.AST_NODE_TYPES.TaggedTemplateExpression:
|
|
367
|
-
return getNodeName(node.tag);
|
|
368
|
-
|
|
369
366
|
case _experimentalUtils.AST_NODE_TYPES.MemberExpression:
|
|
370
367
|
return joinNames(getNodeName(node.object), getNodeName(node.property));
|
|
371
368
|
|
|
@@ -395,24 +392,24 @@ const getTestCallExpressionsFromDeclaredVariables = declaredVariables => {
|
|
|
395
392
|
|
|
396
393
|
exports.getTestCallExpressionsFromDeclaredVariables = getTestCallExpressionsFromDeclaredVariables;
|
|
397
394
|
|
|
398
|
-
const isTestCase = node => node.callee.type === _experimentalUtils.AST_NODE_TYPES.Identifier && TestCaseName.hasOwnProperty(node.callee.name) ||
|
|
399
|
-
node.callee.type === _experimentalUtils.AST_NODE_TYPES.TaggedTemplateExpression && node.callee.tag.type === _experimentalUtils.AST_NODE_TYPES.MemberExpression && isSupportedAccessor(node.callee.tag.property, TestCaseProperty.each) || // e.g. it.concurrent.{skip,only}
|
|
400
|
-
node.callee.type === _experimentalUtils.AST_NODE_TYPES.MemberExpression && node.callee.property.type === _experimentalUtils.AST_NODE_TYPES.Identifier && TestCaseProperty.hasOwnProperty(node.callee.property.name) && (node.callee.object.type === _experimentalUtils.AST_NODE_TYPES.Identifier && TestCaseName.hasOwnProperty(node.callee.object.name) || node.callee.object.type === _experimentalUtils.AST_NODE_TYPES.MemberExpression && node.callee.object.object.type === _experimentalUtils.AST_NODE_TYPES.Identifier && TestCaseName.hasOwnProperty(node.callee.object.object.name));
|
|
395
|
+
const isTestCase = node => node.callee.type === _experimentalUtils.AST_NODE_TYPES.Identifier && TestCaseName.hasOwnProperty(node.callee.name) || node.callee.type === _experimentalUtils.AST_NODE_TYPES.MemberExpression && node.callee.property.type === _experimentalUtils.AST_NODE_TYPES.Identifier && TestCaseProperty.hasOwnProperty(node.callee.property.name) && (node.callee.object.type === _experimentalUtils.AST_NODE_TYPES.Identifier && TestCaseName.hasOwnProperty(node.callee.object.name) || node.callee.object.type === _experimentalUtils.AST_NODE_TYPES.MemberExpression && node.callee.object.object.type === _experimentalUtils.AST_NODE_TYPES.Identifier && TestCaseName.hasOwnProperty(node.callee.object.object.name));
|
|
401
396
|
|
|
402
397
|
exports.isTestCase = isTestCase;
|
|
403
398
|
|
|
404
399
|
const isDescribe = node => node.callee.type === _experimentalUtils.AST_NODE_TYPES.Identifier && DescribeAlias.hasOwnProperty(node.callee.name) || node.callee.type === _experimentalUtils.AST_NODE_TYPES.MemberExpression && node.callee.object.type === _experimentalUtils.AST_NODE_TYPES.Identifier && DescribeAlias.hasOwnProperty(node.callee.object.name) && node.callee.property.type === _experimentalUtils.AST_NODE_TYPES.Identifier && DescribeProperty.hasOwnProperty(node.callee.property.name);
|
|
405
400
|
/**
|
|
406
|
-
* Checks if the given `
|
|
401
|
+
* Checks if the given node` is a call to `<describe|test|it>.each(...)`.
|
|
402
|
+
* If `true`, the code must look like `<method>.each(...)`.
|
|
403
|
+
*
|
|
404
|
+
* @param {JestFunctionCallExpression<DescribeAlias | TestCaseName>} node
|
|
407
405
|
*
|
|
408
|
-
* @
|
|
409
|
-
* @return {node is JestFunctionCallExpression<DescribeAlias, DescribeProperty.each>}
|
|
406
|
+
* @return {node is JestFunctionCallExpressionWithMemberExpressionCallee<DescribeAlias | TestCaseName, DescribeProperty.each | TestCaseProperty.each>}
|
|
410
407
|
*/
|
|
411
408
|
|
|
412
409
|
|
|
413
410
|
exports.isDescribe = isDescribe;
|
|
414
411
|
|
|
415
|
-
const
|
|
412
|
+
const isEachCall = node => node.callee.type === _experimentalUtils.AST_NODE_TYPES.MemberExpression && isSupportedAccessor(node.callee.property, DescribeProperty.each);
|
|
416
413
|
/**
|
|
417
414
|
* Gets the arguments of the given `JestFunctionCallExpression`.
|
|
418
415
|
*
|
|
@@ -425,7 +422,7 @@ const isDescribeEach = node => node.callee.type === _experimentalUtils.AST_NODE_
|
|
|
425
422
|
*/
|
|
426
423
|
|
|
427
424
|
|
|
428
|
-
exports.
|
|
425
|
+
exports.isEachCall = isEachCall;
|
|
429
426
|
|
|
430
427
|
const getJestFunctionArguments = node => node.callee.type === _experimentalUtils.AST_NODE_TYPES.MemberExpression && isSupportedAccessor(node.callee.property, DescribeProperty.each) && node.parent && node.parent.type === _experimentalUtils.AST_NODE_TYPES.CallExpression ? node.parent.arguments : node.arguments;
|
|
431
428
|
|
|
@@ -79,7 +79,7 @@ var _default = (0, _utils.createRule)({
|
|
|
79
79
|
});
|
|
80
80
|
}
|
|
81
81
|
|
|
82
|
-
if (!(0, _utils.
|
|
82
|
+
if (!(0, _utils.isEachCall)(node) && callback.params.length) {
|
|
83
83
|
context.report({
|
|
84
84
|
messageId: 'unexpectedDescribeArgument',
|
|
85
85
|
loc: paramsLocation(callback.params)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eslint-plugin-jest",
|
|
3
|
-
"version": "24.1.
|
|
3
|
+
"version": "24.1.5",
|
|
4
4
|
"description": "Eslint rules for Jest",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"eslint",
|
|
@@ -105,7 +105,7 @@
|
|
|
105
105
|
"eslint": "^5.1.0 || ^6.0.0 || ^7.0.0",
|
|
106
106
|
"eslint-config-prettier": "^6.5.0",
|
|
107
107
|
"eslint-plugin-eslint-comments": "^3.1.2",
|
|
108
|
-
"eslint-plugin-eslint-config": "^
|
|
108
|
+
"eslint-plugin-eslint-config": "^2.0.0",
|
|
109
109
|
"eslint-plugin-eslint-plugin": "^2.0.0",
|
|
110
110
|
"eslint-plugin-import": "^2.20.2",
|
|
111
111
|
"eslint-plugin-node": "^11.0.0",
|