eslint-plugin-jest 23.7.0 → 23.8.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,17 @@
1
+ # [23.8.0](https://github.com/jest-community/eslint-plugin-jest/compare/v23.7.0...v23.8.0) (2020-02-23)
2
+
3
+ ### Bug Fixes
4
+
5
+ - **valid-title:** ensure argument node is defined before accessing props
6
+ ([#538](https://github.com/jest-community/eslint-plugin-jest/issues/538))
7
+ ([7730f75](https://github.com/jest-community/eslint-plugin-jest/commit/7730f757561100559509b756fd362ca33b9ab1d4))
8
+
9
+ ### Features
10
+
11
+ - **no-large-snapshots:** add setting to define maxSize by snapshot type
12
+ ([#524](https://github.com/jest-community/eslint-plugin-jest/issues/524))
13
+ ([0d77300](https://github.com/jest-community/eslint-plugin-jest/commit/0d77300e61adc7a5aa84f34ff4ccc164075d5f41))
14
+
1
15
  # [23.7.0](https://github.com/jest-community/eslint-plugin-jest/compare/v23.6.0...v23.7.0) (2020-02-07)
2
16
 
3
17
  ### Bug Fixes
@@ -98,7 +98,7 @@ line 4
98
98
 
99
99
  ## Options
100
100
 
101
- This rule has an option for modifying the max number of lines allowed for a
101
+ This rule has options for modifying the max number of lines allowed for a
102
102
  snapshot:
103
103
 
104
104
  In an `eslintrc` file:
@@ -106,11 +106,19 @@ In an `eslintrc` file:
106
106
  ```json
107
107
  ...
108
108
  "rules": {
109
- "jest/no-large-snapshots": ["warn", { "maxSize": 12 }]
109
+ "jest/no-large-snapshots": ["warn", { "maxSize": 12, "inlineMaxSize": 6 }]
110
110
  }
111
111
  ...
112
112
  ```
113
113
 
114
+ Max number of lines allowed could be defined by snapshot type (Inline and
115
+ External). Use `inlineMaxSize` for
116
+ [Inline Snapshots](https://jestjs.io/docs/en/snapshot-testing#inline-snapshots)
117
+ size and `maxSize` for
118
+ [External Snapshots](https://jestjs.io/docs/en/snapshot-testing#snapshot-testing-with-jest).
119
+ If only `maxSize` is provided on options, the value of `maxSize` will be used to
120
+ both snapshot types (Inline and External).
121
+
114
122
  In addition there is an option for whitelisting large snapshot files. Since
115
123
  `//eslint` comments will be removed when a `.snap` file is updated, this option
116
124
  provides a way of whitelisting large snapshots. The list of whitelistedSnapshots
@@ -11,6 +11,12 @@ var _experimentalUtils = require("@typescript-eslint/experimental-utils");
11
11
 
12
12
  var _utils = require("./utils");
13
13
 
14
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
15
+
16
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
17
+
18
+ function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
19
+
14
20
  const reportOnViolation = (context, node, {
15
21
  maxSize: lineLimit = 50,
16
22
  whitelistedSnapshots = {}
@@ -73,6 +79,9 @@ var _default = (0, _utils.createRule)({
73
79
  maxSize: {
74
80
  type: 'number'
75
81
  },
82
+ inlineMaxSize: {
83
+ type: 'number'
84
+ },
76
85
  whitelistedSnapshots: {
77
86
  type: 'object',
78
87
  patternProperties: {
@@ -99,7 +108,11 @@ var _default = (0, _utils.createRule)({
99
108
  return {
100
109
  CallExpression(node) {
101
110
  if ('property' in node.callee && ((0, _utils.isSupportedAccessor)(node.callee.property, 'toMatchInlineSnapshot') || (0, _utils.isSupportedAccessor)(node.callee.property, 'toThrowErrorMatchingInlineSnapshot'))) {
102
- reportOnViolation(context, node, options);
111
+ var _options$inlineMaxSiz;
112
+
113
+ reportOnViolation(context, node, _objectSpread({}, options, {
114
+ maxSize: (_options$inlineMaxSiz = options.inlineMaxSize) !== null && _options$inlineMaxSiz !== void 0 ? _options$inlineMaxSiz : options.maxSize
115
+ }));
103
116
  }
104
117
  }
105
118
 
@@ -360,28 +360,18 @@ exports.TestCaseProperty = TestCaseProperty;
360
360
  TestCaseProperty["todo"] = "todo";
361
361
  })(TestCaseProperty || (exports.TestCaseProperty = TestCaseProperty = {}));
362
362
 
363
+ const joinNames = (a, b) => a && b ? `${a}.${b}` : null;
364
+
363
365
  function getNodeName(node) {
364
- function joinNames(a, b) {
365
- return a && b ? `${a}.${b}` : null;
366
+ if (isSupportedAccessor(node)) {
367
+ return getAccessorValue(node);
366
368
  }
367
369
 
368
370
  switch (node.type) {
369
- case _experimentalUtils.AST_NODE_TYPES.Identifier:
370
- return node.name;
371
-
372
- case _experimentalUtils.AST_NODE_TYPES.Literal:
373
- return `${node.value}`;
374
-
375
- case _experimentalUtils.AST_NODE_TYPES.TemplateLiteral:
376
- if (node.expressions.length === 0) return node.quasis[0].value.cooked;
377
- break;
378
-
379
371
  case _experimentalUtils.AST_NODE_TYPES.MemberExpression:
380
372
  return joinNames(getNodeName(node.object), getNodeName(node.property));
381
373
 
382
374
  case _experimentalUtils.AST_NODE_TYPES.NewExpression:
383
- return getNodeName(node.callee);
384
-
385
375
  case _experimentalUtils.AST_NODE_TYPES.CallExpression:
386
376
  return getNodeName(node.callee);
387
377
  }
@@ -397,8 +387,8 @@ const isHook = node => node.callee.type === _experimentalUtils.AST_NODE_TYPES.Id
397
387
 
398
388
  exports.isHook = isHook;
399
389
 
400
- const getTestCallExpressionsFromDeclaredVariables = declaredVaiables => {
401
- return declaredVaiables.reduce((acc, {
390
+ const getTestCallExpressionsFromDeclaredVariables = declaredVariables => {
391
+ return declaredVariables.reduce((acc, {
402
392
  references
403
393
  }) => acc.concat(references.map(({
404
394
  identifier
@@ -72,12 +72,16 @@ var _default = (0, _utils.createRule)({
72
72
  const disallowedWordsRegexp = new RegExp(`\\b(${disallowedWords.join('|')})\\b`, 'iu');
73
73
  return {
74
74
  CallExpression(node) {
75
- if (!((0, _utils.isDescribe)(node) || (0, _utils.isTestCase)(node)) || !node.arguments.length) {
75
+ if (!(0, _utils.isDescribe)(node) && !(0, _utils.isTestCase)(node)) {
76
76
  return;
77
77
  }
78
78
 
79
79
  const [argument] = (0, _utils.getJestFunctionArguments)(node);
80
80
 
81
+ if (!argument) {
82
+ return;
83
+ }
84
+
81
85
  if (!(0, _utils.isStringNode)(argument)) {
82
86
  if (argument.type === _experimentalUtils.AST_NODE_TYPES.BinaryExpression && doesBinaryExpressionContainStringNode(argument)) {
83
87
  return;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint-plugin-jest",
3
- "version": "23.7.0",
3
+ "version": "23.8.0",
4
4
  "description": "Eslint rules for Jest",
5
5
  "repository": "jest-community/eslint-plugin-jest",
6
6
  "license": "MIT",