eslint-plugin-jest 25.0.2 → 25.0.6
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/lib/rules/valid-expect-in-promise.js +85 -0
- package/package.json +9 -10
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,32 @@
|
|
|
1
|
+
## [25.0.6](https://github.com/jest-community/eslint-plugin-jest/compare/v25.0.5...v25.0.6) (2021-10-14)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* **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)
|
|
7
|
+
* **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))
|
|
8
|
+
|
|
9
|
+
## [25.0.5](https://github.com/jest-community/eslint-plugin-jest/compare/v25.0.4...v25.0.5) (2021-10-11)
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
### Bug Fixes
|
|
13
|
+
|
|
14
|
+
* 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))
|
|
15
|
+
|
|
16
|
+
## [25.0.4](https://github.com/jest-community/eslint-plugin-jest/compare/v25.0.3...v25.0.4) (2021-10-11)
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
### Bug Fixes
|
|
20
|
+
|
|
21
|
+
* update `@typescript-eslint/experimental-utils` to v5 ([#941](https://github.com/jest-community/eslint-plugin-jest/issues/941)) ([afad49a](https://github.com/jest-community/eslint-plugin-jest/commit/afad49a885eeb1ac52f00d8e1666259210a4b675))
|
|
22
|
+
|
|
23
|
+
## [25.0.3](https://github.com/jest-community/eslint-plugin-jest/compare/v25.0.2...v25.0.3) (2021-10-11)
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
### Bug Fixes
|
|
27
|
+
|
|
28
|
+
* **valid-expect-in-promise:** support awaited promises in arguments ([#936](https://github.com/jest-community/eslint-plugin-jest/issues/936)) ([bd2c33c](https://github.com/jest-community/eslint-plugin-jest/commit/bd2c33c858573d5414d8bc0d401eb6f27801ad2b))
|
|
29
|
+
|
|
1
30
|
## [25.0.2](https://github.com/jest-community/eslint-plugin-jest/compare/v25.0.1...v25.0.2) (2021-10-11)
|
|
2
31
|
|
|
3
32
|
|
|
@@ -103,6 +103,72 @@ 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
|
+
};
|
|
125
|
+
/**
|
|
126
|
+
* Attempts to determine if the runtime value represented by the given `identifier`
|
|
127
|
+
* is `await`ed as an argument along the given call expression
|
|
128
|
+
*/
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
const isValueAwaitedInArguments = (name, call) => {
|
|
132
|
+
let node = call;
|
|
133
|
+
|
|
134
|
+
while (node) {
|
|
135
|
+
if (node.type === _experimentalUtils.AST_NODE_TYPES.CallExpression) {
|
|
136
|
+
if (isValueAwaitedInElements(name, node.arguments)) {
|
|
137
|
+
return true;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
node = node.callee;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
if (node.type !== _experimentalUtils.AST_NODE_TYPES.MemberExpression) {
|
|
144
|
+
break;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
node = node.object;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
return false;
|
|
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
|
+
};
|
|
106
172
|
/**
|
|
107
173
|
* Attempts to determine if the runtime value represented by the given `identifier`
|
|
108
174
|
* is `await`ed or `return`ed within the given `body` of statements
|
|
@@ -126,6 +192,25 @@ const isValueAwaitedOrReturned = (identifier, body) => {
|
|
|
126
192
|
}
|
|
127
193
|
|
|
128
194
|
if (node.type === _experimentalUtils.AST_NODE_TYPES.ExpressionStatement) {
|
|
195
|
+
// it's possible that we're awaiting the value as an argument
|
|
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
|
+
}
|
|
212
|
+
}
|
|
213
|
+
|
|
129
214
|
if (node.expression.type === _experimentalUtils.AST_NODE_TYPES.AwaitExpression && isPromiseMethodThatUsesValue(node.expression, identifier)) {
|
|
130
215
|
return true;
|
|
131
216
|
} // (re)assignment changes the runtime value, so if we've not found an
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eslint-plugin-jest",
|
|
3
|
-
"version": "25.0.
|
|
3
|
+
"version": "25.0.6",
|
|
4
4
|
"description": "Eslint rules for Jest",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"eslint",
|
|
@@ -60,10 +60,10 @@
|
|
|
60
60
|
"projects": [
|
|
61
61
|
{
|
|
62
62
|
"displayName": "test",
|
|
63
|
-
"testEnvironment": "node",
|
|
64
63
|
"testPathIgnorePatterns": [
|
|
65
64
|
"<rootDir>/lib/.*",
|
|
66
|
-
"<rootDir>/src/rules/__tests__/fixtures/*"
|
|
65
|
+
"<rootDir>/src/rules/__tests__/fixtures/*",
|
|
66
|
+
"<rootDir>/src/rules/__tests__/test-utils.ts"
|
|
67
67
|
]
|
|
68
68
|
},
|
|
69
69
|
{
|
|
@@ -79,7 +79,7 @@
|
|
|
79
79
|
]
|
|
80
80
|
},
|
|
81
81
|
"dependencies": {
|
|
82
|
-
"@typescript-eslint/experimental-utils": "^
|
|
82
|
+
"@typescript-eslint/experimental-utils": "^5.0.0"
|
|
83
83
|
},
|
|
84
84
|
"devDependencies": {
|
|
85
85
|
"@babel/cli": "^7.4.4",
|
|
@@ -95,8 +95,8 @@
|
|
|
95
95
|
"@types/jest": "^27.0.0",
|
|
96
96
|
"@types/node": "^14.0.0",
|
|
97
97
|
"@types/prettier": "^2.0.0",
|
|
98
|
-
"@typescript-eslint/eslint-plugin": "^
|
|
99
|
-
"@typescript-eslint/parser": "^
|
|
98
|
+
"@typescript-eslint/eslint-plugin": "^5.0.0",
|
|
99
|
+
"@typescript-eslint/parser": "^5.0.0",
|
|
100
100
|
"babel-jest": "^27.0.0",
|
|
101
101
|
"babel-plugin-replace-ts-export-assignment": "^0.0.2",
|
|
102
102
|
"dedent": "^0.7.0",
|
|
@@ -105,17 +105,16 @@
|
|
|
105
105
|
"eslint-plugin-eslint-comments": "^3.1.2",
|
|
106
106
|
"eslint-plugin-eslint-config": "^2.0.0",
|
|
107
107
|
"eslint-plugin-eslint-plugin": "^3.5.3",
|
|
108
|
-
"eslint-plugin-import": "^2.
|
|
108
|
+
"eslint-plugin-import": "^2.25.1",
|
|
109
109
|
"eslint-plugin-node": "^11.0.0",
|
|
110
110
|
"eslint-plugin-prettier": "^3.4.1",
|
|
111
111
|
"husky": "^7.0.2",
|
|
112
112
|
"is-ci": "^3.0.0",
|
|
113
113
|
"jest": "^27.0.0",
|
|
114
|
-
"jest-runner-eslint": "^0.
|
|
114
|
+
"jest-runner-eslint": "^1.0.0",
|
|
115
115
|
"lint-staged": "^11.1.2",
|
|
116
116
|
"pinst": "^2.0.0",
|
|
117
117
|
"prettier": "^2.0.5",
|
|
118
|
-
"resolve-from": "^5.0.0",
|
|
119
118
|
"rimraf": "^3.0.0",
|
|
120
119
|
"semantic-release": "^18.0.0",
|
|
121
120
|
"semver": "^7.3.5",
|
|
@@ -123,7 +122,7 @@
|
|
|
123
122
|
"typescript": "^4.4.0"
|
|
124
123
|
},
|
|
125
124
|
"peerDependencies": {
|
|
126
|
-
"@typescript-eslint/eslint-plugin": "^4.0.0",
|
|
125
|
+
"@typescript-eslint/eslint-plugin": "^4.0.0 || ^5.0.0",
|
|
127
126
|
"eslint": "^6.0.0 || ^7.0.0"
|
|
128
127
|
},
|
|
129
128
|
"peerDependenciesMeta": {
|