npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

jest-puppeteer-performance

v1.1.2

Published

Automated UI Performance Testing with Jest and Puppeteer

Downloads

69

Readme

jest-puppeteer-performance

Automated UI Performance Testing with Jest and Puppeteer

Installation

This project has a peer dependency on puppeteer and is intended to be used with jest test runner.

Jest: https://github.com/facebook/jest

Puppeteer: https://github.com/GoogleChrome/puppeteer

npm install jest-puppeteer-performance puppeteer jest

NOTE: We do not install puppeteer or jest because you will need to install them under your own project in order to use them in your source files and with your own tests. jest-puppeteer-performance is not intended to take on the responsibility of providing a test runner, or headless browser. This allows us to keep our package smaller and avoid installing multiple versions of these dependencies.

Usage

This module exports one function analyzePerformance(). Here is an example of how to use it with the default options in a test.

import * as puppeteer from 'puppeteer';
import { analyzePerformance } from 'jest-puppeteer-performance';

describe('Performance Test', async () => {
    let page;
    let browser;

    beforeAll(async () => {
        browser = await puppeteer.launch({headless: false});
        page = await browser.newPage();
        await page.goto('http://example.net/example.html');
    });

    afterAll(async () => {
        await browser.close();
    });

    it('Should be performant', async () => {
        await analyzePerformance(page);
    });
});

analyzePerformance(Puppeteer.Page, MetricsOptions)

MetricsOptions is an object with the following options:

  • exclude: Array of metrics to exclude from measurements.
  • minSamples: Minimum number of samples required before asserting.
  • maxSamples: Maximum number of samples to keep.
  • thresholds: An object desribing how to analyze each metric, indexed by metric keyname. The * special key applies to all metrics not specified separately.
  • thresholds[key].limit: The limit to apply to the threshold method (number of standard deviations, percent increase, or absolute value).
  • thresholds[key].type: The type of threshold method to use when evaluating the specified metric.
{
    exclude: [Metrics.KEYS.Timestamp],
    minSamples: 5,
    maxSamples: 20,
    thresholds: {
        '*': {
            limit: 2,
            type: Metrics.THRESHOLD.StDev
        }
    }
}

Thresholds:

  • Absolute: Absolute Value
  • Percentage: Percentage
  • StDev: Standard Deviation

Metrics gathered:

Timestamp
Documents
Frames
JSEventListeners
Nodes
LayoutCount
RecalcStyleCount
LayoutDuration
RecalcStyleDuration
ScriptDuration
TaskDuration
JSHeapUsedSize
JSHeapTotalSize
appcacheTime
connectTime
domReadyTime
firstPaint
firstPaintTime
initDomTreeTime
loadEventTime
loadTime
lookupDomainTime
readyStart
redirectTime
requestTime
unloadEventTime

Contrib

New Relic

We have provided a script for submitting results to New Relic. You will find the reporter under the contrib namespace.

import * as puppeteer from 'puppeteer';
import { analyzePerformance, performanceEvents, contrib } from 'jest-puppeteer-performance';

let nrAPIKey = 'abcdefABCDEF012345-wXyZ';
let nrCollectorURI = 'https://insights-collector.newrelic.com/v1/accounts/123456/events';

describe('Performance Test', async () => {
    let page;
    let browser;
    let newrelic;

    beforeAll(async () => {
        newrelic = new contrib.NewRelic(performanceEvents, nrAPIKey, nrCollectorURI);
        browser = await puppeteer.launch({headless: false});
        page = await browser.newPage();
        await page.goto('http://example.net/example.html');
    });

    afterAll(async () => {
        await browser.close();
        await newrelic.send();
    });

    it('Should be performant', async () => {
        await analyzePerformance(page);
    });
});