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

Jest 27 support #665

Closed
flunderpero opened this issue Apr 3, 2021 · 9 comments · Fixed by #692
Closed

Jest 27 support #665

flunderpero opened this issue Apr 3, 2021 · 9 comments · Fixed by #692

Comments

@flunderpero
Copy link

Describe the bug
I am trying to use jest-playwright with Jest 27 and get this error:

TypeError: virtualMocks.get is not a function

      at Resolver._getVirtualMockPath (../../node_modules/jest-resolve/build/index.js:447:25)

To Reproduce
I am using a standard installation and a single simple test that just opens a browser.

Desktop (please complete the following information):

  • OS: [macOS M1]
  • Playwright version [1.10.0]
  • jest-playwright version [1.5.1]
  • jest version [27.0.0-next.7]

Jest configuration (Either in the package.json > jest or in the jest.config.js):

module.exports = {
   globals: {
       "ts-jest": {
           diagnostics: false,
           isolatedModules: true,
       },
   },
   moduleDirectories: ["<rootDir>/../../node_modules"],
   moduleFileExtensions: ["ts", "tsx", "js", "jsx", "json", "node"],
   moduleNameMapper: {
       "\\.css$": "identity-obj-proxy",
       "\\.scss$": "identity-obj-proxy",
       "^@cling/(.*)$": "<rootDir>/../$1",
   },
   reporters: ["default"],
   setupFilesAfterEnv: ["<rootDir>/../lib.shared.test/jest_setup.ts"],
   snapshotSerializers: [],
   preset: "jest-playwright-preset",
   testMatch: ["<rootDir>/__tests__/**/*.spec.ts?(x)"],
   transform: {"^.+\\.tsx?$": "ts-jest"},
}

This is a sub-project in a monorepo. But even if I use jest-playwright-preset in the main configuration it won't work.

Additional context
All's working fine with Jest 26.6.3

@mmarkelov
Copy link
Member

@flunderpero sorry for late response. I just don't have much time to look through new Jest version. I just tried to install some dependencies by myself and it helped.

// package.json
...
"dependencies": {
    "expect-playwright": "^0.3.2",
    "jest": "^27.0.0-next.7",
    "jest-playwright-preset": "1.5.1",
    "jest-runner": "^27.0.0-next.7",
    "playwright": "^1.10.0"
  }

@jakobrosenberg
Copy link

I just tried out next.9, but the below fix did unfortunately not help

        "expect-playwright": "^0.3.4",
        "jest": "^27.0.0-next.9",
        "jest-playwright-preset": "^1.5.2",
        "jest-runner": "^27.0.0-next.9",
        "playwright": "^1.10.0",

I posted the same issue on the Jest repo and got this from SimenB

I'd assume it's an issue because they pull in v26 deps:

"jest-circus": "^26.6.3",
"jest-environment-node": "^26.6.2",
"jest-process-manager": "^0.3.1",
"jest-runner": "^26.6.3",

Should probably be peer deps so users can plug in their own versions

jestjs/jest#11267 (comment)

@mmarkelov
Copy link
Member

@jakobrosenberg ok! Thanks for your comment, i'll move jest to peer dependencies

@jakobrosenberg
Copy link

jakobrosenberg commented May 11, 2021

Getting the error below on npm install, but can be fixed with the --force flag.

npm ERR! Found: jest@27.0.0-next.9
npm ERR! node_modules/jest
npm ERR!   dev jest@"^27.0.0-next.9" from the root project
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peer jest@"^26.6.3" from jest-playwright-preset@1.6.0-rc2      
npm ERR! node_modules/jest-playwright-preset
npm ERR!   dev jest-playwright-preset@"^1.6.0-rc2" from the root projectnpm ERR!
npm ERR! Fix the upstream dependency conflict, or retry
npm ERR! this command with --force, or --legacy-peer-deps
npm ERR! to accept an incorrect (and potentially broken) dependency resolution.

After install, I get this error when running tests with jest-playwright-preset.

    TypeError: Jest: a transform must export a `process` function.      

      at ScriptTransformer._getTransformer (node_modules/jest-runner/node_modules/@jest/transform/build/ScriptTransformer.js:360:13)

EDIT:
Adding "jest-runner": "^27.0.0-next.9", to package.json may have fixed it.

@thernstig
Copy link
Contributor

I just updated to Jest 27 and ran into problems. I tracked it down to jest-playwright-preset and this update seems to have fixed it. I tested in 1.6.0-rc4. See original issue on Jest: jestjs/jest#11440

I think this warrants to bump the major release of jest-playwright-preset as Jest 27 was just released. Otherwise more users upgrading will run into this problem of Jest not beeing a peer dependency in earlier releases.

@manzoorwanijk
Copy link

Still facing the same issue with:

"@testing-library/jest-dom": "^5.13.0",
"babel-jest": "^27.0.2",
"jest": "27.0.4",
"jest-circus": "27.0.4",
"jest-environment-jsdom": "27.0.3",
"jest-playwright-jsdom": "^0.0.4",
"jest-playwright-preset": "^1.6.1",
"jest-resolve": "27.0.4"

@amrsalem1
Copy link

what was the resolution of this issue?

@lourd
Copy link

lourd commented Dec 1, 2021

I just ran into this in my project that uses a monorepo. The root issue ended up being an indirect dependency on Jest v26 through react-scripts. No idea why! ¯\(ツ)/¯ I resolved the issue by specifying a resolution with yarn to the same one I was already depending on. E.g.:

...
"resolutions": {
  "react-scripts/jest": "27.2.3"
},
...

Be sure to clear out your node_modules and reinstall after doing so!

@jclaveau
Copy link

Updating to Jest 28 fixed this error in my case

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

Successfully merging a pull request may close this issue.

8 participants