Skip to content

Commit

Permalink
docs: use inclusive language
Browse files Browse the repository at this point in the history
  • Loading branch information
G-Rath committed Jul 26, 2020
1 parent f5585ea commit c1edf8a
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 50 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ Then configure the rules you want to use under the rules section.
}
```

You can also whitelist the environment variables provided by Jest by doing:
You can also tell ESLint about the environment variables provided by Jest by
doing:

```json
{
Expand Down
6 changes: 3 additions & 3 deletions docs/rules/expect-expect.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ it('should work with callbacks/async', () => {

### `assertFunctionNames`

This array option whitelists the assertion function names to look for. Function
names can use wildcards like `request.*.expect`, `request.**.expect`,
`request.*.expect*`
This array option specifies the names of functions that should be considered to
be asserting functions. Function names can use wildcards i.e `request.*.expect`,
`request.**.expect`, `request.*.expect*`

Examples of **incorrect** code for the `{ "assertFunctionNames": ["expect"] }`
option:
Expand Down
10 changes: 5 additions & 5 deletions docs/rules/lowercase-name.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ it('adds 1 + 2 to equal 3', () => {

### `ignore`

This array option whitelists function names so that this rule does not report
their usage as being incorrect. There are three possible values:
This array option controls which Jest functions are checked by this rule. There
are three possible values:

- `"describe"`
- `"test"`
Expand Down Expand Up @@ -73,9 +73,9 @@ it('Uppercase description');

### `allowedPrefixes`

This array option whitelists prefixes that titles can start with with capitals.
This can be useful when writing tests for api endpoints, where you'd like to
prefix with the HTTP method.
This array option allows specifying prefixes which contain capitals that titles
can start with. This can be useful when writing tests for api endpoints, where
you'd like to prefix with the HTTP method.

By default, nothing is allowed (the equivalent of `{ "allowedPrefixes": [] }`).

Expand Down
4 changes: 2 additions & 2 deletions docs/rules/no-hooks.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@ describe('foo', () => {

### `allow`

This array option whitelists setup and teardown hooks so that this rule does not
report their usage as being incorrect. There are four possible values:
This array option controls which Jest hooks are checked by this rule. There are
four possible values:

- `"beforeAll"`
- `"beforeEach"`
Expand Down
84 changes: 45 additions & 39 deletions docs/rules/no-large-snapshots.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# disallow large snapshots (`no-large-snapshots`)

When using Jest's snapshot capability one should be mindful of the size of
created snapshots. As a best practice snapshots should be limited in size in
order to be more manageable and reviewable. A stored snapshot is only as good as
its review and as such keeping it short, sweet, and readable is important to
allow for thorough reviews.
created snapshots. As a general best practice snapshots should be limited in
size in order to be more manageable and reviewable. A stored snapshot is only as
good as its review and as such keeping it short, sweet, and readable is
important to allow for thorough reviews.

## Usage

Expand All @@ -15,9 +15,11 @@ you should set `parserOptions` in your config to at least allow ES2015 in order
to use this rule:

```js
parserOptions: {
ecmaVersion: 2015,
},
module.exports = {
parserOptions: {
ecmaVersion: 2015,
},
};
```

## Rule Details
Expand Down Expand Up @@ -119,48 +121,52 @@ size and `maxSize` for
If only `maxSize` is provided on options, the value of `maxSize` will be used to
both snapshot types (Inline and External).

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.
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.

This option takes a map, with the key being the absolute filepath to a snapshot
file, and the value an array of values made up of strings and regular
expressions to compare to the names of the snapshots in the `.snap` file when
checking if the snapshots size should be allowed.

Note that regular expressions can only be passed in via `.eslintrc.js` as
instances of `RegExp`.

In an `.eslintrc.js` file:

```javascript
...

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

...
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:
Since absolute paths are typically not very portable, you can use the builtin
`path.resolve` function to expand relative paths into absolutes like so:

```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));

...
module.exports = {
rules: {
"jest/no-large-snapshots": ["error",
{ whitelistedSnapshots }
]
}
'jest/no-large-snapshots': [
'error',
{
whitelistedSnapshots: {
[path.resolve('test/__snapshots__/get.js.snap')]: ['full request'],
[path.resolve('test/__snapshots__/put.js.snap')]: ['full request'],
},
},
],
},
};
```

0 comments on commit c1edf8a

Please sign in to comment.