Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • C create-react-app
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 1,547
    • Issues 1,547
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 417
    • Merge requests 417
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • Meta
  • create-react-app
  • Merge requests
  • !7024

Update default jest config to browser:true

  • Review changes

  • Download
  • Email patches
  • Plain diff
Closed Administrator requested to merge github/fork/bengourley/jest-browser-config into master May 09, 2019
  • Overview 3
  • Commits 2
  • Pipelines 0
  • Changes 1

Created by: bengourley

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 simply import 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 in package.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:

scratch/reaccct - [inline-script-improvement] » npm test

> reaccct@0.1.0 test /Users/bengourley/Development/bugsnag-js/packages/node/scratch/reaccct
> react-scripts test


Out of the box, Create React App only supports overriding these Jest options:

  • collectCoverageFrom
  • coverageReporters
  • coverageThreshold
  • extraGlobals
  • globalSetup
  • globalTeardown
  • resetMocks
  • resetModules
  • snapshotSerializers
  • watchPathIgnorePatterns.

These options in your package.json Jest configuration are not currently supported by Create React App:

  • browser

If you wish to override other Jest options, you need to eject from the default setup. You can do so by running npm run eject but remember that this is a one-way operation. You may also file an issue with Create React App to discuss supporting more options out of the box.

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 added browser to the list of supportedKeys, but that can be up for discussion.

Thanks for taking a look 🙂

Assignee
Assign to
Reviewers
Request review from
Time tracking
Source branch: github/fork/bengourley/jest-browser-config