@zappar/jest-console-logs
TypeScript icon, indicating that this package has built-in type declarations

1.1.1 • Public • Published

jest-console-logs

Build

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

You can find some examples in action over at https://github.com/zappar-xr/jest-console-logs/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/jest-console-logs

Then import the library into your tests:

import * as util from '@zappar/jest-console-logs';

Usage

Expecting Console Logs (Sequential)

util.expectSequential resolves once provided logs are detected before the timeout. You may provide a set of logs to be ignored.

  it('expectConsoleLogs', async () => {
    const page = await browser.newPage();
    page.goto(url);
    await util.expectSequential(
      {
        expected: [
          'log 1',
          'log 2',
          'log 3',
        ],
        page,
        timeoutMs: 30000,
        ignore: new Set([
          '[HMR] Waiting for update signal from WDS...',
          '[WDS] Hot Module Replacement enabled.',
          '[WDS] Live Reloading enabled.',
        ]),
      },
    );
    await new Promise((resolve) => setTimeout(resolve, 1000));
    await page.close();
  });

Expecting Console Logs (Unordered)

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

  it('expectUnorderedLogs', async () => {
    const page = await browser.newPage();
    page.goto(url);
    await util.expectLogs({
      expected: [
        'log 1',
        'log 3',
        'log 2',
      ],
      timeoutMs: 1000,
      page,
    });
  });

Catching errors:

  it('expectUnorderedLogsErrors', async () => {
    const page = await browser.newPage();
    page.goto(url);
    try {
      await util.expectLogs({
        expected: [
          'log 1',
          'log 35',
          'log 2',
        ],
        timeoutMs: 1000,
        page,
      });
    } catch (e) {
      expect(e.message).toEqual('Could not find expected console logs: log 35');
    }
  });

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

Readme

Keywords

none

Package Sidebar

Install

npm i @zappar/jest-console-logs

Weekly Downloads

1

Version

1.1.1

License

MIT

Unpacked Size

12.9 kB

Total Files

8

Last publish

Collaborators

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