eslint-plugin-jest
Advanced tools
Comparing version 23.19.0 to 23.20.0
@@ -0,1 +1,8 @@ | ||
# [23.20.0](https://github.com/jest-community/eslint-plugin-jest/compare/v23.19.0...v23.20.0) (2020-07-30) | ||
### Features | ||
* **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)) | ||
# [23.19.0](https://github.com/jest-community/eslint-plugin-jest/compare/v23.18.2...v23.19.0) (2020-07-27) | ||
@@ -2,0 +9,0 @@ |
@@ -125,4 +125,4 @@ # disallow large snapshots (`no-large-snapshots`) | ||
Since `eslint-disable` comments are not preserved by Jest when updating | ||
snapshots, you can use the `whitelistedSnapshots` option to have specific | ||
snapshots allowed regardless of their size. | ||
snapshots, you can use the `allowedSnapshots` option to have specific snapshots | ||
allowed regardless of their size. | ||
@@ -145,3 +145,3 @@ This option takes a map, with the key being the absolute filepath to a snapshot | ||
{ | ||
whitelistedSnapshots: { | ||
allowedSnapshots: { | ||
'/path/to/file.js.snap': ['snapshot name 1', /a big snapshot \d+/], | ||
@@ -166,3 +166,3 @@ }, | ||
{ | ||
whitelistedSnapshots: { | ||
allowedSnapshots: { | ||
[path.resolve('test/__snapshots__/get.js.snap')]: ['full request'], | ||
@@ -169,0 +169,0 @@ [path.resolve('test/__snapshots__/put.js.snap')]: ['full request'], |
@@ -22,3 +22,4 @@ "use strict"; | ||
maxSize: lineLimit = 50, | ||
whitelistedSnapshots = {} | ||
whitelistedSnapshots = {}, | ||
allowedSnapshots = whitelistedSnapshots | ||
}) => { | ||
@@ -28,17 +29,17 @@ const startLine = node.loc.start.line; | ||
const lineCount = endLine - startLine; | ||
const allPathsAreAbsolute = Object.keys(whitelistedSnapshots).every(_path.isAbsolute); | ||
const allPathsAreAbsolute = Object.keys(allowedSnapshots).every(_path.isAbsolute); | ||
if (!allPathsAreAbsolute) { | ||
throw new Error('All paths for whitelistedSnapshots must be absolute. You can use JS config and `path.resolve`'); | ||
throw new Error('All paths for allowedSnapshots must be absolute. You can use JS config and `path.resolve`'); | ||
} | ||
let isWhitelisted = false; | ||
let isAllowed = false; | ||
if (node.type === _experimentalUtils.AST_NODE_TYPES.ExpressionStatement && 'left' in node.expression && (0, _utils.isExpectMember)(node.expression.left)) { | ||
const fileName = context.getFilename(); | ||
const whitelistedSnapshotsInFile = whitelistedSnapshots[fileName]; | ||
const allowedSnapshotsInFile = allowedSnapshots[fileName]; | ||
if (whitelistedSnapshotsInFile) { | ||
if (allowedSnapshotsInFile) { | ||
const snapshotName = (0, _utils.getAccessorValue)(node.expression.left.property); | ||
isWhitelisted = whitelistedSnapshotsInFile.some(name => { | ||
isAllowed = allowedSnapshotsInFile.some(name => { | ||
if (name instanceof RegExp) { | ||
@@ -53,3 +54,3 @@ return name.test(snapshotName); | ||
if (!isWhitelisted && lineCount > lineLimit) { | ||
if (!isAllowed && lineCount > lineLimit) { | ||
context.report({ | ||
@@ -88,2 +89,8 @@ messageId: lineLimit === 0 ? 'noSnapshot' : 'tooLongSnapshots', | ||
}, | ||
allowedSnapshots: { | ||
type: 'object', | ||
additionalProperties: { | ||
type: 'array' | ||
} | ||
}, | ||
whitelistedSnapshots: { | ||
@@ -104,2 +111,6 @@ type: 'object', | ||
create(context, [options]) { | ||
if ('whitelistedSnapshots' in options) { | ||
console.warn('jest/no-large-snapshots: the "whitelistedSnapshots" option has been renamed to "allowedSnapshots"'); | ||
} | ||
if (context.getFilename().endsWith('.snap')) { | ||
@@ -106,0 +117,0 @@ return { |
{ | ||
"name": "eslint-plugin-jest", | ||
"version": "23.19.0", | ||
"version": "23.20.0", | ||
"description": "Eslint rules for Jest", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
235059
3928