98
98
99
99
## Options
100
100
101
- This rule has option for modifying the max number of lines allowed for a
101
+ This rule has an option for modifying the max number of lines allowed for a
102
102
snapshot:
103
103
104
104
In an ` eslintrc ` file:
@@ -110,3 +110,49 @@ In an `eslintrc` file:
110
110
}
111
111
...
112
112
```
113
+
114
+ In addition there is an option for whitelisting large snapshot files. Since
115
+ ` //eslint ` comments will be removed when a ` .snap ` file is updated, this option
116
+ provides a way of whitelisting large snapshots. The list of whitelistedSnapshots
117
+ is keyed first on the absolute filepath of the snapshot file. You can then
118
+ provide an array of strings to match the snapshot names against. If you're using
119
+ a ` .eslintrc.js ` file, you can use regular expressions AND strings.
120
+
121
+ In an ` .eslintrc.js ` file:
122
+
123
+ ``` javascript
124
+ ...
125
+
126
+ " rules" : {
127
+ " jest/no-large-snapshots" : [" error" ,
128
+ {
129
+ " whitelistedSnapshots" : {
130
+ " /path/to/file.js.snap" : [" snapshot name 1" , / a big snapshot \d + / ]
131
+ }
132
+ }]
133
+ }
134
+
135
+ ...
136
+ ```
137
+
138
+ Note: If you store your paths as relative paths, you can use ` path.resolve ` so
139
+ that it can be shared between computers. For example, suppose you have your
140
+ whitelisted snapshots in a file called ` allowed-snaps.js ` which stores them as
141
+ relative paths. To convert them to absolute paths you can do something like the
142
+ following:
143
+
144
+ ``` javascript
145
+ const path = require (' path' );
146
+ const {mapKeys } = require (' lodash' );
147
+
148
+
149
+ const allowedSnapshots = require (' ./allowed-snaps.js' );
150
+ const whitelistedSnapshots = mapKeys (allowedSnapshots, (val , file ) => path .resolve (__dirname , file));
151
+
152
+ ...
153
+ rules: {
154
+ " jest/no-large-snapshots" : [" error" ,
155
+ { whitelistedSnapshots }
156
+ ]
157
+ }
158
+ ```
0 commit comments