@j-o-r/sh
Version:
Execute shell commands on Linux-based systems from javascript
105 lines (104 loc) • 2.65 kB
TypeScript
export default Test;
export type AsyncFunction = () => Promise<any>;
export type TestDefinition = {
/**
* - Test name/description.
*/
description: string;
/**
* - Sync/async test function.
*/
callback: Function | AsyncFunction;
};
export type TestReport = {
/**
* - Test description.
*/
description: string;
/**
* - Execution duration (ms).
*/
duration: number;
/**
* - Whether the test ran.
*/
executed: boolean;
};
export type TestReportSummary = {
/**
* - Total tests defined.
*/
tests: number;
/**
* - Total execution time (ms).
*/
duration: number;
/**
* - Number of failures.
*/
errors: number;
/**
* - Number of tests run.
*/
executed: number;
};
declare class Test {
/**
* Creates a test runner instance.
*
* Tracks tests, errors, unresolved promises via {@link AsyncTracker}.
* Supports sync/async callbacks; detects global errors.
*
* @param {boolean} [quiet=false] - Suppress console reports.
* @example
* const t = new Test();
* t.add('basic', () => { throw new Error('fail'); });
* const report = await t.run();
*/
constructor(quiet?: boolean);
/**
* Sets timeout for settling async in sync tests (hack for late errors).
*
* @param {number} timeout - Timeout (ms); default 50.
* @example
* t.syncTimeout(100);
*/
syncTimeout(timeout: number): void;
/**
* Adds a test case.
*
* @param {string} description - Test name.
* @param {Function | AsyncFunction} callback - Test function.
* @returns {Test} Self for chaining.
* @throws {Error} Invalid description (non-string) or callback (not function).
* @example
* t.add('check 1+1', () => expect(1+1).toBe(2));
*/
add(description: string, callback: Function | AsyncFunction): Test;
/**
* Runs tests (all or selected); returns summary.
*
* Prints progress/errors; checks unresolved promises post-run.
*
* @param {number[]} [execute] - Indices of tests to run (default: all).
* @returns {Promise<TestReportSummary>} Summary stats.
* @example
* await t.run([0, 2]); // Run tests 0 and 2
*/
run(execute?: number[]): Promise<TestReportSummary>;
/**
* Prints unresolved promises report (if any).
*
* @example
* t.unresolved();
*/
unresolved(): void;
/**
* Resets all tests, reports, errors, tracker.
*
* @example
* t.reset();
*/
reset(): void;
#private;
}