diff --git a/test/test.ts b/test/test.ts index 7770773..35fb74f 100644 --- a/test/test.ts +++ b/test/test.ts @@ -23,12 +23,14 @@ const test3 = tap.test( } ); -const test4 = tap.skip.test('my 4th test -> should fail', async (tools) => { +const test4 = tap.test('my 4th test -> should fail', async (tools) => { tools.allowFailure(); expect(false).to.be.true; + return 'hello'; }); const test5 = tap.test('my 5th test -> should pass in about 500ms', async (tools) => { + const test4Result = await test4.testResultPromise; tools.timeout(1000); await tools.delayFor(500); }); diff --git a/ts/tapbundle.classes.tap.ts b/ts/tapbundle.classes.tap.ts index b5d5a4a..aaa30ad 100644 --- a/ts/tapbundle.classes.tap.ts +++ b/ts/tapbundle.classes.tap.ts @@ -2,7 +2,7 @@ import * as plugins from './tapbundle.plugins'; import { IPreTaskFunction, PreTask } from './tapbundle.classes.pretask'; import { TapTest, ITestFunction } from './tapbundle.classes.taptest'; -export class Tap { +export class Tap { /** * skips a test * tests marked with tap.skip.test() are never executed @@ -20,14 +20,14 @@ export class Tap { * only executes tests marked as ONLY */ public only = { - test: (descriptionArg: string, testFunctionArg: ITestFunction) => { + test: (descriptionArg: string, testFunctionArg: ITestFunction) => { this.test(descriptionArg, testFunctionArg, 'only'); }, }; private _tapPreTasks: PreTask[] = []; - private _tapTests: TapTest[] = []; - private _tapTestsOnly: TapTest[] = []; + private _tapTests: TapTest[] = []; + private _tapTestsOnly: TapTest[] = []; /** * Normal test function, will run one by one @@ -36,10 +36,10 @@ export class Tap { */ public test( testDescription: string, - testFunction: ITestFunction, + testFunction: ITestFunction, modeArg: 'normal' | 'only' | 'skip' = 'normal' ) { - const localTest = new TapTest({ + const localTest = new TapTest({ description: testDescription, testFunction, parallel: false, diff --git a/ts/tapbundle.classes.taptest.ts b/ts/tapbundle.classes.taptest.ts index c374367..f2d8701 100644 --- a/ts/tapbundle.classes.taptest.ts +++ b/ts/tapbundle.classes.taptest.ts @@ -9,25 +9,25 @@ import { HrtMeasurement } from '@pushrocks/smarttime'; // interfaces export type TTestStatus = 'success' | 'error' | 'pending' | 'errorAfterSuccess' | 'timeout'; -export type ITestFunction = (tapTools?: TapTools) => Promise; +export interface ITestFunction { (tapTools?: TapTools): Promise }; -export class TapTest { +export class TapTest { public description: string; public failureAllowed: boolean; public hrtMeasurement: HrtMeasurement; public parallel: boolean; public status: TTestStatus; public tapTools: TapTools; - public testFunction: ITestFunction; + public testFunction: ITestFunction; public testKey: number; // the testKey the position in the test qeue. Set upon calling .run() - private testDeferred: Deferred = plugins.smartpromise.defer(); - public testPromise: Promise = this.testDeferred.promise; - private testResultDeferred: Deferred = plugins.smartpromise.defer(); - public testResultPromise: Promise = this.testResultDeferred.promise; + private testDeferred: Deferred> = plugins.smartpromise.defer(); + public testPromise: Promise> = this.testDeferred.promise; + private testResultDeferred: Deferred = plugins.smartpromise.defer(); + public testResultPromise: Promise = this.testResultDeferred.promise; /** * constructor */ - constructor(optionsArg: { description: string; testFunction: ITestFunction; parallel: boolean }) { + constructor(optionsArg: { description: string; testFunction: ITestFunction; parallel: boolean }) { this.description = optionsArg.description; this.hrtMeasurement = new HrtMeasurement(); this.parallel = optionsArg.parallel;