Giter Club home page Giter Club logo

jest-puppeteer-example's Introduction

CircleCI

jest-puppeteer-example

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.

jest-puppeteer-example's People

Contributors

backflip avatar dependabot[bot] avatar mavrin avatar migueloop avatar xfumihiro avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

jest-puppeteer-example's Issues

ReferenceError: document is not defined

@xfumihiro

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.

Setup running multiple times

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.

sample tests are now broken

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

Necessary to close page?

Question: should we be closing the page after each test? eg:

afterAll(async () => {
  await page.close()
})

Add steps in README for people without exprience with npm or yarn

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

  1. Install node dependencies from package.json using npm (or yarn)
    npm install
  2. Run jest from the recently installed package (not global)
    /usr/bin/env node node_modules/jest/bin/jest.js
  3. Confirm that all the tests passed (image from README.md)

These steps were the ones I found to work but maybe there's a better or more general way.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.