question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

🐛 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')];

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:5
  • Comments:6

github_iconTop GitHub Comments

2reactions
kirill-konshincommented, Mar 24, 2020

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

1reaction
simonelnahascommented, 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: https://github.com/electron-userland/electron-builder/issues/3180#issuecomment-408363783

Read more comments on GitHub >

github_iconTop Results From Across the Web

jest-puppeteer | Yarn - Package Manager
Jest preset containing all required configuration for writing integration tests using Puppeteer. npm install jest-puppeteer puppeteer ...
Read more >
Configuring Jest
Configuring Jest. The Jest philosophy is to work great by default, but sometimes you just need more configuration power.
Read more >
npm, pnpm, and Yarn | WebStorm Documentation - JetBrains
WebStorm integrates with the npm, Yarn, Yarn 2, and pnpm, ... Select project package manager: choose the default system installation.
Read more >
referenceerror document is not defined jest - You.com - You.com
But since I also need Puppeteer's environment there's a clash because node only seems to support ONE environment. Ultimately I removed the troubled...
Read more >
Gatsby Changelog | 5.3.0
webpack caching - Starting gradual rollout; Yarn 2 (PNP) support; New API for source plugins: createNodeManifest; Experimental: Node persistence in LMDB - Lower ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found