From f7dd81bbc49702f2e823c66e2dfdb70beb328419 Mon Sep 17 00:00:00 2001 From: Ian VanSchooten Date: Mon, 30 Aug 2021 23:14:59 -0400 Subject: [PATCH] Attempt to explain new resolver option --- docs/Configuration.md | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/docs/Configuration.md b/docs/Configuration.md index 58c1d6133852..3368054a97ae 100644 --- a/docs/Configuration.md +++ b/docs/Configuration.md @@ -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", "extensions": [string], "moduleDirectory": [string], "paths": [string], @@ -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: