eslint-plugin-jest 22.21.0 → 23.0.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.
Files changed (37) hide show
  1. package/CHANGELOG.md +29 -2
  2. package/README.md +12 -14
  3. package/docs/rules/{require-tothrow-message.md → require-to-throw-message.md} +0 -0
  4. package/docs/rules/valid-title.md +78 -0
  5. package/lib/__tests__/__snapshots__/rules.test.ts.snap +94 -0
  6. package/lib/__tests__/rules.test.js +19 -2
  7. package/lib/index.js +9 -3
  8. package/lib/rules/expect-expect.js +5 -25
  9. package/lib/rules/lowercase-name.js +4 -12
  10. package/lib/rules/no-alias-methods.js +3 -2
  11. package/lib/rules/no-export.js +13 -30
  12. package/lib/rules/no-focused-tests.js +3 -1
  13. package/lib/rules/no-identical-title.js +1 -10
  14. package/lib/rules/no-jasmine-globals.js +10 -4
  15. package/lib/rules/no-mocks-import.js +1 -10
  16. package/lib/rules/no-test-callback.js +16 -15
  17. package/lib/rules/no-test-return-statement.js +1 -10
  18. package/lib/rules/no-truthy-falsy.js +3 -2
  19. package/lib/rules/prefer-called-with.js +4 -4
  20. package/lib/rules/prefer-expect-assertions.js +1 -11
  21. package/lib/rules/prefer-inline-snapshots.js +3 -1
  22. package/lib/rules/prefer-spy-on.js +5 -14
  23. package/lib/rules/prefer-strict-equal.js +3 -2
  24. package/lib/rules/prefer-to-be-null.js +3 -2
  25. package/lib/rules/prefer-to-be-undefined.js +3 -2
  26. package/lib/rules/prefer-to-contain.js +10 -23
  27. package/lib/rules/prefer-to-have-length.js +6 -12
  28. package/lib/rules/prefer-todo.js +3 -15
  29. package/lib/rules/{require-tothrow-message.js → require-to-throw-message.js} +7 -8
  30. package/lib/rules/utils.js +36 -50
  31. package/lib/rules/valid-describe.js +9 -29
  32. package/lib/rules/valid-expect-in-promise.js +4 -14
  33. package/lib/rules/valid-expect.js +5 -4
  34. package/lib/rules/valid-title.js +48 -15
  35. package/package.json +27 -13
  36. package/docs/rules/no-empty-title.md +0 -36
  37. package/lib/rules/no-empty-title.js +0 -60
@@ -9,14 +9,6 @@ var _experimentalUtils = require("@typescript-eslint/experimental-utils");
9
9
 
10
10
  var _utils = require("./utils");
11
11
 
