Skip to content

Commit

Permalink
Attempt to explain new resolver option
Browse files Browse the repository at this point in the history
  • Loading branch information
IanVS committed Aug 31, 2021
1 parent 2203a7f commit f7dd81b
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions docs/Configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -783,12 +783,18 @@ By default, each test file gets its own independent module registry. Enabling `r

Default: `undefined`

This option allows the use of a custom resolver. This resolver must be a node module that exports a function expecting a string as the first argument for the path to resolve and an object with the following structure as the second argument:
This option allows the use of a custom resolver. This resolver must be a node module that exports _either_:

1. a function expecting a string as the first argument for the path to resolve and an options object as the second argument. The function should either return a path to the module that should be resolved or throw an error if the module can't be found. _or_
2. an object containing `async` and/or `sync` properties. The `sync` property should be a function with the shape explained above, and the `async` property should also be a function that accepts the same arguments, but returns a promise which resolves with the path to the module or rejects with an error.

The options object provided to resolvers has the shape:

```json
{
"basedir": string,
"defaultResolver": "function(request, options)",
"defaultResolver": "function(request, options) -> string",
"defaultResolverAsync": "function(request, options) -> Promise<string>",
"extensions": [string],
"moduleDirectory": [string],
"paths": [string],
Expand All @@ -797,8 +803,6 @@ This option allows the use of a custom resolver. This resolver must be a node mo
}
```

The function should either return a path to the module that should be resolved or throw an error if the module can't be found.

Note: the defaultResolver passed as an option is the Jest default resolver which might be useful when you write your custom one. It takes the same arguments as your custom one, e.g. `(request, options)`.

For example, if you want to respect Browserify's [`"browser"` field](https://github.com/browserify/browserify-handbook/blob/master/readme.markdown#browser-field), you can use the following configuration:
Expand Down

0 comments on commit f7dd81b

Please sign in to comment.