performance-stub
TypeScript icon, indicating that this package has built-in type declarations

0.2.6 • Public • Published

performance-stub

Greenkeeper badge Build Status NPM version

Stub JavaScript performance implementation for tests.

Usage

import { performance } from "performance-stub";

The exported performance object satisfies TypeScript's Performance interface. All its number members are 0, and all its functions do nothing.

If you don't enjoy name conflicts, you can always import it under a different name:

import { performance as stubPerformance } from "performance-stub";

Shallow Overrides

A createStubPerformance method is exported that creates new Performance instances. Its first parameter takes in shallow overrides for the object that are spread onto the generated object.

import { createStubPerformance } from "performance-stub";
 
createStubPerformance({
    now: () => myClock.now,
});

Deep Overrides

createStubPerformance's second parameter takes in deep overrides for creating navigation and timing stubs.

import { createStubPerformance } from "performance-stub";
 
createStubPerformance({}, {
    navigation: {
        redirectCount: 2,
    },
});

These members are @deprecated in lib.d.ts, and likely should not be used.

Development

After forking the repo from GitHub:

git clone https://github.com/<your-name-here>/performance-stub
cd performance-stub
npm install
npm run verify

Testing

There are two test files under test/: test.dom.ts and test.nodom.ts. Each has a corresponding tsconfig file and task under test:*.

npm run test:dom runs the TypeScript compiler with the normal DOM typings to ensure the created objects satisfy the Performance types. npm run test:nodom runs without the normal DOM typings.

Package Sidebar

Install

npm i performance-stub

Weekly Downloads

10

Version

0.2.6

License

MIT

Unpacked Size

44.6 kB

Total Files

29

Last publish

Collaborators

  • joshuakgoldberg