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.

[Help needed] mixed use of jest-environment-puppeteer and jest-enviroment-jsdom?

See original GitHub issue

💬 Questions and Help

Hey there: I am new to jest and jest-puppeteer, and meet some problems: In my project, some test suites are jsDom based and some are puppeteer based. By the jest doc, we can assign different ENV to different files with a docblock like

/**

So I put this docblock to my puppeteer-based test suites, and leave the others intact (since jest-enviroment-jsdom is the default test ENV)

I give it a try, but see that the code throws at the following(PuppeteerEnviroment.js):

  async setup() {
    const config = await readConfig()
    this.global.puppeteerConfig = config

    const wsEndpoint = process.env.PUPPETEER_WS_ENDPOINT
    if (!wsEndpoint) {
      throw new Error('wsEndpoint not found')
    }

Basically, it seems I need to set the node ENV variable (PUPPETEER_WS_ENDPOINT), but what does it mean? What’s its format like? Can you shed some light?

Note that if I use the jest-puppeter as the preset in jest.config.js, and skip those jsDom based test cases, things are running fine. I am wondering what is happening behind the scene?

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

6reactions
caoweijucommented, Sep 11, 2019

https://github.com/smooth-code/jest-puppeteer/issues/234 i see this, add this block code to any test file’s head

/**
 * @jest-environment jsdom
 */

it works well

4reactions
DongShicommented, Feb 18, 2019

Thanks for the tip @xiaoyuhen Again, this is setting the global test ENV for JEST, and in our case, the test suite based on JSDOM will fail like:

Test suite failed to run ReferenceError: window is not defined

But I think I find a workaround, that is to make jest-environment-puppeteer the default test ENV and meanwhile add a doc block to JSDOM-based test suites like

/**

This will get different test suites correctly set-up.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Using with puppeteer - Jest
Use jest -puppeteer Preset​. Jest Puppeteer provides all required configuration to run your tests using Puppeteer.
Read more >
jest-environment-puppeteer - npm
Start using jest-environment-puppeteer in your project by running `npm ... other projects in the npm registry using jest-environment-puppeteer.
Read more >
jest-puppeteer | Yarn - Package Manager
Jest preset containing all required configuration for writing integration tests using Puppeteer. npm install jest-puppeteer puppeteer ...
Read more >
Getting Started with Jest and Puppeteer | by jsilvax - Medium
Setup Jest, Puppeteer and Babel; Use Puppeteer's API to emulate a ... Finally, we need Babel to transpile our code based on our...
Read more >
How can I work with Jest and puppeteer-cluster - Stack Overflow
jest -puppeteer config: module.exports = { launch: { headless: false, // Use false since hardware acceleration is required for gameplay ...
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