import Macroable from '@poppinss/macroable'; import { type Group } from '../group/main.js'; import { type Emitter } from '../emitter.js'; import { type Refiner } from '../../refiner/main.js'; import type { TestContext } from '../test_context.js'; import type { DataSetNode, TestEndNode, TestOptions, RetryBackoffOptions, TestExecutor, TestHooksHandler, TestHooksCleanupHandler, RunnerListTestNode } from '../../types.js'; /** * Test class exposes a self contained API to configure and run * tests along with its hooks. * * @example * const test = new Test('2 + 2 = 4', emitter, refiner) * * test.run(async ({ assert }) => { * assert.equal(2 + 2 , 4) * }) */ export declare class Test extends Macroable { #private; title: string; parent?: Group | undefined; /** * Methods to call before the test callback is executed */ static executingCallbacks: ((test: Test) => void)[]; /** * Methods to call after the test callback is executed */ static executedCallbacks: ((test: Test, hasError: boolean, errors: TestEndNode['errors']) => void)[]; /** * Define a synchronous function to call before running * the test executor callback * * Do note: Async methods are not allowed * * @param callback - The function to call before running the test executor callback */ static executing(callback: (test: Test) => void): void; /** * Define a synchronous function to call after running * the test executor callback * * Do note: Async methods are not allowed * * @param callback - The function to call after running the test executor callback */ static executed(callback: (test: Test, hasError: boolean, errors: TestEndNode['errors']) => void): void; /** * Know if the test has been executed. Skipped and * todo tests are also considered executed. */ get executed(): boolean; /** * Know if the test has failed. */ get failed(): boolean; /** * Test options */ options: TestOptions; /** * Reference to the test dataset */ dataset?: any[]; /** * Reference to the test context. Available at the time * of running the test */ context: TestContext; /** * Find if the test is pinned */ get isPinned(): boolean; constructor(title: string, context: TestContext | ((test: Test) => TestContext | Promise), emitter: Emitter, refiner: Refiner, parent?: Group | undefined); /** * Skip the test conditionally * * @param skip - Whether to skip the test, can be a function that returns true * @param skipReason - The reason to skip the test */ skip(skip?: boolean | (() => Promise | boolean), skipReason?: string): this; /** * Expect the test to fail. Helpful in creating test cases * to showcase bugs * * @param failReason - The reason the test is expected to fail */ fails(failReason?: string): this; /** * Define custom timeout for the test * * @param timeout - The timeout in milliseconds */ timeout(timeout: number): this; /** * Disable test timeout. It is same as calling `test.timeout(0)` */ disableTimeout(): this; /** * Reset the timeout from within the test callback. * * @param duration - The timeout duration in milliseconds */ resetTimeout(duration?: number): this; /** * Assign tags to the test. Later you can use the tags to run * specific tests * * @param tags - The tags to assign to the test * @param strategy - The strategy to use when assigning the tags */ tags(tags: string[], strategy?: 'replace' | 'append' | 'prepend'): this; /** * Configure the number of times this test should be retried when failing, * with optional exponential backoff or custom delay logic. * * @param retries - The maximum number of times to retry the test callback upon failure. * @param options - Backoff factor multiplier, custom delay callback `(attempt) => ms`, * or a {@link RetryBackoffOptions} configuration object. * * @example * **Exponential Backoff** * ```ts * test('flaky API', async () => { ... }).retry(3, { factor: 2, minTimeout: 500 }) * ``` * * @example * **Custom Delay Callback** * ```ts * test('flaky API', async () => { ... }).retry(3, (attempt) => attempt * 1000) * ``` */ retry(retries: number, options?: number | ((attempt: number) => number) | RetryBackoffOptions): this; /** * Wait for the test executor to call done method */ waitForDone(): this; /** * Pin current test. Pinning a test will only run the * pinned tests. */ pin(): this; /** * Define the dataset for the test. The test executor will be invoked * for all the items inside the dataset array * * @param dataset - The dataset to use for the test * @returns The test with the dataset configured */ with(dataset: Dataset): Test; /** * Define the test executor function * * @param executor - The function to execute * @param debuggingError - The error to use when debugging */ run(executor: TestExecutor, debuggingError?: Error): this; /** * Register a test setup function * * @param handler - The function to call before running the test executor callback */ setup(handler: TestHooksHandler): this; /** * Register a test teardown function * * @param handler - The function to call after running the test executor callback */ teardown(handler: TestHooksHandler): this; /** * Register a cleanup hook from within the test * * @param handler - The function to call after running the test executor callback */ cleanup(handler: TestHooksCleanupHandler): this; /** * Execute test */ exec(): Promise; /** * Return JSON representation of the test */ toJSON(): RunnerListTestNode; }