eslint-plugin-jest 25.0.4 → 25.2.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/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,32 @@
|
|
|
1
|
+
# [25.2.0](https://github.com/jest-community/eslint-plugin-jest/compare/v25.1.0...v25.2.0) (2021-10-14)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Features
|
|
5
|
+
|
|
6
|
+
* **expect-expect:** support `additionalTestBlockFunctions` option ([#850](https://github.com/jest-community/eslint-plugin-jest/issues/850)) ([3b94c62](https://github.com/jest-community/eslint-plugin-jest/commit/3b94c62b81a50bc8b213c597bb59799cff1ef207))
|
|
7
|
+
|
|
8
|
+
# [25.1.0](https://github.com/jest-community/eslint-plugin-jest/compare/v25.0.6...v25.1.0) (2021-10-14)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Features
|
|
12
|
+
|
|
13
|
+
* support `eslint@8` ([#940](https://github.com/jest-community/eslint-plugin-jest/issues/940)) ([5a9e45f](https://github.com/jest-community/eslint-plugin-jest/commit/5a9e45f61888a3c32eac3cbfeaf3acdfaa5d9c83))
|
|
14
|
+
|
|
15
|
+
## [25.0.6](https://github.com/jest-community/eslint-plugin-jest/compare/v25.0.5...v25.0.6) (2021-10-14)
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
### Bug Fixes
|
|
19
|
+
|
|
20
|
+
* **valid-expect-in-promise:** allow `expect.resolve` & `expect.reject` ([#948](https://github.com/jest-community/eslint-plugin-jest/issues/948)) ([71b7e17](https://github.com/jest-community/eslint-plugin-jest/commit/71b7e17953b4310a4f2845adc951c68cf062cdc1)), closes [#947](https://github.com/jest-community/eslint-plugin-jest/issues/947)
|
|
21
|
+
* **valid-expect-in-promise:** support `await` in arrays ([#949](https://github.com/jest-community/eslint-plugin-jest/issues/949)) ([a62130c](https://github.com/jest-community/eslint-plugin-jest/commit/a62130c28d01dea065cc6900a062180de2079876))
|
|
22
|
+
|
|
23
|
+
## [25.0.5](https://github.com/jest-community/eslint-plugin-jest/compare/v25.0.4...v25.0.5) (2021-10-11)
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
### Bug Fixes
|
|
27
|
+
|
|
28
|
+
* support `@typescript-eslint/eslint-plugin@5` ([#942](https://github.com/jest-community/eslint-plugin-jest/issues/942)) ([9b842a3](https://github.com/jest-community/eslint-plugin-jest/commit/9b842a309fb8e4263896f3e5b5150cf091d48698))
|
|
29
|
+
|
|
1
30
|
## [25.0.4](https://github.com/jest-community/eslint-plugin-jest/compare/v25.0.3...v25.0.4) (2021-10-11)
|
|
2
31
|
|
|
3
32
|
|
|
@@ -34,7 +34,8 @@ it('should work with callbacks/async', () => {
|
|
|
34
34
|
"jest/expect-expect": [
|
|
35
35
|
"error",
|
|
36
36
|
{
|
|
37
|
-
"assertFunctionNames": ["expect"]
|
|
37
|
+
"assertFunctionNames": ["expect"],
|
|
38
|
+
"additionalTestBlockFunctions": []
|
|
38
39
|
}
|
|
39
40
|
]
|
|
40
41
|
}
|
|
@@ -102,3 +103,43 @@ describe('GET /user', function () {
|
|
|
102
103
|
});
|
|
103
104
|
});
|
|
104
105
|
```
|
|
106
|
+
|
|
107
|
+
### `additionalTestBlockFunctions`
|
|
108
|
+
|
|
109
|
+
This array can be used to specify the names of functions that should also be
|
|
110
|
+
treated as test blocks:
|
|
111
|
+
|
|
112
|
+
```json
|
|
113
|
+
{
|
|
114
|
+
"rules": {
|
|
115
|
+
"jest/expect-expect": [
|
|
116
|
+
"error",
|
|
117
|
+
{ "additionalTestBlockFunctions": ["theoretically"] }
|
|
118
|
+
]
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
The following is _correct_ when using the above configuration:
|
|
124
|
+
|
|
125
|
+
```js
|
|
126
|
+
import theoretically from 'jest-theories';
|
|
127
|
+
|
|
128
|
+
describe('NumberToLongString', () => {
|
|
129
|
+
const theories = [
|
|
130
|
+
{ input: 100, expected: 'One hundred' },
|
|
131
|
+
{ input: 1000, expected: 'One thousand' },
|
|
132
|
+
{ input: 10000, expected: 'Ten thousand' },
|
|
133
|
+
{ input: 100000, expected: 'One hundred thousand' },
|
|
134
|
+
];
|
|
135
|
+
|
|
136
|
+
theoretically(
|
|
137
|
+
'the number {input} is correctly translated to string',
|
|
138
|
+
theories,
|
|
139
|
+
theory => {
|
|
140
|
+
const output = NumberToLongString(theory.input);
|
|
141
|
+
expect(output).toBe(theory.expected);
|
|
142
|
+
},
|
|
143
|
+
);
|
|
144
|
+
});
|
|
145
|
+
```
|
|
@@ -26,7 +26,7 @@ it('adds 1 + 2 to equal 3', () => {
|
|
|
26
26
|
|
|
27
27
|
```json
|
|
28
28
|
{
|
|
29
|
-
"jest/lowercase-name": [
|
|
29
|
+
"jest/prefer-lowercase-name": [
|
|
30
30
|
"error",
|
|
31
31
|
{
|
|
32
32
|
"ignore": ["describe", "test"]
|
|
@@ -50,7 +50,7 @@ By default, none of these options are enabled (the equivalent of
|
|
|
50
50
|
Example of **correct** code for the `{ "ignore": ["describe"] }` option:
|
|
51
51
|
|
|
52
52
|
```js
|
|
53
|
-
/* eslint jest/lowercase-name: ["error", { "ignore": ["describe"] }] */
|
|
53
|
+
/* eslint jest/prefer-lowercase-name: ["error", { "ignore": ["describe"] }] */
|
|
54
54
|
|
|
55
55
|
describe('Uppercase description');
|
|
56
56
|
```
|
|
@@ -58,7 +58,7 @@ describe('Uppercase description');
|
|
|
58
58
|
Example of **correct** code for the `{ "ignore": ["test"] }` option:
|
|
59
59
|
|
|
60
60
|
```js
|
|
61
|
-
/* eslint jest/lowercase-name: ["error", { "ignore": ["test"] }] */
|
|
61
|
+
/* eslint jest/prefer-lowercase-name: ["error", { "ignore": ["test"] }] */
|
|
62
62
|
|
|
63
63
|
test('Uppercase description');
|
|
64
64
|
```
|
|
@@ -66,7 +66,7 @@ test('Uppercase description');
|
|
|
66
66
|
Example of **correct** code for the `{ "ignore": ["it"] }` option:
|
|
67
67
|
|
|
68
68
|
```js
|
|
69
|
-
/* eslint jest/lowercase-name: ["error", { "ignore": ["it"] }] */
|
|
69
|
+
/* eslint jest/prefer-lowercase-name: ["error", { "ignore": ["it"] }] */
|
|
70
70
|
|
|
71
71
|
it('Uppercase description');
|
|
72
72
|
```
|
|
@@ -82,7 +82,7 @@ By default, nothing is allowed (the equivalent of `{ "allowedPrefixes": [] }`).
|
|
|
82
82
|
Example of **correct** code for the `{ "allowedPrefixes": ["GET"] }` option:
|
|
83
83
|
|
|
84
84
|
```js
|
|
85
|
-
/* eslint jest/lowercase-name: ["error", { "allowedPrefixes": ["GET"] }] */
|
|
85
|
+
/* eslint jest/prefer-lowercase-name: ["error", { "allowedPrefixes": ["GET"] }] */
|
|
86
86
|
|
|
87
87
|
describe('GET /live');
|
|
88
88
|
```
|
|
@@ -95,7 +95,7 @@ title starting with an upper-case letter.
|
|
|
95
95
|
Example of **correct** code for the `{ "ignoreTopLevelDescribe": true }` option:
|
|
96
96
|
|
|
97
97
|
```js
|
|
98
|
-
/* eslint jest/lowercase-name: ["error", { "ignoreTopLevelDescribe": true }] */
|
|
98
|
+
/* eslint jest/prefer-lowercase-name: ["error", { "ignoreTopLevelDescribe": true }] */
|
|
99
99
|
describe('MyClass', () => {
|
|
100
100
|
describe('#myMethod', () => {
|
|
101
101
|
it('does things', () => {
|
|
@@ -47,6 +47,12 @@ var _default = (0, _utils.createRule)({
|
|
|
47
47
|
items: [{
|
|
48
48
|
type: 'string'
|
|
49
49
|
}]
|
|
50
|
+
},
|
|
51
|
+
additionalTestBlockFunctions: {
|
|
52
|
+
type: 'array',
|
|
53
|
+
items: {
|
|
54
|
+
type: 'string'
|
|
55
|
+
}
|
|
50
56
|
}
|
|
51
57
|
},
|
|
52
58
|
additionalProperties: false
|
|
@@ -54,11 +60,13 @@ var _default = (0, _utils.createRule)({
|
|
|
54
60
|
type: 'suggestion'
|
|
55
61
|
},
|
|
56
62
|
defaultOptions: [{
|
|
57
|
-
assertFunctionNames: ['expect']
|
|
63
|
+
assertFunctionNames: ['expect'],
|
|
64
|
+
additionalTestBlockFunctions: []
|
|
58
65
|
}],
|
|
59
66
|
|
|
60
67
|
create(context, [{
|
|
61
|
-
assertFunctionNames = ['expect']
|
|
68
|
+
assertFunctionNames = ['expect'],
|
|
69
|
+
additionalTestBlockFunctions = []
|
|
62
70
|
}]) {
|
|
63
71
|
const unchecked = [];
|
|
64
72
|
|
|
@@ -81,11 +89,13 @@ var _default = (0, _utils.createRule)({
|
|
|
81
89
|
|
|
82
90
|
return {
|
|
83
91
|
CallExpression(node) {
|
|
84
|
-
|
|
92
|
+
var _getNodeName;
|
|
93
|
+
|
|
94
|
+
const name = (_getNodeName = (0, _utils.getNodeName)(node.callee)) !== null && _getNodeName !== void 0 ? _getNodeName : '';
|
|
85
95
|
|
|
86
|
-
if (
|
|
96
|
+
if ((0, _utils.isTestCaseCall)(node) || additionalTestBlockFunctions.includes(name)) {
|
|
87
97
|
unchecked.push(node);
|
|
88
|
-
} else if (
|
|
98
|
+
} else if (matchesAssertFunctionName(name, assertFunctionNames)) {
|
|
89
99
|
// Return early in case of nested `it` statements.
|
|
90
100
|
checkCallExpressionUsed(context.getAncestors());
|
|
91
101
|
}
|
|
@@ -103,6 +103,25 @@ const isPromiseMethodThatUsesValue = (node, identifier) => {
|
|
|
103
103
|
|
|
104
104
|
return (0, _utils.isIdentifier)(node.argument, name);
|
|
105
105
|
};
|
|
106
|
+
/**
|
|
107
|
+
* Attempts to determine if the runtime value represented by the given `identifier`
|
|
108
|
+
* is `await`ed within the given array of elements
|
|
109
|
+
*/
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
const isValueAwaitedInElements = (name, elements) => {
|
|
113
|
+
for (const element of elements) {
|
|
114
|
+
if (element.type === _experimentalUtils.AST_NODE_TYPES.AwaitExpression && (0, _utils.isIdentifier)(element.argument, name)) {
|
|
115
|
+
return true;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
if (element.type === _experimentalUtils.AST_NODE_TYPES.ArrayExpression && isValueAwaitedInElements(name, element.elements)) {
|
|
119
|
+
return true;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
return false;
|
|
124
|
+
};
|
|
106
125
|
/**
|
|
107
126
|
* Attempts to determine if the runtime value represented by the given `identifier`
|
|
108
127
|
* is `await`ed as an argument along the given call expression
|
|
@@ -114,10 +133,8 @@ const isValueAwaitedInArguments = (name, call) => {
|
|
|
114
133
|
|
|
115
134
|
while (node) {
|
|
116
135
|
if (node.type === _experimentalUtils.AST_NODE_TYPES.CallExpression) {
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
return true;
|
|
120
|
-
}
|
|
136
|
+
if (isValueAwaitedInElements(name, node.arguments)) {
|
|
137
|
+
return true;
|
|
121
138
|
}
|
|
122
139
|
|
|
123
140
|
node = node.callee;
|
|
@@ -132,6 +149,26 @@ const isValueAwaitedInArguments = (name, call) => {
|
|
|
132
149
|
|
|
133
150
|
return false;
|
|
134
151
|
};
|
|
152
|
+
|
|
153
|
+
const getLeftMostCallExpression = call => {
|
|
154
|
+
let leftMostCallExpression = call;
|
|
155
|
+
let node = call;
|
|
156
|
+
|
|
157
|
+
while (node) {
|
|
158
|
+
if (node.type === _experimentalUtils.AST_NODE_TYPES.CallExpression) {
|
|
159
|
+
leftMostCallExpression = node;
|
|
160
|
+
node = node.callee;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
if (node.type !== _experimentalUtils.AST_NODE_TYPES.MemberExpression) {
|
|
164
|
+
break;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
node = node.object;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
return leftMostCallExpression;
|
|
171
|
+
};
|
|
135
172
|
/**
|
|
136
173
|
* Attempts to determine if the runtime value represented by the given `identifier`
|
|
137
174
|
* is `await`ed or `return`ed within the given `body` of statements
|
|
@@ -156,8 +193,22 @@ const isValueAwaitedOrReturned = (identifier, body) => {
|
|
|
156
193
|
|
|
157
194
|
if (node.type === _experimentalUtils.AST_NODE_TYPES.ExpressionStatement) {
|
|
158
195
|
// it's possible that we're awaiting the value as an argument
|
|
159
|
-
if (node.expression.type === _experimentalUtils.AST_NODE_TYPES.CallExpression
|
|
160
|
-
|
|
196
|
+
if (node.expression.type === _experimentalUtils.AST_NODE_TYPES.CallExpression) {
|
|
197
|
+
if (isValueAwaitedInArguments(name, node.expression)) {
|
|
198
|
+
return true;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
const leftMostCall = getLeftMostCallExpression(node.expression);
|
|
202
|
+
|
|
203
|
+
if ((0, _utils.isExpectCall)(leftMostCall) && leftMostCall.arguments.length > 0 && (0, _utils.isIdentifier)(leftMostCall.arguments[0], name)) {
|
|
204
|
+
const {
|
|
205
|
+
modifier
|
|
206
|
+
} = (0, _utils.parseExpectCall)(leftMostCall);
|
|
207
|
+
|
|
208
|
+
if ((modifier === null || modifier === void 0 ? void 0 : modifier.name) === _utils.ModifierName.resolves || (modifier === null || modifier === void 0 ? void 0 : modifier.name) === _utils.ModifierName.rejects) {
|
|
209
|
+
return true;
|
|
210
|
+
}
|
|
211
|
+
}
|
|
161
212
|
}
|
|
162
213
|
|
|
163
214
|
if (node.expression.type === _experimentalUtils.AST_NODE_TYPES.AwaitExpression && isPromiseMethodThatUsesValue(node.expression, identifier)) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eslint-plugin-jest",
|
|
3
|
-
"version": "25.0
|
|
3
|
+
"version": "25.2.0",
|
|
4
4
|
"description": "Eslint rules for Jest",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"eslint",
|
|
@@ -60,10 +60,13 @@
|
|
|
60
60
|
"projects": [
|
|
61
61
|
{
|
|
62
62
|
"displayName": "test",
|
|
63
|
-
"
|
|
63
|
+
"moduleNameMapper": {
|
|
64
|
+
"eslint/use-at-your-own-risk": "eslint/lib/unsupported-api.js"
|
|
65
|
+
},
|
|
64
66
|
"testPathIgnorePatterns": [
|
|
65
67
|
"<rootDir>/lib/.*",
|
|
66
|
-
"<rootDir>/src/rules/__tests__/fixtures/*"
|
|
68
|
+
"<rootDir>/src/rules/__tests__/fixtures/*",
|
|
69
|
+
"<rootDir>/src/rules/__tests__/test-utils.ts"
|
|
67
70
|
]
|
|
68
71
|
},
|
|
69
72
|
{
|
|
@@ -95,27 +98,26 @@
|
|
|
95
98
|
"@types/jest": "^27.0.0",
|
|
96
99
|
"@types/node": "^14.0.0",
|
|
97
100
|
"@types/prettier": "^2.0.0",
|
|
98
|
-
"@typescript-eslint/eslint-plugin": "^
|
|
99
|
-
"@typescript-eslint/parser": "^
|
|
101
|
+
"@typescript-eslint/eslint-plugin": "^5.0.0",
|
|
102
|
+
"@typescript-eslint/parser": "^5.0.0",
|
|
100
103
|
"babel-jest": "^27.0.0",
|
|
101
104
|
"babel-plugin-replace-ts-export-assignment": "^0.0.2",
|
|
102
105
|
"dedent": "^0.7.0",
|
|
103
|
-
"eslint": "^6.0.0 || ^7.0.0",
|
|
106
|
+
"eslint": "^6.0.0 || ^7.0.0 || ^8.0.0",
|
|
104
107
|
"eslint-config-prettier": "^8.3.0",
|
|
105
108
|
"eslint-plugin-eslint-comments": "^3.1.2",
|
|
106
109
|
"eslint-plugin-eslint-config": "^2.0.0",
|
|
107
110
|
"eslint-plugin-eslint-plugin": "^3.5.3",
|
|
108
|
-
"eslint-plugin-import": "^2.
|
|
111
|
+
"eslint-plugin-import": "^2.25.1",
|
|
109
112
|
"eslint-plugin-node": "^11.0.0",
|
|
110
113
|
"eslint-plugin-prettier": "^3.4.1",
|
|
111
114
|
"husky": "^7.0.2",
|
|
112
115
|
"is-ci": "^3.0.0",
|
|
113
116
|
"jest": "^27.0.0",
|
|
114
|
-
"jest-runner-eslint": "^0.
|
|
117
|
+
"jest-runner-eslint": "^1.0.0",
|
|
115
118
|
"lint-staged": "^11.1.2",
|
|
116
119
|
"pinst": "^2.0.0",
|
|
117
120
|
"prettier": "^2.0.5",
|
|
118
|
-
"resolve-from": "^5.0.0",
|
|
119
121
|
"rimraf": "^3.0.0",
|
|
120
122
|
"semantic-release": "^18.0.0",
|
|
121
123
|
"semver": "^7.3.5",
|
|
@@ -123,8 +125,8 @@
|
|
|
123
125
|
"typescript": "^4.4.0"
|
|
124
126
|
},
|
|
125
127
|
"peerDependencies": {
|
|
126
|
-
"@typescript-eslint/eslint-plugin": "^4.0.0",
|
|
127
|
-
"eslint": "^6.0.0 || ^7.0.0"
|
|
128
|
+
"@typescript-eslint/eslint-plugin": "^4.0.0 || ^5.0.0",
|
|
129
|
+
"eslint": "^6.0.0 || ^7.0.0 || ^8.0.0"
|
|
128
130
|
},
|
|
129
131
|
"peerDependenciesMeta": {
|
|
130
132
|
"@typescript-eslint/eslint-plugin": {
|
|
@@ -150,5 +152,8 @@
|
|
|
150
152
|
"@semantic-release/git",
|
|
151
153
|
"@semantic-release/github"
|
|
152
154
|
]
|
|
155
|
+
},
|
|
156
|
+
"resolutions": {
|
|
157
|
+
"@typescript-eslint/experimental-utils": "^5.0.0"
|
|
153
158
|
}
|
|
154
159
|
}
|