12
- function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _nonIterableRest(); }
13
-
14
- function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance"); }
15
-
16
- function _iterableToArrayLimit(arr, i) { if (!(Symbol.iterator in Object(arr) || Object.prototype.toString.call(arr) === "[object Arguments]")) { return; } var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
17
-
18
- function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
19
-
20
12
  const isThenOrCatchCall = node => node.type === _experimentalUtils.AST_NODE_TYPES.CallExpression && node.callee.type === _experimentalUtils.AST_NODE_TYPES.MemberExpression && (0, _utils.isSupportedAccessor)(node.callee.property) && ['then', 'catch'].includes((0, _utils.getAccessorValue)(node.callee.property));
21
13
 
22
14
  const isExpectCallPresentInFunction = body => {
@@ -125,7 +117,9 @@ var _default = (0, _utils.createRule)({
125
117
  const testFunction = findTestFunction(node);
126
118
 
127
119
  if (testFunction && !isHavingAsyncCallBackParam(testFunction)) {
128
- const body = testFunction.body;
120
+ const {
121
+ body
122
+ } = testFunction;
129
123
  /* istanbul ignore if https://github.com/typescript-eslint/typescript-eslint/issues/734 */
130
124
 
131
125
  if (!body) {
@@ -137,15 +131,11 @@ var _default = (0, _utils.createRule)({
137
131
  }
138
132
 
139
133
  const testFunctionBody = body.body;
140
-
141
- const _node$arguments = _slicedToArray(node.arguments, 2),
142
- fulfillmentCallback = _node$arguments[0],
143
- rejectionCallback = _node$arguments[1]; // then block can have two args, fulfillment & rejection
134
+ const [fulfillmentCallback, rejectionCallback] = node.arguments; // then block can have two args, fulfillment & rejection
144
135
  // then block can have one args, fulfillment
145
136
  // catch block can have one args, rejection
146
137
  // ref: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise
147
138
 
148
-
149
139
  verifyExpectWithReturn([fulfillmentCallback, rejectionCallback], node.callee, context, testFunctionBody);
150
140
  }
151
141
  }
@@ -111,10 +111,11 @@ var _default = (0, _utils.createRule)({
111
111
  return;
112
112
  }
113
113
 
114
- const _parseExpectCall = (0, _utils.parseExpectCall)(node),
115
- expect = _parseExpectCall.expect,
116
- modifier = _parseExpectCall.modifier,
117
- matcher = _parseExpectCall.matcher;
114
+ const {
115
+ expect,
116
+ modifier,
117
+ matcher
118
+ } = (0, _utils.parseExpectCall)(node);
118
119
 
119
120
  if (expect.arguments.length > 1) {
120
121
  const secondArgumentLocStart = expect.arguments[1].loc.start;
@@ -9,15 +9,19 @@ var _experimentalUtils = require("@typescript-eslint/experimental-utils");
9
9
 
10
10
  var _utils = require("./utils");
11
11
 
12
- function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _nonIterableRest(); }
13
-
14
- function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance"); }
12
+ const trimFXprefix = word => ['f', 'x'].includes(word.charAt(0)) ? word.substr(1) : word;
15
13
 
16
- function _iterableToArrayLimit(arr, i) { if (!(Symbol.iterator in Object(arr) || Object.prototype.toString.call(arr) === "[object Arguments]")) { return; } var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
14
+ const doesBinaryExpressionContainStringNode = binaryExp => {
15
+ if ((0, _utils.isStringNode)(binaryExp.right)) {
16
+ return true;
17
+ }
17
18
 
18
- function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
19
+ if (binaryExp.left.type === _experimentalUtils.AST_NODE_TYPES.BinaryExpression) {
20
+ return doesBinaryExpressionContainStringNode(binaryExp.left);
21
+ }
19
22
 
20
- const trimFXprefix = word => ['f', 'x'].includes(word.charAt(0)) ? word.substr(1) : word;
23
+ return (0, _utils.isStringNode)(binaryExp.left);
24
+ };
21
25
 
22
26
  var _default = (0, _utils.createRule)({
23
27
  name: __filename,
@@ -28,32 +32,64 @@ var _default = (0, _utils.createRule)({
28
32
  recommended: false
29
33
  },
30
34
  messages: {
35
+ titleMustBeString: 'Title must be a string',
36
+ emptyTitle: '{{ jestFunctionName }} should not have an empty title',
31
37
  duplicatePrefix: 'should not have duplicate prefix',
32
38
  accidentalSpace: 'should not have leading or trailing spaces'
33
39
  },
34
40
  type: 'suggestion',
35
- schema: [],
41
+ schema: [{
42
+ type: 'object',
43
+ properties: {
44
+ ignoreTypeOfDescribeName: {
45
+ type: 'boolean',
46
+ default: false
47
+ }
48
+ },
49
+ additionalProperties: false
50
+ }],
36
51
  fixable: 'code'
37
52
  },
38
- defaultOptions: [],
53
+ defaultOptions: [{
54
+ ignoreTypeOfDescribeName: false
55
+ }],
39
56
 
40
- create(context) {
57
+ create(context, [{
58
+ ignoreTypeOfDescribeName
59
+ }]) {
41
60
  return {
42
61
  CallExpression(node) {
43
62
  if (!((0, _utils.isDescribe)(node) || (0, _utils.isTestCase)(node)) || !node.arguments.length) {
44
63
  return;
45
64
  }
46
65
 
47
- const _node$arguments = _slicedToArray(node.arguments, 1),
48
- argument = _node$arguments[0];
66
+ const [argument] = (0, _utils.getJestFunctionArguments)(node);
49
67
 
50
68
  if (!(0, _utils.isStringNode)(argument)) {
69
+ if (argument.type === _experimentalUtils.AST_NODE_TYPES.BinaryExpression && doesBinaryExpressionContainStringNode(argument)) {
70
+ return;
71
+ }
72
+
73
+ if (argument.type !== _experimentalUtils.AST_NODE_TYPES.TemplateLiteral && !(ignoreTypeOfDescribeName && (0, _utils.isDescribe)(node))) {
74
+ context.report({
75
+ messageId: 'titleMustBeString',
76
+ loc: argument.loc
77
+ });
78
+ }
79
+
51
80
  return;
52
81
  }
53
82
 
54
83
  const title = (0, _utils.getStringValue)(argument);
55
84
 
56
85
  if (!title) {
86
+ context.report({
87
+ messageId: 'emptyTitle',
88
+ data: {
89
+ jestFunctionName: (0, _utils.isDescribe)(node) ? _utils.DescribeAlias.describe : _utils.TestCaseName.test
90
+ },
91
+ node
92
+ });
57
93
  return;
58
94
  }
59
95
 
@@ -71,10 +107,7 @@ var _default = (0, _utils.createRule)({
71
107
  }
72
108
 
73
109
  const nodeName = trimFXprefix((0, _utils.getNodeName)(node.callee));
74
-
75
- const _title$split = title.split(' '),
76
- _title$split2 = _slicedToArray(_title$split, 1),
77
- firstWord = _title$split2[0];
110
+ const [firstWord] = title.split(' ');
78
111
 
79
112
  if (firstWord.toLowerCase() === nodeName) {
80
113
  context.report({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint-plugin-jest",
3
- "version": "22.21.0",
3
+ "version": "23.0.3",
4
4
  "description": "Eslint rules for Jest",
5
5
  "repository": "jest-community/eslint-plugin-jest",
6
6
  "license": "MIT",
@@ -20,7 +20,7 @@
20
20
  ],
21
21
  "main": "lib/",
22
22
  "engines": {
23
- "node": ">=6"
23
+ "node": ">=8"
24
24
  },
25
25
  "peerDependencies": {
26
26
  "eslint": ">=5"
@@ -37,35 +37,39 @@
37
37
  "typecheck": "tsc -p ."
38
38
  },
39
39
  "dependencies": {
40
- "@typescript-eslint/experimental-utils": "^1.13.0"
40
+ "@typescript-eslint/experimental-utils": "^2.5.0"
41
41
  },
42
42
  "devDependencies": {
43
43
  "@babel/cli": "^7.4.4",
44
44
  "@babel/core": "^7.4.4",
45
45
  "@babel/preset-env": "^7.4.4",
46
46
  "@babel/preset-typescript": "^7.3.3",
47
- "@commitlint/cli": "^6.0.0",
48
- "@commitlint/config-conventional": "^6.0.0",
49
- "@types/eslint": "^4.16.6",
47
+ "@commitlint/cli": "^8.2.0",
48
+ "@commitlint/config-conventional": "^8.2.0",
49
+ "@semantic-release/changelog": "^3.0.5",
50
+ "@semantic-release/git": "^7.0.17",
51
+ "@types/eslint": "^6.1.3",
50
52
  "@types/jest": "^24.0.15",
51
53
  "@types/node": "^12.6.6",
52
- "@typescript-eslint/eslint-plugin": "^1.13.0",
53
- "@typescript-eslint/parser": "^1.13.0",
54
+ "@typescript-eslint/eslint-plugin": "^2.5.0",
55
+ "@typescript-eslint/parser": "^2.5.0",
54
56
  "babel-jest": "^24.9.0",
55
57
  "babel-plugin-replace-ts-export-assignment": "^0.0.2",
56
- "eslint": "^5.1.0",
57
- "eslint-config-prettier": "^5.1.0",
58
+ "eslint": "^5.1.0 || ^6.0.0",
59
+ "eslint-config-prettier": "^6.5.0",
58
60
  "eslint-plugin-eslint-plugin": "^2.0.0",
59
61
  "eslint-plugin-import": "^2.18.0",
60
- "eslint-plugin-node": "^8.0.0",
62
+ "eslint-plugin-node": "^10.0.0",
61
63
  "eslint-plugin-prettier": "^3.0.0",
62
- "husky": "^1.0.1",
64
+ "husky": "^3.0.9",
63
65
  "jest": "^24.9.0",
64
66
  "jest-runner-eslint": "^0.7.1",
65
- "lint-staged": "^8.0.4",
67
+ "lint-staged": "^9.4.2",
66
68
  "prettier": "^1.10.2",
67
69
  "prettylint": "^1.0.0",
70
+ "resolve-from": "^5.0.0",
68
71
  "rimraf": "^3.0.0",
72
+ "semantic-release": "^15.13.28",
69
73
  "typescript": "^3.5.3"
70
74
  },
71
75
  "prettier": {
@@ -122,5 +126,15 @@
122
126
  "commit-msg": "commitlint -e $HUSKY_GIT_PARAMS",
123
127
  "pre-commit": "lint-staged"
124
128
  }
129
+ },
130
+ "release": {
131
+ "plugins": [
132
+ "@semantic-release/commit-analyzer",
133
+ "@semantic-release/release-notes-generator",
134
+ "@semantic-release/changelog",
135
+ "@semantic-release/npm",
136
+ "@semantic-release/git",
137
+ "@semantic-release/github"
138
+ ]
125
139
  }
126
140
  }
@@ -1,36 +0,0 @@
1
- # Disallow empty titles
2
-
3
- Having an empty string as your test title is pretty useless. This rule reports
4
- an error if it finds an empty string as s test title.
5
-
6
- This rule is not auto-fixable.
7
-
8
- ## Rule Details
9
-
10
- The following patterns are considered warnings:
11
-
12
- ```js
13
- describe('', () => {});
14
- describe('foo', () => {
15
- it('', () => {});
16
- });
17
- it('', () => {});
18
- test('', () => {});
19
- xdescribe('', () => {});
20
- xit('', () => {});
21
- xtest('', () => {});
22
- ```
23
-
24
- These patterns would not be considered warnings:
25
-
26
- ```js
27
- describe('foo', () => {});
28
- describe('foo', () => {
29
- it('bar', () => {});
30
- });
31
- test('foo', () => {});
32
- it('foo', () => {});
33
- xdescribe('foo', () => {});
34
- xit('foo', () => {});
35
- xtest('foo', () => {});
36
- ```
@@ -1,60 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
-
8
- var _utils = require("./utils");
9
-
10
- function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _nonIterableRest(); }
11
-
12
- function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance"); }
13
-
14
- function _iterableToArrayLimit(arr, i) { if (!(Symbol.iterator in Object(arr) || Object.prototype.toString.call(arr) === "[object Arguments]")) { return; } var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
15
-
16
- function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
17
-
18
- var _default = (0, _utils.createRule)({
19
- name: __filename,
20
- meta: {
21
- docs: {
22
- category: 'Best Practices',
23
- description: 'Disallow empty titles',
24
- recommended: false
25
- },
26
- messages: {
27
- describe: 'describe should not have an empty title',
28
- test: 'test should not have an empty title'
29
- },
30
- type: 'suggestion',
31
- schema: []
32
- },
33
- defaultOptions: [],
34
-
35
- create(context) {
36
- return {
37
- CallExpression(node) {
38
- if (!(0, _utils.isDescribe)(node) && !(0, _utils.isTestCase)(node)) {
39
- return;
40
- }
41
-
42
- const _node$arguments = _slicedToArray(node.arguments, 1),
43
- argument = _node$arguments[0];
44
-
45
- if (!argument || !(0, _utils.isStringNode)(argument, '')) {
46
- return;
47
- }
48
-
49
- context.report({
50
- messageId: (0, _utils.isDescribe)(node) ? _utils.DescribeAlias.describe : _utils.TestCaseName.test,
51
- node: argument
52
- });
53
- }
54
-
55
- };
56
- }
57
-
58
- });
59
-
60
- exports.default = _default;