test-runner: Incompatibility with Jest 28: `Got error running globalSetup`

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

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 7
  • Comments: 18 (9 by maintainers)

Commits related to this issue

Most upvoted comments

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.

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!

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 🥇

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.

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

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.

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?

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.

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.

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