performance-stub v0.2.6
performance-stub
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
@deprecatedinlib.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 verifyTesting
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.