Socket
Book a DemoInstallSign in
Socket

@zappar/test-utils

Package Overview
Dependencies
Maintainers
11
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@zappar/test-utils

Screenshot and console test utilities for jest/puppeteer

latest
Source
npmnpm
Version
0.0.3
Version published
Maintainers
11
Created
Source

Test Utils

Build

This library contains some handy functions which aid jest-puppeteer tests.

You can find some examples in action over at https://github.com/zappar-xr/test-utils/tree/master/tests

Table Of Contents

Click to expand table of contents

Starting Development

You can use this library by installing from NPM for use in a jest-puppeteer project.

NPM

Run the following NPM command inside your project directory:

$ npm install --save-dev @zappar/test-utils

Then import the library into your tests:

import * as util from '@zappar/test-utils';

Usage

Expecting Console Logs

util.expectConsoleLogs resolves once provided logs are detected before the timeout.

it('expectConsoleLogs', async () => {
  const page = await browser.newPage();
  page.goto(url);
  await util.expectConsoleLogs(
    [ // expected logs
      'log 1',
      'log 2',
      'log 3',
    ],
    page,
    30000, //timeout
    new Set([ // logs to ignore
      '[HMR] Waiting for update signal from WDS...',
      '[WDS] Hot Module Replacement enabled.',
      '[WDS] Live Reloading enabled.',
    ]),
  );
});

Waiting for console logs

util.waitForConsoleLog takes a log to wait for, the page and a timeout.

 it('waitForConsoleLog', async () => {
    const page = await browser.newPage();
    page.goto(url);
    await util.waitForConsoleLog('log 5', page, 10000);
  });

Compare Screenshots

util.compareScreenshots returns a promise containing the difference between two images.

const buffer = await page.screenshot();
await fs.writeFile('tests/screenshots/page.png', (buffer as unknown) as Buffer);
const diff = await util.compareScreenshots(await fs.readFile('tests/screenshots_expected/correct-page.png'), (buffer as unknown) as Buffer);
await expect(diff).toBeLessThan(50);

FAQs

Package last updated on 09 Apr 2021

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