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

Incompatibility with Jest 28: Got error running globalSetup #99

Closed
ifahrentholz opened this issue Apr 26, 2022 · 18 comments · Fixed by #154
Closed

Incompatibility with Jest 28: Got error running globalSetup #99

ifahrentholz opened this issue Apr 26, 2022 · 18 comments · Fixed by #154
Labels
bug Something isn't working

Comments

@ifahrentholz
Copy link

ifahrentholz commented Apr 26, 2022

Describe the bug

Starting npm run test-storybook fails with an TypeError

TypeError: Jest: Got error running globalSetup - /Users/ingo.fahrentholz/Developer/delme/storybook-testing/node_modules/@storybook/test-runner/playwright/global-setup.js, reason: Class extends value #<Object> is not a constructor or null
    at Object.getPlaywrightEnv (/Users/ingo.fahrentholz/Developer/delme/storybook-testing/node_modules/jest-playwright-preset/lib/PlaywrightEnvironment.js:59:48)
    at Object.<anonymous> (/Users/ingo.fahrentholz/Developer/delme/storybook-testing/node_modules/jest-playwright-preset/lib/PlaywrightEnvironment.js:242:27)
    at Module._compile (node:internal/modules/cjs/loader:1103:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1157:10)
    at Object.newLoader (/Users/ingo.fahrentholz/Developer/delme/storybook-testing/node_modules/pirates/lib/index.js:141:7)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
    at Module.require (node:internal/modules/cjs/loader:1005:19)
    at require (node:internal/modules/cjs/helpers:102:18)
    at Object.<anonymous> (/Users/ingo.fahrentholz/Developer/delme/storybook-testing/node_modules/jest-playwright-preset/index.js:1:18)
    at Module._compile (node:internal/modules/cjs/loader:1103:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1157:10)
    at Object.newLoader (/Users/ingo.fahrentholz/Developer/delme/storybook-testing/node_modules/pirates/lib/index.js:141:7)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
    at Module.require (node:internal/modules/cjs/loader:1005:19)

Steps to reproduce the behavior

start storybook
start test-storybook

Expected behavior

test-runner should run the tests defined as play functions inside the story.

Environment

  • OS: macOS 12.3.1
  • Node.js version: 16.14.2
  • NPM version: 8.5.0

Repository

https://github.com/ifahrentholz/storybook-test-runner-bug

@ifahrentholz ifahrentholz added the bug Something isn't working label Apr 26, 2022
@ifahrentholz ifahrentholz changed the title Jest: Got error runnung globalSetup Jest: Got error running globalSetup Apr 27, 2022
@yannbf
Copy link
Member

yannbf commented Apr 27, 2022

Hey @ifahrentholz thanks for opening this issue.
The reason this is happening is because jest-playwright has a broad dependency range for some jest dependencies.
As soon as this issue is solved or this PR is merged, we will be able to solve this problem correctly.

In the meantime, I believe you can try to add package resolutions to lock these libraries to these versions:

"resolutions":  {
    "jest": "^27.5.1",
    "jest-runner": "^27.5.1",
    "jest-environment-node": "27.5.1"
}

I haven't tested that myself but I think it might work.

@ifahrentholz
Copy link
Author

ifahrentholz commented Apr 28, 2022

Hi @yannbf,
many thanks for your response. It helped me to solve the issue.
Setting the "resolutions" in my package.json did not work BUT it pointed me in the right direction.
I've set the peerDependencies instead and that fixed the issue 👍

"peerDependencies":  {
    "jest": "^27.5.1",
    "jest-runner": "^27.5.1",
    "jest-environment-node": "27.5.1"
  },

Thanks for your help 🥇

@yannbf
Copy link
Member

yannbf commented May 25, 2022

Hey everyone, sorry this is still ongoing. We need help from the jest-playwright maintainers in order to solve this.
Please add a 👍 to the following issue: playwright-community/jest-playwright#796

@yannbf yannbf changed the title Jest: Got error running globalSetup Incompatibility with Jest 28: Got error running globalSetup May 25, 2022
@yannbf yannbf pinned this issue May 25, 2022
@IanVS
Copy link
Member

IanVS commented May 25, 2022

@yannbf
Copy link
Member

yannbf commented May 26, 2022

@yannbf, a fix was just released in https://github.com/playwright-community/jest-playwright/releases/tag/v1.7.1. 🙌

