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

Unable to run jest after 26 to 27 version bump with Yarn 3's PnP #11452

Closed
wegry opened this issue May 26, 2021 · 10 comments · Fixed by #11465 or #11493
Closed

Unable to run jest after 26 to 27 version bump with Yarn 3's PnP #11452

wegry opened this issue May 26, 2021 · 10 comments · Fixed by #11465 or #11493
Labels

Comments

@wegry
Copy link

wegry commented May 26, 2021

🐛 Bug Report

After adding

packageExtensions:
  jest-util@*:
    dependencies:
      jest-runner: '*'

to my .yarnrc.yml, now it looks like jest-circus is blowing up when trying to access slash in node_modules.

    Cannot find module 'slash' from '[project-absolute-path]/.yarn/cache/jest-circus-npm-27.0.1-012c78744a-aa949ec0ff.zip/node_modules/jest-circus/build'

    Require stack:
      .yarn/cache/jest-circus-npm-27.0.1-012c78744a-aa949ec0ff.zip/node_modules/jest-circus/build/utils.js
      .yarn/cache/jest-circus-npm-27.0.1-012c78744a-aa949ec0ff.zip/node_modules/jest-circus/build/eventHandler.js
      .yarn/cache/jest-circus-npm-27.0.1-012c78744a-aa949ec0ff.zip/node_modules/jest-circus/build/state.js
      .yarn/cache/jest-circus-npm-27.0.1-012c78744a-aa949ec0ff.zip/node_modules/jest-circus/build/index.js
      .yarn/cache/jest-circus-npm-27.0.1-012c78744a-aa949ec0ff.zip/node_modules/jest-circus/build/legacy-code-todo-rewrite/jestAdapterInit.js

To Reproduce

Steps to reproduce the behavior:

  1. Patch up packageExtenions missing (according to Yarn 3, at least) dependency between jest-util and jest-runner
  2. Run Jest 27.0.1 with PnP dependencies.

Expected behavior

jest-circus should be able to resolve its dependencies successfully with Yarn 3's PnP.

Link to repl or repo (highly encouraged)

envinfo

  System:
    OS: macOS 11.2.3
    CPU: (12) x64 Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz
    Memory: 638.26 MB / 16.00 GB
    Shell: 5.8 - /bin/zsh
  Binaries:
    Node: 14.17.0 - ~/.nvm/versions/node/v14.17.0/bin/node
    Yarn: 3.0.0-rc.2 - ~/.nvm/versions/node/v14.17.0/bin/yarn
    npm: 6.14.13 - ~/.nvm/versions/node/v14.17.0/bin/npm
  Managers:
    Homebrew: 3.0.1 - /usr/local/bin/brew
    pip3: 20.0.2 - /usr/local/bin/pip3
    RubyGems: 3.0.3 - /usr/bin/gem
  Utilities:
    Make: 3.81 - /usr/bin/make
    GCC: 4.2.1 - /usr/bin/gcc
    Git: 2.28.0 - /usr/local/bin/git
    Clang: 11.0.3 - /usr/bin/clang
    Mercurial: 5.4.2 - /usr/local/bin/hg
  Servers:
    Apache: 2.4.46 - /usr/sbin/apachectl
  Virtualization:
    Docker: 20.10.6 - /usr/local/bin/docker
    VirtualBox: 6.1.12 - /usr/local/bin/vboxmanage
  IDEs:
    Nano: 2.0.6 - /usr/bin/nano
    Sublime Text: 3211 - /usr/local/bin/subl
    VSCode: 1.56.2 - /usr/local/bin/code
    Vim: 8.2 - /usr/bin/vim
    Xcode: /undefined - /usr/bin/xcodebuild
  Languages:
    Bash: 3.2.57 - /bin/bash
    Go: 1.15.12 - /usr/local/go/bin/go
    Perl: 5.28.2 - /usr/bin/perl
    PHP: 7.3.24 - /usr/bin/php
    Python: 2.7.16 - /usr/bin/python
    Python3: 3.8.3 - /usr/local/bin/python3
    Ruby: 2.6.3 - /usr/bin/ruby
  Databases:
    SQLite: 3.32.3 - /usr/bin/sqlite3
  Browsers:
    Chrome: 90.0.4430.212
    Firefox Developer Edition: 89.0
    Safari: 14.0.3
@IvanRodriCalleja
Copy link

IvanRodriCalleja commented May 27, 2021

Maybe this can help you:

packageExtensions:
  jest-util@*:
    dependencies:
      jest-runner: '*'
  jest-circus@*:
    dependencies:
      slash: '*'

But it creates a different problem

 ({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,jest){export default function slash(path) {
                                                                                      ^^^^^^

    SyntaxError: Unexpected token 'export'

@SimenB
Copy link
Member

SimenB commented May 27, 2021

You'll need to force it to be slash@3, as v4 uses ESM. However, that's clearly a bug, so I'll add the missing dependency 🙂

The jest-util one sounds weird though, there is no instance of jest-runner in jest-util. I assume it's because we don't resolve it properly or something, I'll dig into it 👍

@IvanRodriCalleja
Copy link

@SimenB Thanks for the quick response and fix!!

@SimenB
Copy link
Member

SimenB commented May 29, 2021

Please give 27.0.2 a try

@IvanRodriCalleja
Copy link

I checked and the problem related to dependencies is fixed.

But now i am getting a different error but i am not sure if i have something wrong in the configuration (with versions 26.* i didn't have to configure nothing)

● Validation Error:

  Test environment jsdom cannot be found. Make sure the testEnvironment configuration option points to an existing node module.

  Configuration Documentation:
  https://jestjs.io/docs/configuration

Here is my jest.config.js

module.exports = {
	moduleFileExtensions: ['js', 'ts', 'tsx'],
	roots: ['<rootDir>/tests'],
	testMatch: ['**/__tests__/**/*.+(ts|tsx|js)', '**/?(*.)+(spec|test).+(ts|tsx|js)'],
	testEnvironment: 'jsdom',
	transform: {
		'^.+\\.tsx?$': [
			'esbuild-jest',
			{
				sourcemap: true,
				loaders: {
					'.spec.ts': 'tsx'
				}
			}
		]
	}
};

Am i doing something wrong? do i have to add something to testEnvironmentOptions? Is it related to jest or jsdom?

With pnp there isn't node_modules, i don't know where to point it.

@SimenB
Copy link
Member

SimenB commented May 31, 2021

Ah no, that's a regression, I'll fix it.

(to work around it, you can install jest-environment-jsdom yourself, and do require.resolve('jest-environment-jsdom') in the config)

@SimenB
Copy link
Member

SimenB commented Jun 3, 2021

https://github.com/facebook/jest/releases/tag/v27.0.4 🙏

@IvanRodriCalleja
Copy link

Version 27.0.4 is working for me with pnp

image

@SimenB
Copy link
Member

SimenB commented Jun 3, 2021

wonderful, thanks!

@github-actions
Copy link

github-actions bot commented Jul 4, 2021

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 Jul 4, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
3 participants