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

Yarn 2 with PNP mode cannot resolve jest-puppeteer preset correctly #319

Closed
kirill-konshin opened this issue Feb 15, 2020 · 6 comments ยท Fixed by #335
Closed

Yarn 2 with PNP mode cannot resolve jest-puppeteer preset correctly #319

kirill-konshin opened this issue Feb 15, 2020 · 6 comments ยท Fixed by #335

Comments

@kirill-konshin
Copy link

๐Ÿ› Bug Report

โ— Validation Error:

  Preset jest-puppeteer is invalid:

  The "id" argument must be of type string. Received type object
  TypeError [ERR_INVALID_ARG_TYPE]: The "id" argument must be of type string. Received type object
    at validateString (internal/validators.js:112:11)
    at Module.require (internal/modules/cjs/loader.js:841:3)
    at require (internal/modules/cjs/helpers.js:74:18)
    at setupPreset (/x/.yarn/cache/jest-config-npm-25.1.0-d4275d52c2-2.zip/node_modules/jest-config/build/normalize.js:298:14)
    at normalize (/x/.yarn/cache/jest-config-npm-25.1.0-d4275d52c2-2.zip/node_modules/jest-config/build/normalize.js:643:15)
    at readConfig (/x/.yarn/cache/jest-config-npm-25.1.0-d4275d52c2-2.zip/node_modules/jest-config/build/index.js:220:68)
    at async readConfigs (/x/.yarn/cache/jest-config-npm-25.1.0-d4275d52c2-2.zip/node_modules/jest-config/build/index.js:401:26)
    at async runCLI (/x/.yarn/cache/@jest-core-npm-25.1.0-8e811ad5a3-2.zip/node_modules/@jest/core/build/cli/index.js:203:59)
    at async Object.run (/x/.yarn/cache/jest-cli-npm-25.1.0-6214862080-2.zip/node_modules/jest-cli/build/cli/index.js:216:37)

The problem is I have config in LIB repo and acutal tests in another APP repo, so I have to resolve preset from the LIB repo. But I can't just write require.resolve('jest-puppeteer') because there are no js files, only json config.

I tried to put it like this:

exports.preset = require('path').dirname(require.resolve('jest-puppeteer/jest-preset.json'));

It works but it produces next error:

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

Because jest-environment-puppeteer should be resolved from jest-puppeteer.

I suggest to make config a regular js file instead of json and return resolved paths instead of just package identifiers.

Workaround

Manually install jest-environment-puppeteer and expect-puppeteer and put following in config:

exports.globalSetup = require.resolve('jest-environment-puppeteer/setup');
exports.globalTeardown = require.resolve('jest-environment-puppeteer/teardown');
exports.testEnvironment= require.resolve('jest-environment-puppeteer');
module.exports.setupFilesAfterEnv = [require.resolve('expect-puppeteer')];
@kirill-konshin
Copy link
Author

kirill-konshin commented Feb 15, 2020

Another problem is that puppeteer is not listed as peerDependency and jest-environment-puppeteer is not listed at all. Although it is used: https://github.com/smooth-code/jest-puppeteer/blob/61d04c7e54908c2d662152cc0840b121742437fb/packages/jest-environment-puppeteer/src/PuppeteerEnvironment.js#L2

As a workaround in order to fix it add following to .yarnrc.yml:

packageExtensions:
  "jest-environment-puppeteer@*":
    peerDependencies:
      puppeteer: "*"
    dependencies:
      jest-environment-node: "*"

@kirill-konshin
Copy link
Author

Any updates? More than a month has passed and no response.

@simonelnahas
Copy link

simonelnahas commented Apr 10, 2020

Are you sure that it have been installed properly?
I found that it hadn't even been installed. Check your package.json in devDependencies
If it's missing maybe you made the same mistake as me.

To install properly use:

yarn add --dev puppeteer jest-puppeteer

Not

yarn add dev puppeteer jest-puppeteer

omg ๐Ÿ˜ฎ

Reference:
electron-userland/electron-builder#3180 (comment)

@kirill-konshin
Copy link
Author

I am 100% sure it's installed correctly. If you look at my comment you'll see that it's the problem of package, not installation. Package is using unlisted dependencies.

@l-abels
Copy link

l-abels commented Apr 29, 2020

I recently switched from npm to pnpm and started receiving the error Test environment jest-environment-puppeteer cannot be found. Make sure the testEnvironment configuration option points to an existing node module.

From what I understand about pnpm, this means that jest-environment-puppeteer is being resolved through methods that aren't technically legal, and rely on a side-effect of how npm structures modules.

@eddiegroves
Copy link

Error with Yarn 2

Error: jest-environment-puppeteer tried to access puppeteer, but it isn't declared in its dependencies; this makes the require call ambiguous and unsound.

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

Successfully merging a pull request may close this issue.

5 participants