This is an example of using the global setup/teardown apis alone with the async test-environment apis to make jest work smoothly with puppeteer.
Please file an issue or send me a DM if you have any questions.
A working example of jest with puppeteer
Home Page: http://facebook.github.io/jest/docs/en/puppeteer.html#content
License: The Unlicense
This is an example of using the global setup/teardown apis alone with the async test-environment apis to make jest work smoothly with puppeteer.
Please file an issue or send me a DM if you have any questions.
First of all, thanks for sharing the setup configuration, it really helped me to get started with jest + puppeteer.
With my current configuration, I cannot get the reference of global document variable.
I understand that it replaces jest-environment-jsdom
with jest-environment-node
.
Can you please let me know what I'm missing here & how your example code works?
Thank you.
it('should load without error', async () => {
let text = await page.evaluate(() => document.body.textContent)
expect(text).toContain('google')
})
I'm not blocked though, I'm using page.$eval
to get element handle.
Is it expected that the setup runs once PER test? This is the output I get:
Determining test suites to run...Setup Puppeteer Environment.
Setup Puppeteer Test Environment.
PASS __tests__/test3.js
Setup Puppeteer Test Environment.
PASS __tests__/test1.js
Setup Puppeteer Test Environment.
PASS __tests__/test2.js
Setup Puppeteer Test Environment.
PASS __tests__/test5.js
Setup Puppeteer Test Environment.
PASS __tests__/test4.js
Test Suites: 5 passed, 5 total
Tests: 5 passed, 5 total
Snapshots: 0 total
Time: 2.049s
Ran all test suites.
Teardown Puppeteer Environment.
I can't see an explanation here or in this repo...
Why is it so complicated?
The examples show test google.com
, it's online server.
Is there a way we can configure the config files and run puppeteer in headless or non-headless mode from command line. if yes, how ? If you could share that will be great.
chrome changed behaviour where if you are on google.com, it goes to startup page instead of the actual site. your sample tests are hitting this case and never finishing since you are never on an actual website
Hi @xfumihiro,
This is really cool that you have put this example together and would be definitely very helpful.
While ago I started a project with the same purpose and has a full integration of jest and puppeteer in it.
https://github.com/NimaSoroush/differencify
jest section:
https://github.com/NimaSoroush/differencify#usage-with-jest
Maybe worth linking these two projects together. Let me know what are your thoughts?
How can we run all test in our own order like
I want to run all tests in ascending or Descending order how can I do?
Question: should we be closing the page after each test? eg:
afterAll(async () => {
await page.close()
})
I'm starting from scratch learning node + jest + puppeteer and this repo really helped, thanks!
I would add the commands needed to run it, as it would make it easier for people new to the frontend world to have a working test suite of jest + puppetter. These steps may be
npm install
/usr/bin/env node node_modules/jest/bin/jest.js
These steps were the ones I found to work but maybe there's a better or more general way.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.