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
[Help needed] mixed use of jest-environment-puppeteer and jest-enviroment-jsdom? #198
Comments
you dont need set the node ENV variable, because reference https://github.com/GoogleChrome/puppeteer/blob/master/docs/api.md#browserwsendpoint |
Thanks for the pointers @xiaoyuhen , they are very helpful. I guess this is because I did not use jest-puppeteer as the preset in jest.config.js, seems doing this will make jest-environment-puppeteer the default test ENV for my project, no? I do see in the README that:
I wonder how can I get just-puppeteer work without making it the preset for jest? |
You can use yarn add jest-environment-puppeteer expect-puppeteer -D jest.config module.exports = {
globalSetup: 'jest-environment-puppeteer/setup',
globalTeardown: 'jest-environment-puppeteer/teardown',
testEnvironment: 'jest-environment-puppeteer',
setupTestFrameworkScriptFile: 'expect-puppeteer',
} |
Thanks for the tip @xiaoyuhen
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. |
@DongShi how do you JSDOM to testEnvironment while use jest-puppeteer? jest-puppeteer's inside testEnvironment was customed,has no window Object, when i run same test based on jsdom, i get 'window is not defined' |
#234 i see this, add this block code to any test file's head
it works well |
To anybody else stumbling into this; in my case it was this: My module.exports = {
preset: isBrowser ? 'jest-puppeteer' : undefined,
...
globalSetup: './script/start-server-for-jest.mjs',
globalTeardown: './script/kill-server-for-jest.mjs',
} But the my own setting of import setupJestPuppeteer from 'jest-environment-puppeteer/setup.js'
...
export default async () => {
...
if (process.env.BROWSER) {
await setupJestPuppeteer()
}
} |
💬 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):
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?
The text was updated successfully, but these errors were encountered: