Socket
Socket
Sign inDemoInstall

@rws-air/jestscreenshot

Package Overview
Dependencies
262
Maintainers
6
Versions
30
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @rws-air/jestscreenshot

Jest reporter plugin to take Puppeteer screenshots on failing tests


Version published
Weekly downloads
18
increased by63.64%
Maintainers
6
Install size
5.01 MB
Created
Weekly downloads
 

Readme

Source

logo

Rijkswaterstaat jestscreenshot

Creates screenshots with Puppeteer when a Jest test fails and optionally upload it to Slack


Project Status

GitHub

Bundle Sizes

npm bundle size npm bundle size

Versions

npm

Our Badges

website slack trello Pivotal Tracked Sketch Designed Zeplin Based


Installation

Install with yarn or npm:

yarn add -D @rws-air/jestscreenshot @types/jest-environment-puppeteer jest-circus jest-environment-puppeteer

Usage

const JestScreenshot = require('@rws-air/jestscreenshot');

About automated Slack uploading

This library supports uploading your screenshots to Slack by providing the SLACK_WEBTOKEN environment variable, or, through the slackToken option. You will also nede to provide the Slack Channel ID(s) through the option slackChannels and setting slackUpload option to true.

Example

Please note that you cannot use ES module imports in the jest-enviroment.ts file. Jest does not support them.

// jest.config.js

module.exports = {
  testRunner: 'jest-circus/runner',
  testEnvironment: '<rootDir>/__tests__/jest-environment.js',

  testMatch: ['<rootDir>/__tests__/index.test.ts'],

  globalSetup: 'jest-environment-puppeteer/setup',
  globalTeardown: 'jest-environment-puppeteer/teardown',
  setupFilesAfterEnv: ['expect-puppeteer', '<rootDir>/__tests__/jest-framework.ts']
};
// jest-framework.ts

jest.retryTimes(2);
// jest-environment.ts

/* eslint-disable @typescript-eslint/no-var-requires, @typescript-eslint/no-require-imports, @typescript-eslint/explicit-member-accessibility */
const PuppeteerEnvironment = require('jest-environment-puppeteer');
const JestScreenshot = require('@rws-air/jestscreenshot');
require('jest-circus');

const retryAttempts = process.env.RETRY_ATTEMPTS || 2;

// @ts-ignore
class CustomEnvironment extends PuppeteerEnvironment {
  async setup() {
    await super.setup();

    if (!process.env.CI) await this.localSetup();
  }

  async teardown() {
    // @ts-ignore
    await this.global.page.waitFor(2000);
    await super.teardown();
  }

  async handleTestEvent(event, state) {
    if (event.name === 'test_fn_failure') {
      if (state.currentlyRunningTest.invocations > retryAttempts) {
        const testName = state.currentlyRunningTest.name;
        const jestScreenshot = new JestScreenshot({
          page: this.global.page,
          dirName: __dirname,
          testName,
          slackChannels: ['ChannelID'],
          slackUpload: true
        });

        await jestScreenshot.setup();
      }
    }
  }
}

module.exports = CustomEnvironment;

API Documentation

Check out the docs on github pages

Keywords

FAQs

Last updated on 22 May 2020

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc