JSPM

@jeeyah/jestscreenshot

1.0.3
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 28
  • Score
    100M100P100Q70944F
  • License ISC

Extend Jest and Puppeteer to automatically take screenshots after each test failure or success

Package Exports

  • @jeeyah/jestscreenshot

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@jeeyah/jestscreenshot) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

jestscreenshot

Extend Jest and Puppeteer to automatically take screenshots after each test failure or success.

Screen shots will be created in a subdirectory of your test script as follows.

Success: screenshots/scriptname-testname.png Failure: screenshots/0-fail-scriptname-testname.png

Import jestscreenshot

let jestscreenshot = require('@jeeyah/jestscreenshot');

In beforeAll, initialize jestscreenshot after initializing Puppeteer

beforeAll(async () => {
  // Create puppeteer browser and page objects first:
  // 
  // browser = await options.puppeteer.launch
  // page = await ret.browser.newPage();
  
  let path = require('path');
  let scriptName = path.basename(__filename).replace('.js', '');
  /** page: page object returned from Puppeteer
   * dirName: __dirname defaults to same directory as script
   * scriptName: Used in the screen shot file name
   * onlyFailures: ONLY take screenshots on test failures, default: false
   */
  let options = {
    page: page, 
    dirName: __dirname,
    scriptName: scriptName
  };
  
  await jestscreenshot.init(options);
});

In afterAll, configure jestscreenshot cleanup just prior to closing browser

jestscreenshot needs to wait for screen shots to finish before the browser closes.

afterAll(() => {
  jestscreenshot.cleanup(function () {
    if (browser) {
      browser.close();
    }
  });
});

Example test file

See tests/test.js for a working example.