This package has been deprecated

Author message:

This package has been moved to @zappar/jest-console-logs

@zappar/test-utils
TypeScript icon, indicating that this package has built-in type declarations

0.0.3 • Public • Published

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);

Readme

Keywords

none

Package Sidebar

Install

npm i @zappar/test-utils

Weekly Downloads

1

Version

0.0.3

License

MIT

Unpacked Size

10.7 kB

Total Files

10

Last publish

Collaborators

  • david.szucs
  • seenevz
  • cgauld
  • deim
  • simon_zappar
  • jordan-zappar
  • george.martin
  • squeral
  • francesca.may
  • justin_zappar