UNPKG

toofast

Version:

The Node.js performance testing tool with unit-test-like API.

47 lines (46 loc) 1.69 kB
import { getCurrentNode, DescribeNode, MeasureNode, TestNode, TestSuiteNode } from './runner-api.js'; export function beforeEach(hook) { getCurrentNode().beforeEach(hook); } export function afterEach(hook) { getCurrentNode().afterEach(hook); } export function beforeWarmup(hook) { getCurrentNode().beforeWarmup(hook); } export function afterWarmup(hook) { getCurrentNode().afterWarmup(hook); } export function beforeBatch(hook) { getCurrentNode().beforeBatch(hook); } export function afterBatch(hook) { getCurrentNode().afterBatch(hook); } export function beforeIteration(hook) { getCurrentNode().beforeIteration(hook); } export function afterIteration(hook) { getCurrentNode().afterIteration(hook); } export function describe(name, arg1, arg2) { const node = getCurrentNode(); if (!(node instanceof TestSuiteNode || node instanceof DescribeNode)) { throw new Error('Unexpected describe() invocation'); } node.appendChild(typeof arg1 === 'function' ? new DescribeNode(name, arg1) : new DescribeNode(name, arg2, arg1)); } export function test(name, arg1, arg2) { const node = getCurrentNode(); if (!(node instanceof TestSuiteNode || node instanceof DescribeNode)) { throw new Error('Unexpected test() invocation'); } node.appendChild(typeof arg1 === 'function' ? new TestNode(name, arg1) : new TestNode(name, arg2, arg1)); } export function measure(arg0, arg1) { const node = getCurrentNode(); if (!(node instanceof TestNode)) { throw new Error('Unexpected measure() invocation'); } node.appendChild(typeof arg0 === 'function' ? new MeasureNode(arg0) : new MeasureNode(arg1, arg0)); }