Skip to content

Instantly share code, notes, and snippets.

@rjz
Created April 11, 2018 02:03
Show Gist options
  • Select an option

  • Save rjz/2c3a902fb04bbf1a666034dde414ca75 to your computer and use it in GitHub Desktop.

Select an option

Save rjz/2c3a902fb04bbf1a666034dde414ca75 to your computer and use it in GitHub Desktop.

Phantom Pain

Joel Griffith - Sr. Dev @ AppNexus (Twitter: @griffith_joel)

Sample repo: joelgriffith/phantompain

Background

  • worked with phantomjs to run unit test suite
  • switch to headless chrome
  • phantomjs dev said, "peace"
  • what about site snapshots, visual regressions, functional testing, ...

Some things are hard with react

  • take a screenshot of a webpage (e.g. for twitter, social media, etc)
  • puppeteer (headless chrome library) makes this fast and easy
  • simulate search engine requests w/o server-side rendering? yes, we can

Also good for improving functional tests

  • page.evaluate - define and execute a method within the page. Useful for loading libraries, injecting XSS attempts, etc.
  • works neatly with mocha, jasmine, jest, whatever--even with jest.concurrent (browser sessions are indepnedent)

And visual regressions

  • use jest-image-snapshot (.expectImageSnapshot) to generate binary visual diffs

Thanks, Joel!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment