eslint-plugin-jest 23.19.0 → 23.20.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,10 @@
1
+ # [23.20.0](https://github.com/jest-community/eslint-plugin-jest/compare/v23.19.0...v23.20.0) (2020-07-30)
2
+
3
+
4
+ ### Features
5
+
6
+ * **no-large-snapshots:** deprecate `whitelistedSnapshots` for new name ([#632](https://github.com/jest-community/eslint-plugin-jest/issues/632)) ([706f5c2](https://github.com/jest-community/eslint-plugin-jest/commit/706f5c2bc54797f0f32178fab1d194d9a4309f70))
7
+
1
8
  # [23.19.0](https://github.com/jest-community/eslint-plugin-jest/compare/v23.18.2...v23.19.0) (2020-07-27)
2
9
 
3
10
 
@@ -122,8 +122,8 @@ If only `maxSize` is provided on options, the value of `maxSize` will be used to
122
122
  both snapshot types (Inline and External).
123
123
 
124
124
  Since `eslint-disable` comments are not preserved by Jest when updating
125
- snapshots, you can use the `whitelistedSnapshots` option to have specific
126
- snapshots allowed regardless of their size.
125
+ snapshots, you can use the `allowedSnapshots` option to have specific snapshots
126
+ allowed regardless of their size.
127
127
 
128
128
  This option takes a map, with the key being the absolute filepath to a snapshot
129
129
  file, and the value an array of values made up of strings and regular
@@ -141,7 +141,7 @@ module.exports = {
141
141
  'jest/no-large-snapshots': [
142
142
  'error',
143
143
  {
144
- whitelistedSnapshots: {
144
+ allowedSnapshots: {
145
145
  '/path/to/file.js.snap': ['snapshot name 1', /a big snapshot \d+/],
146
146
  },
147
147
  },
@@ -161,7 +161,7 @@ module.exports = {
161
161
  'jest/no-large-snapshots': [
162
162
  'error',
163
163
  {
164
- whitelistedSnapshots: {
164
+ allowedSnapshots: {
165
165
  [path.resolve('test/__snapshots__/get.js.snap')]: ['full request'],
166
166
  [path.resolve('test/__snapshots__/put.js.snap')]: ['full request'],
167
167
  },
@@ -19,26 +19,27 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.definePrope
19
19
 
20
20
  const reportOnViolation = (context, node, {
21
21
  maxSize: lineLimit = 50,
22
- whitelistedSnapshots = {}
22
+ whitelistedSnapshots = {},
23
+ allowedSnapshots = whitelistedSnapshots
23
24
  }) => {
24
25
  const startLine = node.loc.start.line;
25
26
  const endLine = node.loc.end.line;
26
27
  const lineCount = endLine - startLine;
27
- const allPathsAreAbsolute = Object.keys(whitelistedSnapshots).every(_path.isAbsolute);
28
+ const allPathsAreAbsolute = Object.keys(allowedSnapshots).every(_path.isAbsolute);
28
29
 
29
30
  if (!allPathsAreAbsolute) {
30
- throw new Error('All paths for whitelistedSnapshots must be absolute. You can use JS config and `path.resolve`');
31
+ throw new Error('All paths for allowedSnapshots must be absolute. You can use JS config and `path.resolve`');
31
32
  }
32
33
 
33
- let isWhitelisted = false;
34
+ let isAllowed = false;
34
35
 
35
36
  if (node.type === _experimentalUtils.AST_NODE_TYPES.ExpressionStatement && 'left' in node.expression && (0, _utils.isExpectMember)(node.expression.left)) {
36
37
  const fileName = context.getFilename();
37
- const whitelistedSnapshotsInFile = whitelistedSnapshots[fileName];
38
+ const allowedSnapshotsInFile = allowedSnapshots[fileName];
38
39
 
39
- if (whitelistedSnapshotsInFile) {
40
+ if (allowedSnapshotsInFile) {
40
41
  const snapshotName = (0, _utils.getAccessorValue)(node.expression.left.property);
41
- isWhitelisted = whitelistedSnapshotsInFile.some(name => {
42
+ isAllowed = allowedSnapshotsInFile.some(name => {
42
43
  if (name instanceof RegExp) {
43
44
  return name.test(snapshotName);
44
45
  }
@@ -48,7 +49,7 @@ const reportOnViolation = (context, node, {
48
49
  }
49
50
  }
50
51
 
51
- if (!isWhitelisted && lineCount > lineLimit) {
52
+ if (!isAllowed && lineCount > lineLimit) {
52
53
  context.report({
53
54
  messageId: lineLimit === 0 ? 'noSnapshot' : 'tooLongSnapshots',
54
55
  data: {
@@ -82,6 +83,12 @@ var _default = (0, _utils.createRule)({
82
83
  inlineMaxSize: {
83
84
  type: 'number'
84
85
  },
86
+ allowedSnapshots: {
87
+ type: 'object',
88
+ additionalProperties: {
89
+ type: 'array'
90
+ }
91
+ },
85
92
  whitelistedSnapshots: {
86
93
  type: 'object',
87
94
  patternProperties: {
@@ -97,6 +104,10 @@ var _default = (0, _utils.createRule)({
97
104
  defaultOptions: [{}],
98
105
 
99
106
  create(context, [options]) {
107
+ if ('whitelistedSnapshots' in options) {
108
+ console.warn('jest/no-large-snapshots: the "whitelistedSnapshots" option has been renamed to "allowedSnapshots"');
109
+ }
110
+
100
111
  if (context.getFilename().endsWith('.snap')) {
101
112
  return {
102
113
  ExpressionStatement(node) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint-plugin-jest",
3
- "version": "23.19.0",
3
+ "version": "23.20.0",
4
4
  "description": "Eslint rules for Jest",
5
5
  "keywords": [
6
6
  "eslint",