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-performance-matchers

v1.0.1

Published

A minimalistic library with jest matchers(assertions) for measuring code performance

Downloads

765

Readme

jest-performance-matchers

SonarCloud

Security Rating Coverage Reliability Rating

License: MIT

A minimalistic library with jest matchers(assertions) for measuring code performance in node.js

Prerequisites

jest-performance-matchers only supports

  • Jest version 27.0.0 and newer
  • Node.js version 14.0.0 and newer

How to install

With npm:

npm intall --save-dev jest-performance-matchers

Setup

Either import the matcher in test you want to use them :

import 'jest-performance-matchers';

Or create a setup script and add to setupFilesAfterEnv as instructed in Configuring Jest :

// setupPerformanceMatchers.js

import 'jest-performance-matchers';
// jest.config.js

"jest": {
  "setupFilesAfterEnv": ['<rootDir>/setupPerformanceMatchers.js']
}

How to use the matchers

.toCompleteWithin

Assert that the synchronous code runs within the given duration:

import 'jest-performance-matchers';

describe('Test the performance of synchronous code', () => {
    test("Should complete in 10 ms at most", () => {
        expect(() => {
            // Do something that should complete in 10 ms at most;
        }).toCompleteWithin(10);
    });

    test("Should not complete in less than 10 ms", () => {
        expect(() => {
            // Do something that should not complete in less than 10 ms;
        }).not.toCompleteWithin(10);
    });
});

.toCompleteWithinQuantile

Assert that the synchronous code executed for I times, runs Q% the time within the given duration:

import 'jest-performance-matchers';

describe('Test the performance of synchronous code', () => {
    test("Should be executed 100 times and 95% of the time should complete in 10 ms at most", () => {
        expect(() => {
            // Do something that 95% of the time should complete in 10 ms at most;
        }).toCompleteWithinQuantile(10, {iterations: 100, quantile: 95});
    });

    test("Should be executed 100 times and 95% of the time should not complete in less 10 ms", () => {
        expect(() => {
            // Do something that 95% of the time should not complete in less 10 ms;
        }).not.toCompleteWithinQuantile(10, {iterations: 100, quantile: 95});
    });
});

.toResolveWithin

Assert that the asynchronous code resolves within the given duration:

import 'jest-performance-matchers';

describe('Test the performance of asynchronous code', () => {
    test("Should resolve in 10 ms at most (async)", async () => {
        await expect(async () => {
            // await for a promise that should resolve in 10 ms at most;
        }).toResolveWithin(10);
    });

    test("Should resolve in 10 ms at most (promise)", async () => {
        return expect(() => {
            // return a promise that should resolve in 10 ms at most;
        }).toResolveWithin(10);
    });

    test("Should not resolve in less than 10 ms (promise)", async () => {
        return expect(() => {
            // return a promise that should not resolve in less than 10 ms;
        }).not.toResolveWithin(10);
    });
});

.toResolveWithinQuantile

Assert that the asynchronous code resolves for I times, runs Q% the time within the given duration:

import 'jest-performance-matchers';

describe('Test the performance of asynchronous code', () => {
    test("Should be executed 100 times and 95% of the time should resolve for 10 ms at most", async () => {
        await expect(async () => {
            // await for a promise that 95% of the time should resolve for 10 ms at most;
        }).toResolveWithinQuantile(10, {iterations: 100, quantile: 95});
    });

    test("Should be executed 100 times and 95% of the time should not resolve in less than 10 ms", async () => {
        await expect(() => {
            // return a promise that 95% of the time should not resolve in less than 10 ms;
        }).not.toResolveWithinQuantile(10, {iterations: 100, quantile: 95});
    });
});

How to Contribute

Contributions from the community are highly appreciated. Here are ways you can contribute to this project:

  1. Reporting Issues: If you find bugs or have suggestions, open an issue.

  2. Code Contributions: Submit code changes through pull requests.

  3. Documentation: Improve project documentation through pull requests.

  4. Support: Simply give the project a star, your support is greatly appreciated!

Getting Started

  1. Fork the repository and clone it to your local environment.

  2. Create a new branch for your changes.

  3. Make your changes, commit them with descriptive messages, and push to your forked repository.

  4. Create a Pull Request (PR) from your branch to the main repository.

If you have any questions, feel free to reach out. Happy coding!

License

MIT License