UNPKG

perf-insight

Version:

Performance benchmarking tool for NodeJS.

102 lines 3.86 kB
import { RunningStdDev } from './sd.mjs'; export type PreparedPerfTestFn<T> = (name: string, method: (data: T) => unknown | Promise<unknown>, timeout?: number) => void; export interface PerfTestFn { (name: string, method: () => unknown | Promise<unknown>, timeout?: number): void; } export interface Prepared<T> { test: PreparedPerfTestFn<T>; } export type UserFn = () => unknown | Promise<unknown>; export interface RunnerContext { /** * Register a test to be run. */ test: PerfTestFn; /** * Prepare data to be used in a test. * @param prepareFn - A function that returns the data to be used in the test. */ prepare<T>(prepareFn: () => T | Promise<T>): Prepared<Awaited<T>>; /** * Register a function to be called after all tests have been run to allow for cleanup. * @param fn - The function to run after all tests have been run. */ afterAll: (fn: UserFn) => void; /** * Register a function to be called after each test has been run to allow for cleanup. * @param fn - The function to run after each test. */ afterEach: (fn: UserFn) => void; /** * Register a function to be called before all tests have been run to allow for setup. * @param fn - The function to run before all tests. */ beforeAll: (fn: UserFn) => void; /** * Register a function to be called before each test has been run to allow for setup. * @param fn - The function to run before all tests. */ beforeEach: (fn: UserFn) => void; timeout: number; /** * Sets the timeout for all tests in the suite. * @param timeoutMs - The amount of time in milliseconds to run the test. */ setTimeout: (timeoutMs: number) => void; } export interface PerfTest extends PerfTestFn, Omit<RunnerContext, 'test'> { } export interface TestResult { name: string; /** the total amount of time spent in the test. */ duration: number; /** the number of iterations */ iterations: number; runs: number[]; /** * The error that was thrown. */ error?: Error | undefined; /** * The timeout in milliseconds used. */ timeout: number; /** The time related to testing, but not included in duration. */ overhead: number; iterationCallbacks: number; sd: RunningStdDev; } export interface RunnerResult { name: string; description: string | undefined; results: TestResult[]; hadFailures: boolean; } export type SuiteFn = (test: PerfTest, context: RunnerContext) => void | Promise<void>; export declare function getActiveSuites(): PerfSuite[]; export interface PerfSuiteRunTestsOptions { /** * Filter for the tests to run. * Only run tests that contain the filter string. * Empty array will run all tests. */ tests?: string[] | undefined; } export interface PerfSuite { readonly name: string; readonly description?: string | undefined; readonly runTests: (options: PerfSuiteRunTestsOptions) => Promise<RunnerResult>; /** * Sets the default timeout for all tests in the suite. * @param timeout - time in milliseconds. * @returns PerfSuite */ readonly setTimeout: (timeout: number | undefined) => this; } export declare function suite(name: string, suiteFn: SuiteFn): PerfSuite; export declare function suite(name: string, description: string | undefined, suiteFn: SuiteFn): PerfSuite; export declare function suite(name: string, description: string, suiteFn: SuiteFn): PerfSuite; export declare function runSuite(suite: PerfSuite): Promise<RunnerResult>; export declare function runSuite(name: string, description: string | undefined, suiteFn: SuiteFn): Promise<RunnerResult>; export declare function runSuite(name: string, suiteFn: SuiteFn): Promise<RunnerResult>; //# sourceMappingURL=perfSuite.d.mts.map