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

No jest tests are working @#cra #2211

Closed
fix-me opened this issue Dec 13, 2019 · 5 comments
Closed

No jest tests are working @#cra #2211

fix-me opened this issue Dec 13, 2019 · 5 comments

Comments

@fix-me
Copy link

fix-me commented Dec 13, 2019

Having the latest versions installed, npm install + npm test work perfectly on create-react-app consuming a create-react-library from artifactory,
unfortunately pnpm does not!

Here is what comes using pnpm (no problems with npm here):

import { computed, decorate, observable } from "mobx";
           ^

    SyntaxError: Unexpected token {

 [..................]

  ● Test suite failed to run

    Jest encountered an unexpected token

    This usually means that you are trying to import a file which Jest cannot parse, e.g. it's not plain JavaScript.

    By default, if Jest sees a Babel config, it will use that to transform your files, ignoring "node_modules".

    Here's what you can do:
     • To have some of your "node_modules" files transformed, you can specify a custom "transformIgnorePatterns" in your config.
     • If you need a custom transformation specify a "transform" option in your config.
     • If you simply want to mock your non-JS modules (e.g. binary assets) you can stub them out with the "moduleNameMapper" config option.

    You'll find more details and examples of these config options in the docs:
    https://jestjs.io/docs/en/configuration.html

It seems that some babel transformers do not work or behave different than with npm.

<()nmts<

@zkochan zkochan changed the title ⚠️ Warning! No jest tests are working @#cra, switching back to npm No jest tests are working @#cra Dec 13, 2019
@jofravelo
Copy link

jofravelo commented Nov 4, 2020

I have the same problem, but in my case it's linked to the paths added in transformIgnorePatterns, in jest.config.js, that are not rightly resolved. It stopped working after starting to use pnpm with no change on either code or config.

I suspect it's due to the fact that pnpm uses "symbolic links" in node_modules and then folders are not "physically" there. Apparently, that's a problem for Jest (or Babel?) when resolving paths.

@jofravelo
Copy link

jofravelo commented Nov 4, 2020

At the end solved the issue using this solution: jestjs/jest#2081 (comment)

It turns out it's rather linked to the folder structure. Even when I used --shamefully-hoist when installing dependencies, apparently it's not flat enough for some :)

@fireairforce
Copy link
Member

I meet the same question... but my regex seems not work..

@juanpicado
Copy link
Member

🤔 ... how are you exactly installing CRA with pnpm? I'd like to reproduce it.

@zkochan
Copy link
Member

zkochan commented May 8, 2022

If it is still an issue, use the node-linker=hoisted setting.

@zkochan zkochan closed this as completed May 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants