eslint-plugin-jest 26.1.1 → 26.5.3
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 +50 -2
- package/docs/rules/no-conditional-expect.md +1 -1
- package/docs/rules/no-deprecated-functions.md +1 -2
- package/docs/rules/no-identical-title.md +1 -1
- package/docs/rules/no-jasmine-globals.md +2 -2
- package/docs/rules/no-jest-import.md +1 -1
- package/docs/rules/no-large-snapshots.md +2 -2
- package/docs/rules/no-standalone-expect.md +1 -1
- package/docs/rules/prefer-comparison-matcher.md +1 -1
- package/docs/rules/prefer-equality-matcher.md +1 -1
- package/docs/rules/prefer-expect-assertions.md +1 -1
- package/docs/rules/prefer-hooks-in-order.md +133 -0
- package/docs/rules/prefer-hooks-on-top.md +1 -1
- package/docs/rules/prefer-lowercase-title.md +2 -2
- package/docs/rules/valid-expect.md +2 -2
- package/lib/rules/consistent-test-it.js +9 -8
- package/lib/rules/expect-expect.js +4 -4
- package/lib/rules/max-nested-describe.js +2 -2
- package/lib/rules/no-alias-methods.js +1 -1
- package/lib/rules/no-conditional-expect.js +3 -3
- package/lib/rules/no-conditional-in-test.js +2 -2
- package/lib/rules/no-deprecated-functions.js +1 -3
- package/lib/rules/no-disabled-tests.js +36 -61
- package/lib/rules/no-done-callback.js +6 -4
- package/lib/rules/no-duplicate-hooks.js +23 -23
- package/lib/rules/no-export.js +1 -1
- package/lib/rules/no-focused-tests.js +40 -43
- package/lib/rules/no-hooks.js +4 -2
- package/lib/rules/no-identical-title.js +10 -7
- package/lib/rules/no-if.js +6 -4
- package/lib/rules/no-restricted-matchers.js +39 -43
- package/lib/rules/no-standalone-expect.js +5 -5
- package/lib/rules/no-test-prefixes.js +12 -20
- package/lib/rules/no-test-return-statement.js +5 -2
- package/lib/rules/prefer-called-with.js +14 -13
- package/lib/rules/prefer-comparison-matcher.js +9 -4
- package/lib/rules/prefer-equality-matcher.js +15 -5
- package/lib/rules/prefer-expect-assertions.js +4 -2
- package/lib/rules/prefer-hooks-in-order.js +84 -0
- package/lib/rules/prefer-hooks-on-top.js +2 -2
- package/lib/rules/prefer-lowercase-title.js +12 -22
- package/lib/rules/prefer-snapshot-hint.js +34 -3
- package/lib/rules/prefer-strict-equal.js +1 -1
- package/lib/rules/prefer-to-be.js +1 -1
- package/lib/rules/prefer-todo.js +22 -7
- package/lib/rules/require-hook.js +7 -7
- package/lib/rules/require-top-level-describe.js +10 -4
- package/lib/rules/utils/accessors.js +135 -0
- package/lib/rules/{detectJestVersion.js → utils/detectJestVersion.js} +0 -0
- package/lib/rules/utils/followTypeAssertionChain.js +14 -0
- package/lib/rules/utils/index.js +83 -0
- package/lib/rules/utils/misc.js +120 -0
- package/lib/rules/utils/parseExpectCall.js +145 -0
- package/lib/rules/utils/parseJestFnCall.js +323 -0
- package/lib/rules/valid-describe-callback.js +4 -2
- package/lib/rules/valid-expect-in-promise.js +13 -15
- package/lib/rules/valid-title.js +8 -6
- package/package.json +9 -12
- package/lib/rules/utils.js +0 -513
package/README.md
CHANGED
|
@@ -59,6 +59,53 @@ doing:
|
|
|
59
59
|
This is included in all configs shared by this plugin, so can be omitted if
|
|
60
60
|
extending them.
|
|
61
61
|
|
|
62
|
+
#### Aliased Jest globals
|
|
63
|
+
|
|
64
|
+
You can tell this plugin about any global Jests you have aliased using the
|
|
65
|
+
`globalAliases` setting:
|
|
66
|
+
|
|
67
|
+
```json
|
|
68
|
+
{
|
|
69
|
+
"settings": {
|
|
70
|
+
"jest": {
|
|
71
|
+
"globalAliases": {
|
|
72
|
+
"describe": ["context"],
|
|
73
|
+
"fdescribe": ["fcontext"],
|
|
74
|
+
"xdescribe": ["xcontext"]
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
### Running rules only on test-related files
|
|
82
|
+
|
|
83
|
+
The rules provided by this plugin assume that the files they are checking are
|
|
84
|
+
test-related. This means it's generally not suitable to include them in your
|
|
85
|
+
top-level configuration as that applies to all files being linted which can
|
|
86
|
+
include source files.
|
|
87
|
+
|
|
88
|
+
You can use
|
|
89
|
+
[overrides](https://eslint.org/docs/user-guide/configuring/configuration-files#how-do-overrides-work)
|
|
90
|
+
to have ESLint apply additional rules to specific files:
|
|
91
|
+
|
|
92
|
+
```json
|
|
93
|
+
{
|
|
94
|
+
"extends": ["eslint:recommended"],
|
|
95
|
+
"overrides": [
|
|
96
|
+
{
|
|
97
|
+
"files": ["test/**"],
|
|
98
|
+
"plugins": ["jest"],
|
|
99
|
+
"extends": ["plugin:jest/recommended"],
|
|
100
|
+
"rules": { "jest/prefer-expect-assertions": "off" }
|
|
101
|
+
}
|
|
102
|
+
],
|
|
103
|
+
"rules": {
|
|
104
|
+
"indent": ["error", 2]
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
```
|
|
108
|
+
|
|
62
109
|
### Jest `version` setting
|
|
63
110
|
|
|
64
111
|
The behaviour of some rules (specifically [`no-deprecated-functions`][]) change
|
|
@@ -181,6 +228,7 @@ installations requiring long-term consistency.
|
|
|
181
228
|
| [prefer-equality-matcher](docs/rules/prefer-equality-matcher.md) | Suggest using the built-in equality matchers | | ![suggest][] |
|
|
182
229
|
| [prefer-expect-assertions](docs/rules/prefer-expect-assertions.md) | Suggest using `expect.assertions()` OR `expect.hasAssertions()` | | ![suggest][] |
|
|
183
230
|
| [prefer-expect-resolves](docs/rules/prefer-expect-resolves.md) | Prefer `await expect(...).resolves` over `expect(await ...)` syntax | | ![fixable][] |
|
|
231
|
+
| [prefer-hooks-in-order](docs/rules/prefer-hooks-in-order.md) | Prefer having hooks in a consistent order | | |
|
|
184
232
|
| [prefer-hooks-on-top](docs/rules/prefer-hooks-on-top.md) | Suggest having hooks before any test cases | | |
|
|
185
233
|
| [prefer-lowercase-title](docs/rules/prefer-lowercase-title.md) | Enforce lowercase test names | | ![fixable][] |
|
|
186
234
|
| [prefer-snapshot-hint](docs/rules/prefer-snapshot-hint.md) | Prefer including a hint with external snapshots | | |
|
|
@@ -211,8 +259,8 @@ adjust your eslint config as outlined
|
|
|
211
259
|
|
|
212
260
|
Note that unlike the type-checking rules in `@typescript-eslint/eslint-plugin`,
|
|
213
261
|
the rules here will fallback to doing nothing if type information is not
|
|
214
|
-
available, meaning
|
|
215
|
-
on JavaScript and TypeScript projects.
|
|
262
|
+
available, meaning it's safe to include them in shared configs that could be
|
|
263
|
+
used on JavaScript and TypeScript projects.
|
|
216
264
|
|
|
217
265
|
Also note that `unbound-method` depends on `@typescript-eslint/eslint-plugin`,
|
|
218
266
|
as it extends the original `unbound-method` rule from that plugin.
|
|
@@ -107,7 +107,7 @@ While you can use `expect.assertions` & `expect.hasAssertions` for these
|
|
|
107
107
|
situations, they only work with `expect`.
|
|
108
108
|
|
|
109
109
|
A better way to handle this situation is to introduce a wrapper to handle the
|
|
110
|
-
catching, and otherwise
|
|
110
|
+
catching, and otherwise return a specific "no error thrown" error if nothing is
|
|
111
111
|
thrown by the wrapped function:
|
|
112
112
|
|
|
113
113
|
```typescript
|
|
@@ -37,8 +37,7 @@ Originally, the `requireActual` & `requireMock` the `requireActual`&
|
|
|
37
37
|
|
|
38
38
|
These functions were later moved onto the `jest` object in order to be easier
|
|
39
39
|
for type checkers to handle, and their use via `require` deprecated. Finally,
|
|
40
|
-
the release of Jest 26 saw them removed from the `require` function
|
|
41
|
-
together.
|
|
40
|
+
the release of Jest 26 saw them removed from the `require` function altogether.
|
|
42
41
|
|
|
43
42
|
### `jest.runTimersToTime`
|
|
44
43
|
|
|
@@ -7,7 +7,7 @@ fix.
|
|
|
7
7
|
|
|
8
8
|
## Rule Details
|
|
9
9
|
|
|
10
|
-
This rule looks at the title of every test and test
|
|
10
|
+
This rule looks at the title of every test and test suite. It will report when
|
|
11
11
|
two test suites or two test cases at the same level of a test suite have the
|
|
12
12
|
same title.
|
|
13
13
|
|
|
@@ -9,8 +9,8 @@ API.
|
|
|
9
9
|
|
|
10
10
|
### Rule details
|
|
11
11
|
|
|
12
|
-
This rule reports on any usage of Jasmine globals which is not ported to Jest,
|
|
13
|
-
and suggests
|
|
12
|
+
This rule reports on any usage of Jasmine globals, which is not ported to Jest,
|
|
13
|
+
and suggests alternatives from Jest's own API.
|
|
14
14
|
|
|
15
15
|
### Default configuration
|
|
16
16
|
|
|
@@ -118,8 +118,8 @@ External). Use `inlineMaxSize` for
|
|
|
118
118
|
[Inline Snapshots](https://jestjs.io/docs/en/snapshot-testing#inline-snapshots)
|
|
119
119
|
size and `maxSize` for
|
|
120
120
|
[External Snapshots](https://jestjs.io/docs/en/snapshot-testing#snapshot-testing-with-jest).
|
|
121
|
-
If only `maxSize` is provided on options, the value of `maxSize` will be used
|
|
122
|
-
both snapshot types (Inline and External).
|
|
121
|
+
If only `maxSize` is provided on options, the value of `maxSize` will be used
|
|
122
|
+
for both snapshot types (Inline and External).
|
|
123
123
|
|
|
124
124
|
Since `eslint-disable` comments are not preserved by Jest when updating
|
|
125
125
|
snapshots, you can use the `allowedSnapshots` option to have specific snapshots
|
|
@@ -61,7 +61,7 @@ describe('a test', () => {
|
|
|
61
61
|
```
|
|
62
62
|
|
|
63
63
|
\*Note that this rule will not trigger if the helper function is never used even
|
|
64
|
-
|
|
64
|
+
though the `expect` will not execute. Rely on a rule like no-unused-vars for
|
|
65
65
|
this case.
|
|
66
66
|
|
|
67
67
|
### Options
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Suggest using the built-in comparison matchers (`prefer-comparison-matcher`)
|
|
2
2
|
|
|
3
|
-
Jest has a number of built-in matchers for comparing numbers which allow for
|
|
3
|
+
Jest has a number of built-in matchers for comparing numbers, which allow for
|
|
4
4
|
more readable tests and error messages if an expectation fails.
|
|
5
5
|
|
|
6
6
|
## Rule details
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Suggest using the built-in equality matchers (`prefer-equality-matcher`)
|
|
2
2
|
|
|
3
|
-
Jest has built-in matchers for expecting equality which allow for more readable
|
|
3
|
+
Jest has built-in matchers for expecting equality, which allow for more readable
|
|
4
4
|
tests and error messages if an expectation fails.
|
|
5
5
|
|
|
6
6
|
## Rule details
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
# Prefer having hooks in a consistent order (`prefer-hooks-in-order`)
|
|
2
|
+
|
|
3
|
+
While hooks can be setup in any order, they're always called by `jest` in this
|
|
4
|
+
specific order:
|
|
5
|
+
|
|
6
|
+
1. `beforeAll`
|
|
7
|
+
1. `beforeEach`
|
|
8
|
+
1. `afterEach`
|
|
9
|
+
1. `afterAll`
|
|
10
|
+
|
|
11
|
+
This rule aims to make that more obvious by enforcing grouped hooks be setup in
|
|
12
|
+
that order within tests.
|
|
13
|
+
|
|
14
|
+
## Rule Details
|
|
15
|
+
|
|
16
|
+
Examples of **incorrect** code for this rule
|
|
17
|
+
|
|
18
|
+
```js
|
|
19
|
+
/* eslint jest/prefer-hooks-in-order: "error" */
|
|
20
|
+
|
|
21
|
+
describe('foo', () => {
|
|
22
|
+
beforeEach(() => {
|
|
23
|
+
seedMyDatabase();
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
beforeAll(() => {
|
|
27
|
+
createMyDatabase();
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
it('accepts this input', () => {
|
|
31
|
+
// ...
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
it('returns that value', () => {
|
|
35
|
+
// ...
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
describe('when the database has specific values', () => {
|
|
39
|
+
const specificValue = '...';
|
|
40
|
+
|
|
41
|
+
beforeEach(() => {
|
|
42
|
+
seedMyDatabase(specificValue);
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
it('accepts that input', () => {
|
|
46
|
+
// ...
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
it('throws an error', () => {
|
|
50
|
+
// ...
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
afterEach(() => {
|
|
54
|
+
clearLogger();
|
|
55
|
+
});
|
|
56
|
+
beforeEach(() => {
|
|
57
|
+
mockLogger();
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
it('logs a message', () => {
|
|
61
|
+
// ...
|
|
62
|
+
});
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
afterAll(() => {
|
|
66
|
+
removeMyDatabase();
|
|
67
|
+
});
|
|
68
|
+
});
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
Examples of **correct** code for this rule
|
|
72
|
+
|
|
73
|
+
```js
|
|
74
|
+
/* eslint jest/prefer-hooks-in-order: "error" */
|
|
75
|
+
|
|
76
|
+
describe('foo', () => {
|
|
77
|
+
beforeAll(() => {
|
|
78
|
+
createMyDatabase();
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
beforeEach(() => {
|
|
82
|
+
seedMyDatabase();
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
it('accepts this input', () => {
|
|
86
|
+
// ...
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
it('returns that value', () => {
|
|
90
|
+
// ...
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
describe('when the database has specific values', () => {
|
|
94
|
+
const specificValue = '...';
|
|
95
|
+
|
|
96
|
+
beforeEach(() => {
|
|
97
|
+
seedMyDatabase(specificValue);
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
it('accepts that input', () => {
|
|
101
|
+
// ...
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
it('throws an error', () => {
|
|
105
|
+
// ...
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
beforeEach(() => {
|
|
109
|
+
mockLogger();
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
afterEach(() => {
|
|
113
|
+
clearLogger();
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
it('logs a message', () => {
|
|
117
|
+
// ...
|
|
118
|
+
});
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
afterAll(() => {
|
|
122
|
+
removeMyDatabase();
|
|
123
|
+
});
|
|
124
|
+
});
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
## Also See
|
|
128
|
+
|
|
129
|
+
- [`prefer-hooks-on-top`](prefer-hooks-on-top.md)
|
|
130
|
+
|
|
131
|
+
## Further Reading
|
|
132
|
+
|
|
133
|
+
- [Order of execution of describe and test blocks](https://jestjs.io/docs/setup-teardown#order-of-execution-of-describe-and-test-blocks)
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# Suggest having hooks before any test cases (`prefer-hooks-on-top`)
|
|
2
2
|
|
|
3
3
|
While hooks can be setup anywhere in a test file, they are always called in a
|
|
4
|
-
specific order which means it can be confusing if they're intermixed with test
|
|
4
|
+
specific order, which means it can be confusing if they're intermixed with test
|
|
5
5
|
cases.
|
|
6
6
|
|
|
7
7
|
This rule helps to ensure that hooks are always defined before test cases.
|
|
@@ -73,8 +73,8 @@ it('Uppercase description');
|
|
|
73
73
|
|
|
74
74
|
### `allowedPrefixes`
|
|
75
75
|
|
|
76
|
-
This array option allows specifying prefixes which contain capitals that titles
|
|
77
|
-
can start with. This can be useful when writing tests for
|
|
76
|
+
This array option allows specifying prefixes, which contain capitals that titles
|
|
77
|
+
can start with. This can be useful when writing tests for API endpoints, where
|
|
78
78
|
you'd like to prefix with the HTTP method.
|
|
79
79
|
|
|
80
80
|
By default, nothing is allowed (the equivalent of `{ "allowedPrefixes": [] }`).
|
|
@@ -136,9 +136,9 @@ test('all the things', async () => {
|
|
|
136
136
|
await Promise.resolve(
|
|
137
137
|
expect(Promise.resolve('hello')).resolves.toEqual('hello'),
|
|
138
138
|
);
|
|
139
|
-
await Promise.all(
|
|
139
|
+
await Promise.all([
|
|
140
140
|
expect(Promise.resolve('hello')).resolves.toEqual('hello'),
|
|
141
141
|
expect(Promise.resolve('hi')).resolves.toEqual('hi'),
|
|
142
|
-
);
|
|
142
|
+
]);
|
|
143
143
|
});
|
|
144
144
|
```
|
|
@@ -50,19 +50,20 @@ var _default = (0, _utils2.createRule)({
|
|
|
50
50
|
let describeNestingLevel = 0;
|
|
51
51
|
return {
|
|
52
52
|
CallExpression(node) {
|
|
53
|
-
const
|
|
53
|
+
const jestFnCall = (0, _utils2.parseJestFnCall)(node, context);
|
|
54
54
|
|
|
55
|
-
if (!
|
|
55
|
+
if (!jestFnCall) {
|
|
56
56
|
return;
|
|
57
57
|
}
|
|
58
58
|
|
|
59
|
-
if (
|
|
59
|
+
if (jestFnCall.type === 'describe') {
|
|
60
60
|
describeNestingLevel++;
|
|
61
|
+
return;
|
|
61
62
|
}
|
|
62
63
|
|
|
63
64
|
const funcNode = node.callee.type === _utils.AST_NODE_TYPES.TaggedTemplateExpression ? node.callee.tag : node.callee.type === _utils.AST_NODE_TYPES.CallExpression ? node.callee.callee : node.callee;
|
|
64
65
|
|
|
65
|
-
if (
|
|
66
|
+
if (jestFnCall.type === 'test' && describeNestingLevel === 0 && !jestFnCall.name.endsWith(testKeyword)) {
|
|
66
67
|
const oppositeTestKeyword = getOppositeTestKeyword(testKeyword);
|
|
67
68
|
context.report({
|
|
68
69
|
messageId: 'consistentMethod',
|
|
@@ -71,11 +72,11 @@ var _default = (0, _utils2.createRule)({
|
|
|
71
72
|
testKeyword,
|
|
72
73
|
oppositeTestKeyword
|
|
73
74
|
},
|
|
74
|
-
fix: buildFixer(funcNode,
|
|
75
|
+
fix: buildFixer(funcNode, jestFnCall.name, testKeyword)
|
|
75
76
|
});
|
|
76
77
|
}
|
|
77
78
|
|
|
78
|
-
if (
|
|
79
|
+
if (jestFnCall.type === 'test' && describeNestingLevel > 0 && !jestFnCall.name.endsWith(testKeywordWithinDescribe)) {
|
|
79
80
|
const oppositeTestKeyword = getOppositeTestKeyword(testKeywordWithinDescribe);
|
|
80
81
|
context.report({
|
|
81
82
|
messageId: 'consistentMethodWithinDescribe',
|
|
@@ -84,13 +85,13 @@ var _default = (0, _utils2.createRule)({
|
|
|
84
85
|
testKeywordWithinDescribe,
|
|
85
86
|
oppositeTestKeyword
|
|
86
87
|
},
|
|
87
|
-
fix: buildFixer(funcNode,
|
|
88
|
+
fix: buildFixer(funcNode, jestFnCall.name, testKeywordWithinDescribe)
|
|
88
89
|
});
|
|
89
90
|
}
|
|
90
91
|
},
|
|
91
92
|
|
|
92
93
|
'CallExpression:exit'(node) {
|
|
93
|
-
if ((0, _utils2.
|
|
94
|
+
if ((0, _utils2.isTypeOfJestFnCall)(node, context, ['describe'])) {
|
|
94
95
|
describeNestingLevel--;
|
|
95
96
|
}
|
|
96
97
|
}
|
|
@@ -23,8 +23,8 @@ var _utils2 = require("./utils");
|
|
|
23
23
|
*/
|
|
24
24
|
function matchesAssertFunctionName(nodeName, patterns) {
|
|
25
25
|
return patterns.some(p => new RegExp(`^${p.split('.').map(x => {
|
|
26
|
-
if (x === '**') return '[a-z\\.]*';
|
|
27
|
-
return x.replace(/\*/gu, '[a-z]*');
|
|
26
|
+
if (x === '**') return '[a-z\\d\\.]*';
|
|
27
|
+
return x.replace(/\*/gu, '[a-z\\d]*');
|
|
28
28
|
}).join('\\.')}(\\.|$)`, 'ui').test(nodeName));
|
|
29
29
|
}
|
|
30
30
|
|
|
@@ -76,7 +76,7 @@ var _default = (0, _utils2.createRule)({
|
|
|
76
76
|
|
|
77
77
|
if (node.type === _utils.AST_NODE_TYPES.FunctionDeclaration) {
|
|
78
78
|
const declaredVariables = context.getDeclaredVariables(node);
|
|
79
|
-
const testCallExpressions = (0, _utils2.getTestCallExpressionsFromDeclaredVariables)(declaredVariables);
|
|
79
|
+
const testCallExpressions = (0, _utils2.getTestCallExpressionsFromDeclaredVariables)(declaredVariables, context);
|
|
80
80
|
checkCallExpressionUsed(testCallExpressions);
|
|
81
81
|
}
|
|
82
82
|
|
|
@@ -93,7 +93,7 @@ var _default = (0, _utils2.createRule)({
|
|
|
93
93
|
|
|
94
94
|
const name = (_getNodeName = (0, _utils2.getNodeName)(node.callee)) !== null && _getNodeName !== void 0 ? _getNodeName : '';
|
|
95
95
|
|
|
96
|
-
if ((0, _utils2.
|
|
96
|
+
if ((0, _utils2.isTypeOfJestFnCall)(node, context, ['test']) || additionalTestBlockFunctions.includes(name)) {
|
|
97
97
|
if (node.callee.type === _utils.AST_NODE_TYPES.MemberExpression && (0, _utils2.isSupportedAccessor)(node.callee.property, 'todo')) {
|
|
98
98
|
return;
|
|
99
99
|
}
|
|
@@ -46,7 +46,7 @@ var _default = (0, _utils2.createRule)({
|
|
|
46
46
|
parent
|
|
47
47
|
} = node;
|
|
48
48
|
|
|
49
|
-
if ((parent === null || parent === void 0 ? void 0 : parent.type) !== _utils.AST_NODE_TYPES.CallExpression || !(0, _utils2.
|
|
49
|
+
if ((parent === null || parent === void 0 ? void 0 : parent.type) !== _utils.AST_NODE_TYPES.CallExpression || !(0, _utils2.isTypeOfJestFnCall)(parent, context, ['describe'])) {
|
|
50
50
|
return;
|
|
51
51
|
}
|
|
52
52
|
|
|
@@ -69,7 +69,7 @@ var _default = (0, _utils2.createRule)({
|
|
|
69
69
|
parent
|
|
70
70
|
} = node;
|
|
71
71
|
|
|
72
|
-
if ((parent === null || parent === void 0 ? void 0 : parent.type) === _utils.AST_NODE_TYPES.CallExpression && (0, _utils2.
|
|
72
|
+
if ((parent === null || parent === void 0 ? void 0 : parent.type) === _utils.AST_NODE_TYPES.CallExpression && (0, _utils2.isTypeOfJestFnCall)(parent, context, ['describe'])) {
|
|
73
73
|
describeCallbackStack.pop();
|
|
74
74
|
}
|
|
75
75
|
}
|
|
@@ -64,7 +64,7 @@ var _default = (0, _utils.createRule)({
|
|
|
64
64
|
canonical
|
|
65
65
|
},
|
|
66
66
|
node: matcher.node.property,
|
|
67
|
-
fix: fixer => [
|
|
67
|
+
fix: fixer => [(0, _utils.replaceAccessorFixer)(fixer, matcher.node.property, canonical)]
|
|
68
68
|
});
|
|
69
69
|
}
|
|
70
70
|
}
|
|
@@ -39,7 +39,7 @@ var _default = (0, _utils2.createRule)({
|
|
|
39
39
|
return {
|
|
40
40
|
FunctionDeclaration(node) {
|
|
41
41
|
const declaredVariables = context.getDeclaredVariables(node);
|
|
42
|
-
const testCallExpressions = (0, _utils2.getTestCallExpressionsFromDeclaredVariables)(declaredVariables);
|
|
42
|
+
const testCallExpressions = (0, _utils2.getTestCallExpressionsFromDeclaredVariables)(declaredVariables, context);
|
|
43
43
|
|
|
44
44
|
if (testCallExpressions.length > 0) {
|
|
45
45
|
inTestCase = true;
|
|
@@ -47,7 +47,7 @@ var _default = (0, _utils2.createRule)({
|
|
|
47
47
|
},
|
|
48
48
|
|
|
49
49
|
CallExpression(node) {
|
|
50
|
-
if ((0, _utils2.
|
|
50
|
+
if ((0, _utils2.isTypeOfJestFnCall)(node, context, ['test'])) {
|
|
51
51
|
inTestCase = true;
|
|
52
52
|
}
|
|
53
53
|
|
|
@@ -71,7 +71,7 @@ var _default = (0, _utils2.createRule)({
|
|
|
71
71
|
},
|
|
72
72
|
|
|
73
73
|
'CallExpression:exit'(node) {
|
|
74
|
-
if ((0, _utils2.
|
|
74
|
+
if ((0, _utils2.isTypeOfJestFnCall)(node, context, ['test'])) {
|
|
75
75
|
inTestCase = false;
|
|
76
76
|
}
|
|
77
77
|
|
|
@@ -37,13 +37,13 @@ var _default = (0, _utils.createRule)({
|
|
|
37
37
|
|
|
38
38
|
return {
|
|
39
39
|
CallExpression(node) {
|
|
40
|
-
if ((0, _utils.
|
|
40
|
+
if ((0, _utils.isTypeOfJestFnCall)(node, context, ['test'])) {
|
|
41
41
|
inTestCase = true;
|
|
42
42
|
}
|
|
43
43
|
},
|
|
44
44
|
|
|
45
45
|
'CallExpression:exit'(node) {
|
|
46
|
-
if ((0, _utils.
|
|
46
|
+
if ((0, _utils.isTypeOfJestFnCall)(node, context, ['test'])) {
|
|
47
47
|
inTestCase = false;
|
|
48
48
|
}
|
|
49
49
|
},
|
|
@@ -7,8 +7,6 @@ exports.default = void 0;
|
|
|
7
7
|
|
|
8
8
|
var _utils = require("@typescript-eslint/utils");
|
|
9
9
|
|
|
10
|
-
var _detectJestVersion = require("./detectJestVersion");
|
|
11
|
-
|
|
12
10
|
var _utils2 = require("./utils");
|
|
13
11
|
|
|
14
12
|
const parseJestVersion = rawVersion => {
|
|
@@ -40,7 +38,7 @@ var _default = (0, _utils2.createRule)({
|
|
|
40
38
|
create(context) {
|
|
41
39
|
var _context$settings, _context$settings$jes;
|
|
42
40
|
|
|
43
|
-
const jestVersion = parseJestVersion(((_context$settings = context.settings) === null || _context$settings === void 0 ? void 0 : (_context$settings$jes = _context$settings.jest) === null || _context$settings$jes === void 0 ? void 0 : _context$settings$jes.version) || (0,
|
|
41
|
+
const jestVersion = parseJestVersion(((_context$settings = context.settings) === null || _context$settings === void 0 ? void 0 : (_context$settings$jes = _context$settings.jest) === null || _context$settings$jes === void 0 ? void 0 : _context$settings$jes.version) || (0, _utils2.detectJestVersion)());
|
|
44
42
|
const deprecations = { ...(jestVersion >= 15 && {
|
|
45
43
|
'jest.resetModuleRegistry': 'jest.resetModules'
|
|
46
44
|
}),
|
|
@@ -17,8 +17,6 @@ var _default = (0, _utils.createRule)({
|
|
|
17
17
|
},
|
|
18
18
|
messages: {
|
|
19
19
|
missingFunction: 'Test is missing function argument',
|
|
20
|
-
skippedTestSuite: 'Skipped test suite',
|
|
21
|
-
skippedTest: 'Skipped test',
|
|
22
20
|
pending: 'Call to pending()',
|
|
23
21
|
pendingSuite: 'Call to pending() within test suite',
|
|
24
22
|
pendingTest: 'Call to pending() within test',
|
|
@@ -34,51 +32,50 @@ var _default = (0, _utils.createRule)({
|
|
|
34
32
|
let suiteDepth = 0;
|
|
35
33
|
let testDepth = 0;
|
|
36
34
|
return {
|
|
37
|
-
'CallExpression[callee.name="describe"]'() {
|
|
38
|
-
suiteDepth++;
|
|
39
|
-
},
|
|
40
|
-
|
|
41
|
-
'CallExpression[callee.name=/^(it|test)$/]'() {
|
|
42
|
-
testDepth++;
|
|
43
|
-
},
|
|
44
|
-
|
|
45
|
-
'CallExpression[callee.name=/^(it|test)$/][arguments.length<2]'(node) {
|
|
46
|
-
context.report({
|
|
47
|
-
messageId: 'missingFunction',
|
|
48
|
-
node
|
|
49
|
-
});
|
|
50
|
-
},
|
|
51
|
-
|
|
52
35
|
CallExpression(node) {
|
|
53
|
-
const
|
|
36
|
+
const jestFnCall = (0, _utils.parseJestFnCall)(node, context);
|
|
54
37
|
|
|
55
|
-
if (
|
|
38
|
+
if (!jestFnCall) {
|
|
56
39
|
return;
|
|
57
40
|
}
|
|
58
41
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
break;
|
|
68
|
-
|
|
69
|
-
case 'it.skip':
|
|
70
|
-
case 'it.concurrent.skip':
|
|
71
|
-
case 'test.skip':
|
|
72
|
-
case 'test.concurrent.skip':
|
|
73
|
-
case 'it.skip.each':
|
|
74
|
-
case 'test.skip.each':
|
|
75
|
-
case 'xit.each':
|
|
76
|
-
case 'xtest.each':
|
|
42
|
+
if (jestFnCall.type === 'describe') {
|
|
43
|
+
suiteDepth++;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
if (jestFnCall.type === 'test') {
|
|
47
|
+
testDepth++;
|
|
48
|
+
|
|
49
|
+
if (node.arguments.length < 2 && jestFnCall.members.every(s => (0, _utils.getAccessorValue)(s) !== 'todo')) {
|
|
77
50
|
context.report({
|
|
78
|
-
messageId: '
|
|
51
|
+
messageId: 'missingFunction',
|
|
79
52
|
node
|
|
80
53
|
});
|
|
81
|
-
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
if ( // the only jest functions that are with "x" are "xdescribe", "xtest", and "xit"
|
|
58
|
+
jestFnCall.name.startsWith('x') || jestFnCall.members.some(s => (0, _utils.getAccessorValue)(s) === 'skip')) {
|
|
59
|
+
context.report({
|
|
60
|
+
messageId: jestFnCall.type === 'describe' ? 'disabledSuite' : 'disabledTest',
|
|
61
|
+
node
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
},
|
|
65
|
+
|
|
66
|
+
'CallExpression:exit'(node) {
|
|
67
|
+
const jestFnCall = (0, _utils.parseJestFnCall)(node, context);
|
|
68
|
+
|
|
69
|
+
if (!jestFnCall) {
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
if (jestFnCall.type === 'describe') {
|
|
74
|
+
suiteDepth--;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
if (jestFnCall.type === 'test') {
|
|
78
|
+
testDepth--;
|
|
82
79
|
}
|
|
83
80
|
},
|
|
84
81
|
|
|
@@ -103,28 +100,6 @@ var _default = (0, _utils.createRule)({
|
|
|
103
100
|
node
|
|
104
101
|
});
|
|
105
102
|
}
|
|
106
|
-
},
|
|
107
|
-
|
|
108
|
-
'CallExpression[callee.name="xdescribe"]'(node) {
|
|
109
|
-
context.report({
|
|
110
|
-
messageId: 'disabledSuite',
|
|
111
|
-
node
|
|
112
|
-
});
|
|
113
|
-
},
|
|
114
|
-
|
|
115
|
-
'CallExpression[callee.name=/^(xit|xtest)$/]'(node) {
|
|
116
|
-
context.report({
|
|
117
|
-
messageId: 'disabledTest',
|
|
118
|
-
node
|
|
119
|
-
});
|
|
120
|
-
},
|
|
121
|
-
|
|
122
|
-
'CallExpression[callee.name="describe"]:exit'() {
|
|
123
|
-
suiteDepth--;
|
|
124
|
-
},
|
|
125
|
-
|
|
126
|
-
'CallExpression[callee.name=/^(it|test)$/]:exit'() {
|
|
127
|
-
testDepth--;
|
|
128
103
|
}
|
|
129
104
|
|
|
130
105
|
};
|