Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

setupFiles can't be found when using browser-resolve Jest resolver #10547

Closed
vvanmol opened this issue Sep 23, 2020 · 6 comments
Closed

setupFiles can't be found when using browser-resolve Jest resolver #10547

vvanmol opened this issue Sep 23, 2020 · 6 comments

Comments

@vvanmol
Copy link

vvanmol commented Sep 23, 2020

🐛 Bug Report

I just upgraded all of our testing libraries to their latest version, including Jest.
Our test suite was dependant on the Jest configuration browser field which had been deprecated now.

I followed the instructions on how to reproduce the behaviour of that browser configuration field and added the following to my Jest configuration file:

"resolver": "browser-resolve"

Since then, when I run our test suite, it directly fails because Jest can't find a local setupFile defined as follow:

"setupFiles": [
    "<rootDir>/test/setup.js"
]

It fails with the following error:

Validation Error:

  Module <rootDir>/test/setup.js in the setupFiles option was not found.
         <rootDir> is: /Users/path/to/application/root

While the displayed path is actually correct and points to my setup script.

To Reproduce

Here's my full Jest configuration file which should be enough to reproduce:

{
  "collectCoverage": true,
  "collectCoverageFrom": [ "src/**/*.{js,jsx}" ],
  "coverageDirectory": "public/coverage/",
  "moduleFileExtensions": ["js", "json", "jsx", "yaml"],
  "moduleNameMapper": {
    "\\.scss$": "identity-obj-proxy"
  },
  "resolver": "browser-resolve",
  "setupFiles": [
    "<rootDir>/test/setup.js"
  ],
  "transform": {
    "\\.yaml$": "yaml-jest",
    "\\.jsx?$": "babel-jest"
  },
  "testResultsProcessor": "jest-sonar-reporter",
  "testURL": "http://localhost:8080/my-application",
  "verbose": true
}

Expected behavior

Local setup files should be resolved properly.

envinfo

  System:
    OS: macOS 10.15.6
    CPU: (8) x64 Intel(R) Core(TM) i7-7820HQ CPU @ 2.90GHz
  Binaries:
    Node: 12.18.3 - /usr/local/opt/node@12/bin/node
    npm: 6.14.6 - /usr/local/opt/node@12/bin/npm
  npmPackages:
    jest: 26.4.2 => 26.4.2 

@piranna
Copy link
Contributor

piranna commented Feb 27, 2021

Any update on this? I'm having the same bug.

@piranna
Copy link
Contributor

piranna commented Feb 27, 2021

Jest 26.6.3 with Node.js v15.10.0 on Ubuntu 20.10

@piranna
Copy link
Contributor

piranna commented Feb 27, 2021

Without the setupFiles option, this is also affecting node_modules packages:

Module /home/piranna/github/randomUUID/node_modules/jest-jasmine2/build/index.js in the testRunner option was not found.
         <rootDir> is: /home/piranna/github/randomUUID

Seems like the resolver option is plainly broken.

@piranna
Copy link
Contributor

piranna commented Mar 9, 2021

Any update on this? How can we move it forward?

@SimenB
Copy link
Member

SimenB commented Mar 9, 2021

The example was wrong, sorry. I updated it in #11140. See updated docs: https://jestjs.io/docs/configuration#resolver-string

@SimenB SimenB closed this as completed Mar 9, 2021
@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 10, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants