Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 47 additions & 1 deletion docs/rules/no-large-snapshots.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ line 4

## Options

This rule has option for modifying the max number of lines allowed for a
This rule has an option for modifying the max number of lines allowed for a
snapshot:

In an `eslintrc` file:
Expand All @@ -110,3 +110,49 @@ In an `eslintrc` file:
}
...
```

In addition there is an option for whitelisting large snapshot files. Since
`//eslint` comments will be removed when a `.snap` file is updated, this option
provides a way of whitelisting large snapshots. The list of whitelistedSnapshots
is keyed first on the absolute filepath of the snapshot file. You can then
provide an array of strings to match the snapshot names against. If you're using
a `.eslintrc.js` file, you can use regular expressions AND strings.

In an `.eslintrc.js` file:

```javascript
...

"rules": {
"jest/no-large-snapshots": ["error",
{
"whitelistedSnapshots": {
"/path/to/file.js.snap": ["snapshot name 1", /a big snapshot \d+/]
}
}]
}

...
```

Note: If you store your paths as relative paths, you can use `path.resolve` so
that it can be shared between computers. For example, suppose you have your
whitelisted snapshots in a file called `allowed-snaps.js` which stores them as
relative paths. To convert them to absolute paths you can do something like the
following:

```javascript
const path = require('path');
const {mapKeys} = require('lodash');


const allowedSnapshots = require('./allowed-snaps.js');
const whitelistedSnapshots = mapKeys(allowedSnapshots, (val, file) => path.resolve(__dirname, file));

...
rules: {
"jest/no-large-snapshots": ["error",
{ whitelistedSnapshots }
]
}
```
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"@babel/preset-env": "^7.4.4",
"@commitlint/cli": "^6.0.0",
"@commitlint/config-conventional": "^6.0.0",
"babel-eslint": "^10.0.2",
"babel-jest": "^24.8.0",
"eslint": "^5.1.0",
"eslint-config-prettier": "^5.1.0",
Expand Down
Loading