🚨 Shai-Hulud Strikes Again:834 Packages Compromised.Technical Analysis
Socket
Book a DemoInstallSign in
Socket

@rws-air/jestscreenshot

Package Overview
Dependencies
Maintainers
6
Versions
30
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@rws-air/jestscreenshot

Jest reporter plugin to take Puppeteer screenshots on failing tests

latest
Source
npmnpm
Version
5.0.1
Version published
Maintainers
6
Created
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

jest

FAQs

Package last updated on 22 May 2020

Did you know?

Socket

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