eslint-plugin-jest 24.3.6 → 24.4.2

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,31 @@
1
+ ## [24.4.2](https://github.com/jest-community/eslint-plugin-jest/compare/v24.4.1...v24.4.2) (2021-09-17)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * use correct property `hasSuggestions` rather than `hasSuggestion` ([#899](https://github.com/jest-community/eslint-plugin-jest/issues/899)) ([dfd2368](https://github.com/jest-community/eslint-plugin-jest/commit/dfd2368d1cb1789b6a95a11be24c36868bb8a819))
7
+
8
+ ## [24.4.1](https://github.com/jest-community/eslint-plugin-jest/compare/v24.4.0...v24.4.1) (2021-09-17)
9
+
10
+
11
+ ### Bug Fixes
12
+
13
+ * mark rules that suggest fixes with `hasSuggestion` for ESLint v8 ([#898](https://github.com/jest-community/eslint-plugin-jest/issues/898)) ([ec0a21b](https://github.com/jest-community/eslint-plugin-jest/commit/ec0a21b0d98d043a9949138e495814e0935d5e31))
14
+
15
+ # [24.4.0](https://github.com/jest-community/eslint-plugin-jest/compare/v24.3.7...v24.4.0) (2021-07-21)
16
+
17
+
18
+ ### Features
19
+
20
+ * create `max-nested-describe` rule ([#845](https://github.com/jest-community/eslint-plugin-jest/issues/845)) ([8067405](https://github.com/jest-community/eslint-plugin-jest/commit/8067405deb609cc1800bce596e929c1840d290ab))
21
+
22
+ ## [24.3.7](https://github.com/jest-community/eslint-plugin-jest/compare/v24.3.6...v24.3.7) (2021-07-21)
23
+
24
+
25
+ ### Bug Fixes
26
+
27
+ * **valid-describe:** report on concise-body arrow functions ([#863](https://github.com/jest-community/eslint-plugin-jest/issues/863)) ([71c5299](https://github.com/jest-community/eslint-plugin-jest/commit/71c5299b14cac6d85ba8f8bd939461503a60468f))
28
+
1
29
  ## [24.3.6](https://github.com/jest-community/eslint-plugin-jest/compare/v24.3.5...v24.3.6) (2021-04-26)
2
30
 
3
31
 
package/README.md CHANGED
@@ -13,8 +13,8 @@
13
13
 
14
14
  ## Installation
15
15
 
16
- ```
17
- $ yarn add --dev eslint eslint-plugin-jest
16
+ ```bash
17
+ yarn add --dev eslint eslint-plugin-jest
18
18
  ```
19
19
 
20
20
  **Note:** If you installed ESLint globally then you must also install
@@ -135,6 +135,7 @@ installations requiring long-term consistency.
135
135
  | [consistent-test-it](docs/rules/consistent-test-it.md) | Have control over `test` and `it` usages | | ![fixable][] |
136
136
  | [expect-expect](docs/rules/expect-expect.md) | Enforce assertion to be made in a test body | ![recommended][] | |
137
137
  | [lowercase-name](docs/rules/lowercase-name.md) | Enforce lowercase test names | | ![fixable][] |
138
+ | [max-nested-describe](docs/rules/max-nested-describe.md) | Enforces a maximum depth to nested describe calls | | |
138
139
  | [no-alias-methods](docs/rules/no-alias-methods.md) | Disallow alias methods | ![style][] | ![fixable][] |
139
140
  | [no-commented-out-tests](docs/rules/no-commented-out-tests.md) | Disallow commented out tests | ![recommended][] | |
140
141
  | [no-conditional-expect](docs/rules/no-conditional-expect.md) | Prevent calling `expect` conditionally | ![recommended][] | |
@@ -0,0 +1,131 @@
1
+ # Enforces a maximum depth to nested describe calls (`max-nested-describe`)
2
+
3
+ While it's useful to be able to group your tests together within the same file
4
+ using `describe()`, having too many levels of nesting throughout your tests make
5
+ them difficult to read.
6
+
7
+ ## Rule Details
8
+
9
+ This rule enforces a maximum depth to nested `describe()` calls to improve code
10
+ clarity in your tests.
11
+
12
+ The following patterns are considered warnings (with the default option of
13
+ `{ "max": 5 } `):
14
+
15
+ ```js
16
+ describe('foo', () => {
17
+ describe('bar', () => {
18
+ describe('baz', () => {
19
+ describe('qux', () => {
20
+ describe('quxx', () => {
21
+ describe('too many', () => {
22
+ it('should get something', () => {
23
+ expect(getSomething()).toBe('Something');
24
+ });
25
+ });
26
+ });
27
+ });
28
+ });
29
+ });
30
+ });
31
+
32
+ describe('foo', function () {
33
+ describe('bar', function () {
34
+ describe('baz', function () {
35
+ describe('qux', function () {
36
+ describe('quxx', function () {
37
+ describe('too many', function () {
38
+ it('should get something', () => {
39
+ expect(getSomething()).toBe('Something');
40
+ });
41
+ });
42
+ });
43
+ });
44
+ });
45
+ });
46
+ });
47
+ ```
48
+
49
+ The following patterns are **not** considered warnings (with the default option
50
+ of `{ "max": 5 } `):
51
+
52
+ ```js
53
+ describe('foo', () => {
54
+ describe('bar', () => {
55
+ it('should get something', () => {
56
+ expect(getSomething()).toBe('Something');
57
+ });
58
+ });
59
+
60
+ describe('qux', () => {
61
+ it('should get something', () => {
62
+ expect(getSomething()).toBe('Something');
63
+ });
64
+ });
65
+ });
66
+
67
+ describe('foo2', function () {
68
+ it('should get something', () => {
69
+ expect(getSomething()).toBe('Something');
70
+ });
71
+ });
72
+
73
+ describe('foo', function () {
74
+ describe('bar', function () {
75
+ describe('baz', function () {
76
+ describe('qux', function () {
77
+ describe('this is the limit', function () {
78
+ it('should get something', () => {
79
+ expect(getSomething()).toBe('Something');
80
+ });
81
+ });
82
+ });
83
+ });
84
+ });
85
+ });
86
+ ```
87
+
88
+ ## Options
89
+
90
+ ```json
91
+ {
92
+ "jest/max-nested-describe": [
93
+ "error",
94
+ {
95
+ "max": 5
96
+ }
97
+ ]
98
+ }
99
+ ```
100
+
101
+ ### `max`
102
+
103
+ Enforces a maximum depth for nested `describe()`.
104
+
105
+ This has a default value of `5`.
106
+
107
+ Examples of patterns **not** considered warnings with options set to
108
+ `{ "max": 2 }`:
109
+
110
+ ```js
111
+ describe('foo', () => {
112
+ describe('bar', () => {
113
+ it('should get something', () => {
114
+ expect(getSomething()).toBe('Something');
115
+ });
116
+ });
117
+ });
118
+
119
+ describe('foo2', function()) {
120
+ describe('bar2', function() {
121
+ it('should get something', function() {
122
+ expect(getSomething()).toBe('Something');
123
+ });
124
+
125
+ it('should get else', function() {
126
+ expect(getSomething()).toBe('Something');
127
+ });
128
+ });
129
+ });
130
+
131
+ ```
@@ -27,7 +27,7 @@ are not using TypeScript.
27
27
  overrides: [
28
28
  {
29
29
  files: ['test/**'],
30
- extends: ['jest'],
30
+ plugins: ['jest'],
31
31
  rules: {
32
32
  // you should turn the original rule off *only* for test files
33
33
  '@typescript-eslint/unbound-method': 'off',
@@ -43,6 +43,12 @@ describe('myFunction', () => {
43
43
  });
44
44
  });
45
45
  });
46
+
47
+ // Returning a value from a describe block is not allowed
48
+ describe('myFunction', () =>
49
+ it('returns a truthy value', () => {
50
+ expect(myFunction()).toBeTruthy();
51
+ }));
46
52
  ```
47
53
 
48
54
  The following patterns are not considered warnings:
@@ -204,11 +204,11 @@ specific Jest test function groups (`describe`, `test`, and `it`).
204
204
  Examples of **incorrect** code when using `mustMatch`:
205
205
 
206
206
  ```js
207
- // with mustMatch: '$that'
207
+ // with mustMatch: '^that'
208
208
  describe('the correct way to do things', () => {});
209
209
  fit('this there!', () => {});
210
210
 
211
- // with mustMatch: { test: '$that' }
211
+ // with mustMatch: { test: '^that' }
212
212
  describe('the tests that will be run', () => {});
213
213
  test('the stuff works', () => {});
214
214
  xtest('errors that are thrown have messages', () => {});
@@ -217,11 +217,11 @@ xtest('errors that are thrown have messages', () => {});
217
217
  Examples of **correct** code when using `mustMatch`:
218
218
 
219
219
  ```js
220
- // with mustMatch: '$that'
220
+ // with mustMatch: '^that'
221
221
  describe('that thing that needs to be done', () => {});
222
222
  fit('that this there!', () => {});
223
223
 
224
- // with mustMatch: { test: '$that' }
224
+ // with mustMatch: { test: '^that' }
225
225
  describe('the tests that will be run', () => {});
226
226
  test('that the stuff works', () => {});
227
227
  xtest('that errors that thrown have messages', () => {});
package/lib/index.js CHANGED
@@ -8,9 +8,9 @@ var _globals = _interopRequireDefault(require("./globals.json"));
8
8
 
9
9
  var snapshotProcessor = _interopRequireWildcard(require("./processors/snapshot-processor"));
10
10
 
11
- function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
11
+ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
12
12
 
13
- function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
13
+ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
14
14
 
15
15
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
16
16
 
@@ -0,0 +1,87 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+
8
+ var _experimentalUtils = require("@typescript-eslint/experimental-utils");
9
+
10
+ var _utils = require("./utils");
11
+
12
+ var _default = (0, _utils.createRule)({
13
+ name: __filename,
14
+ meta: {
15
+ docs: {
16
+ category: 'Best Practices',
17
+ description: 'Enforces a maximum depth to nested describe calls',
18
+ recommended: false
19
+ },
20
+ messages: {
21
+ exceededMaxDepth: 'Too many nested describe calls ({{ depth }}). Maximum allowed is {{ max }}.'
22
+ },
23
+ type: 'suggestion',
24
+ schema: [{
25
+ type: 'object',
26
+ properties: {
27
+ max: {
28
+ type: 'integer',
29
+ minimum: 0
30
+ }
31
+ },
32
+ additionalProperties: false
33
+ }]
34
+ },
35
+ defaultOptions: [{
36
+ max: 5
37
+ }],
38
+
39
+ create(context, [{
40
+ max
41
+ }]) {
42
+ const describeCallbackStack = [];
43
+
44
+ function pushDescribeCallback(node) {
45
+ const {
46
+ parent
47
+ } = node;
48
+
49
+ if ((parent === null || parent === void 0 ? void 0 : parent.type) !== _experimentalUtils.AST_NODE_TYPES.CallExpression || !(0, _utils.isDescribeCall)(parent)) {
50
+ return;
51
+ }
52
+
53
+ describeCallbackStack.push(0);
54
+
55
+ if (describeCallbackStack.length > max) {
56
+ context.report({
57
+ node: parent,
58
+ messageId: 'exceededMaxDepth',
59
+ data: {
60
+ depth: describeCallbackStack.length,
61
+ max
62
+ }
63
+ });
64
+ }
65
+ }
66
+
67
+ function popDescribeCallback(node) {
68
+ const {
69
+ parent
70
+ } = node;
71
+
72
+ if ((parent === null || parent === void 0 ? void 0 : parent.type) === _experimentalUtils.AST_NODE_TYPES.CallExpression && (0, _utils.isDescribeCall)(parent)) {
73
+ describeCallbackStack.pop();
74
+ }
75
+ }
76
+
77
+ return {
78
+ FunctionExpression: pushDescribeCallback,
79
+ 'FunctionExpression:exit': popDescribeCallback,
80
+ ArrowFunctionExpression: pushDescribeCallback,
81
+ 'ArrowFunctionExpression:exit': popDescribeCallback
82
+ };
83
+ }
84
+
85
+ });
86
+
87
+ exports.default = _default;
@@ -24,10 +24,10 @@ const detectJestVersion = () => {
24
24
  try {
25
25
  const jestPath = require.resolve('jest/package.json', {
26
26
  paths: [process.cwd()]
27
- }); // eslint-disable-next-line @typescript-eslint/no-require-imports
27
+ });
28
28
 
29
-
30
- const jestPackageJson = require(jestPath);
29
+ const jestPackageJson = // eslint-disable-next-line @typescript-eslint/no-require-imports
30
+ require(jestPath);
31
31
 
32
32
  if (jestPackageJson.version) {
33
33
  const [majorVersion] = jestPackageJson.version.split('.');
@@ -40,7 +40,8 @@ var _default = (0, _utils.createRule)({
40
40
  useAwaitInsteadOfCallback: 'Use await instead of callback in async functions'
41
41
  },
42
42
  schema: [],
43
- type: 'suggestion'
43
+ type: 'suggestion',
44
+ hasSuggestions: true
44
45
  },
45
46
  defaultOptions: [],
46
47
 
@@ -41,7 +41,8 @@ var _default = (0, _utils.createRule)({
41
41
  suggestRemoveFocus: 'Remove focus from test.'
42
42
  },
43
43
  schema: [],
44
- type: 'suggestion'
44
+ type: 'suggestion',
45
+ hasSuggestions: true
45
46
  },
46
47
  defaultOptions: [],
47
48
  create: context => ({
@@ -39,6 +39,7 @@ var _default = (0, _utils.createRule)({
39
39
  suggestRemovingExtraArguments: 'Remove extra arguments'
40
40
  },
41
41
  type: 'suggestion',
42
+ hasSuggestions: true,
42
43
  schema: [{
43
44
  type: 'object',
44
45
  properties: {
@@ -21,7 +21,8 @@ var _default = (0, _utils.createRule)({
21
21
  suggestReplaceWithStrictEqual: 'Replace with `toStrictEqual()`'
22
22
  },
23
23
  type: 'suggestion',
24
- schema: []
24
+ schema: [],
25
+ hasSuggestions: true
25
26
  },
26
27
  defaultOptions: [],
27
28
 
@@ -61,8 +61,7 @@ const isStringLiteral = (node, value) => node.type === _experimentalUtils.AST_NO
61
61
  *
62
62
  * @template V
63
63
  */
64
- const isTemplateLiteral = (node, value) => node.type === _experimentalUtils.AST_NODE_TYPES.TemplateLiteral && node.quasis.length === 1 && ( // bail out if not simple
65
- value === undefined || node.quasis[0].value.raw === value);
64
+ const isTemplateLiteral = (node, value) => node.type === _experimentalUtils.AST_NODE_TYPES.TemplateLiteral && node.quasis.length === 1 && (value === undefined || node.quasis[0].value.raw === value);
66
65
 
67
66
  /**
68
67
  * Checks if the given `node` is a {@link StringNode}.
@@ -84,6 +84,13 @@ var _default = (0, _utils.createRule)({
84
84
  });
85
85
  }
86
86
 
87
+ if (callback.body.type === _experimentalUtils.AST_NODE_TYPES.CallExpression) {
88
+ context.report({
89
+ messageId: 'unexpectedReturnInDescribe',
90
+ node: callback
91
+ });
92
+ }
93
+
87
94
  if (callback.body.type === _experimentalUtils.AST_NODE_TYPES.BlockStatement) {
88
95
  callback.body.body.forEach(node => {
89
96
  if (node.type === _experimentalUtils.AST_NODE_TYPES.ReturnStatement) {
@@ -123,13 +123,12 @@ var _default = (0, _utils.createRule)({
123
123
  return;
124
124
  }
125
125
 
126
- const testFunctionBody = body.body;
127
- const [fulfillmentCallback, rejectionCallback] = node.arguments; // then block can have two args, fulfillment & rejection
126
+ const testFunctionBody = body.body; // then block can have two args, fulfillment & rejection
128
127
  // then block can have one args, fulfillment
129
128
  // catch block can have one args, rejection
130
129
  // ref: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise
131
130
 
132
- verifyExpectWithReturn([fulfillmentCallback, rejectionCallback], node.callee, context, testFunctionBody);
131
+ verifyExpectWithReturn(node.arguments.slice(0, 2), node.callee, context, testFunctionBody);
133
132
  }
134
133
  }
135
134
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint-plugin-jest",
3
- "version": "24.3.6",
3
+ "version": "24.4.2",
4
4
  "description": "Eslint rules for Jest",
5
5
  "keywords": [
6
6
  "eslint",
@@ -92,12 +92,12 @@
92
92
  "@semantic-release/changelog": "^5.0.1",
93
93
  "@semantic-release/git": "^9.0.0",
94
94
  "@types/dedent": "^0.7.0",
95
- "@types/jest": "^26.0.0",
95
+ "@types/jest": "^27.0.0",
96
96
  "@types/node": "^14.0.0",
97
97
  "@types/prettier": "^2.0.0",
98
98
  "@typescript-eslint/eslint-plugin": "^4.0.1",
99
99
  "@typescript-eslint/parser": "^4.0.1",
100
- "babel-jest": "^26.0.1",
100
+ "babel-jest": "^27.0.0",
101
101
  "babel-plugin-replace-ts-export-assignment": "^0.0.2",
102
102
  "dedent": "^0.7.0",
103
103
  "eslint": "^5.1.0 || ^6.0.0 || ^7.0.0",
@@ -110,7 +110,7 @@
110
110
  "eslint-plugin-prettier": "^3.0.0",
111
111
  "husky": "^6.0.0",
112
112
  "is-ci": "^3.0.0",
113
- "jest": "^26.0.1",
113
+ "jest": "^27.0.0",
114
114
  "jest-runner-eslint": "^0.10.0",
115
115
  "lint-staged": "^10.2.2",
116
116
  "pinst": "^2.0.0",
@@ -118,8 +118,9 @@
118
118
  "resolve-from": "^5.0.0",
119
119
  "rimraf": "^3.0.0",
120
120
  "semantic-release": "^17.0.7",
121
+ "semver": "^7.3.5",
121
122
  "ts-node": "^9.0.0",
122
- "typescript": "^4.0.0"
123
+ "typescript": "^4.4.0"
123
124
  },
124
125
  "peerDependencies": {
125
126
  "@typescript-eslint/eslint-plugin": ">= 4",
@@ -135,7 +136,11 @@
135
136
  },
136
137
  "release": {
137
138
  "branches": [
138
- "main"
139
+ "main",
140
+ {
141
+ "name": "next",
142
+ "prerelease": true
143
+ }
139
144
  ],
140
145
  "plugins": [
141
146
  "@semantic-release/commit-analyzer",