Thanks! I was in contact with the maintainer. Unfortunately that's not the good long term fix, but it does help a lot already. I'll take a stab at jest 28 support in their lib at some point. They're quite busy now with other projects (e.g. component testing) so they don't have resources right now for this

@yannbf
Copy link
Member

yannbf commented May 26, 2022

FWIW I also added a warning for Jest 28 users at #111

@tetarchus
Copy link

tetarchus commented Jun 2, 2022

I've taken a look at jest-playwright and submitted a PR that hopefully allows Jest 28 to work with that library. Finger's crossed they can take a look soon and the test-runner can be updated 🤞🏼

It's awaiting the workflow runs as not contributed to them before, but I ran them on my fork and they all passed.

alixlahuec added a commit to alixlahuec/zotero-roam that referenced this issue Jul 1, 2022
* downgrade to Jest@27 due to current incompatibility with @28 (see storybookjs/test-runner#99)
@syntactic-salt
Copy link

Hey everyone, sorry this is still ongoing. We need help from the jest-playwright maintainers in order to solve this. Please add a 👍 to the following issue: playwright-community/jest-playwright#796

Looks like some good news, finally. jest-playwright released v2.0.0 today. It contains the upgrade to jest@28.

@andykenward
Copy link
Contributor

Hey everyone, sorry this is still ongoing. We need help from the jest-playwright maintainers in order to solve this. Please add a 👍 to the following issue: playwright-community/jest-playwright#796

Looks like some good news, finally. jest-playwright released v2.0.0 today. It contains the upgrade to jest@28.

jest-playwright v.2.0.0 only supports Jest 28+. Would we have to do the same for test-runner?

@syntactic-salt
Copy link

Hey everyone, sorry this is still ongoing. We need help from the jest-playwright maintainers in order to solve this. Please add a 👍 to the following issue: playwright-community/jest-playwright#796

Looks like some good news, finally. jest-playwright released v2.0.0 today. It contains the upgrade to jest@28.

jest-playwright v.2.0.0 only supports Jest 28+. Would we have to do the same for test-runner?

I don't maintain jest-playwright, but that would be my assumption. I don't see how you could support jest < 28 if you rely on jest-playwright.

@Djiit
Copy link

Djiit commented Jul 25, 2022

I guess we would have to bump a new major version. That's what semver is for, no big deal imho

@yannbf
Copy link
Member

yannbf commented Jul 25, 2022

Hey peeps, thanks to @andykenw we've got a great PR already, I'll take care of this and release a new version soon this week!

@syntactic-salt
Copy link

Hey peeps, thanks to @andykenw we've got a great PR already, I'll take care of this and release a new version soon this week!

Any plan to move forward?

@yannbf
Copy link
Member

yannbf commented Aug 6, 2022

Hey peeps! This was released and is available now in v0.6.0-next.1, would you mind giving it a try and giving some feedback? Thanks!

@ifahrentholz
Copy link
Author

Hi @yannbf,
I've tested the version you mentioned and it works fine with jest@^28.1.3

@juliaramosguedes
Copy link

I was having the same issue and trying to use resolutions os peerDependencies didn't work for me.

I'm using the latest create-react-app for my project and react-scripts 5.0.1 installs jest 27.
Installing @storybook/test-runner, i'm not able to run the tests. Same error as above.
TypeError: Jest: Got error running globalSetup
Adding versions 27 or 28 as resolutions os peerDependencies also didn't work.

Digging deep into this, we figure it out that test-runner installs jest-playwright-preset that has jest-environment-node@^28 and jest-runner@^28 as dependencies even though is not declared as such.
Because it is not declared, jest-playwright-preset uses the version 27 of this dependencies installed by react-scripts causing the bug.

My solution:
Install these packages manually.
npm i -D jest-environment-node@^28 jest-runner@^28

I'm not sure if it's the right thing to do, but it worked for me.

@yannbf
Copy link
Member

yannbf commented Jan 10, 2023

Thanks @juliaramosguedes ! The newer versions of the test-runner fixed that, can you remove the dependencies and try it out?

@kriscoleman
Copy link

Hey @yannbf

I can't speak for @juliaramosguedes but his suggestion of running npm i -D jest-environment-node@^28 jest-runner@^28 fixed the issue for me, an dI was using the latest version of test-runner.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

9 participants