Update default jest config to browser:true #7024
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hi! I work at Bugsnag maintaining the notifier for JavaScript
@bugsnag/js
. Some of our users have reported issues when using Bugsnag in Jest tests.We use the
package.json#browser
field to provide the correct Node or Browser module based on the environment so that "universal" JS can simplyimport bugsnag from '@bugsnag/js'
and get the right one.For some reason, even though the default Jest test environment is jsdom (not Node) the default behaviour is to ignore the
browser
field inpackage.json
and load the Node version of a module.In the issue, I've advised people to set
browser: true
in their Jest config, but when you do this on a create-react-app it fails with the following error:Ideally, I would like to get Jest to change the default config to be
browser: true
– since after all the default environment is a browser-like environment. However, users are able to correct this config themselves. My justification for this change to create-react-app is that users are not allowed to override the config at all, and so can't get the tests to load the correct version of our module.Since I'm setting this to something other than the default, and
jestEnvironment
is also configurable, I've addedbrowser
to the list ofsupportedKeys
, but that can be up for discussion.Thanks for taking a look 🙂