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

Not working with Jest #1007

Closed
KSXGitHub opened this issue Jan 23, 2018 · 13 comments
Closed

Not working with Jest #1007

KSXGitHub opened this issue Jan 23, 2018 · 13 comments

Comments

@KSXGitHub
Copy link
Contributor

KSXGitHub commented Jan 23, 2018

pnpm version:

1.30.2

Code to reproduce the issue:

Step 1: Use pnpm

  • Clone this repo
  • Run pnpm install
  • Run pnpx jest

Step 2: Use yarn

  • Delete node_modules
  • Run yarn
  • Run yarn jest

Expected behavior:

Step 1 doesn't fail

Actual behavior:

Step 1 fails while Step 2 doesn't

TypeError: environment.setup is not a function

My speculation:

Flat node_modules doesn't fail.

Additional question:

How to force pnpm create flat node_modules?

Additional information:

  • node -v prints: v9.4.0
  • Windows, OS X, or Linux?: Arch Linux

Related issue: jestjs/jest#5369

@nickpape
Copy link

nickpape commented Jan 23, 2018

When working on our project, we noticed that jest had a couple problems correctly resolving symlinked paths. First, we had to upgrade Jest to ~21.2.1, where they weren't missing dependencies in their package.json. Then, I noticed an issue with jest-resolve not properly resolving symlinks, so I created a PR for them, but don't yet have a CLA to fix the issue. We ended up doing a patch in our tools instead. You might be experiencing similar issues. First, I would definitely advice upgrading Jest, if possible.

jestjs/jest#5085
microsoft/rushstack#466

@KSXGitHub
Copy link
Contributor Author

I just discovered a workaround for this yesterday: Replace jest with jest-cli. It worked.

This is the repo that I worked on.

@KSXGitHub
Copy link
Contributor Author

KSXGitHub commented Jan 24, 2018

I just discovered that the jest will fail if --preserve-symlinks flag is provided

Create a jest.js:

require('jest-cli/bin/jest')

✓ If I execute node jest.js, it works.

✕ If I execute node --preserve-symlink jest.js, it doesn't work.

✕ If I execute pnpm test with node jest.js being test script, it doesn't work. (No idea why)

✕ If I execute pnpx jest, it doesn't throw an irrelevant error message if I add a test to fail (e.g. expect(0).toBe(1)), but it passes if all tests pass.

@zkochan
Copy link
Member

zkochan commented Jan 24, 2018

A node_modules created by pnpm won't work with Node ran with --preserve-symlinks (https://github.com/pnpm/pnpm#limitations). It is a limitation of pnpm because we use symlinks. Though this flag will most probably be deprecated

@KSXGitHub
Copy link
Contributor Author

@zkochan I have no intention of using --preserve-symlinks either, the point that I wanna make here is that pnpm test and pnpx test still fails while node jest.js works.

@dandv
Copy link
Contributor

dandv commented Feb 19, 2018

Jest doesn't work for me either, but the error is SyntaxError: Unexpected token import on the line that imports my module (import { MyModule } from '..'). If I run npm install; npm run test instead of pnpm install; pnpm run test, Jest works. I'm using the latest Jest, 22.3.0.

@KSXGitHub's workaround didn't work (same error). My .babelrc is { "plugins": ["transform-es2015-modules-commonjs"] } because Jest doesn't support native ES6 modules.

@wmertens
Copy link

wmertens commented Mar 29, 2018

for me the error is Cannot find module 'jest-environment-jsdom' - v22.4.3.

The module is installed as part of the jest-cli deps, but not found by jest, presumably because it does weird things with require.

@wmertens
Copy link

It does work when doing --shamefully-flatten, which is good news I suppose, but of course Jest should be fixed to work with hierarchical modules.

@wmertens
Copy link

wmertens commented Nov 8, 2018

Jest works now, v23.6.0

@zkochan
Copy link
Member

zkochan commented Nov 8, 2018

Cool!

@zkochan zkochan closed this as completed Nov 8, 2018
@KSXGitHub
Copy link
Contributor Author

@wmertens It works even without --shamefully-flatten?

@wmertens
Copy link

wmertens commented Nov 8, 2018

@KSXGitHub Yes! And if you want to use Babel 7 you need to override the dependencies as I explain in #1475

@mudlabs
Copy link

mudlabs commented Nov 18, 2018

@wmertens I still get error with v23.6.0

Cannot find module 'jest-environment-jsdom'
at node_modules/.registry.npmjs.org/jest-runner/23.6.0/node_modules/jest-runner/build/run_test.js:39:29

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants