fix(core): update

This commit is contained in:
Philipp Kunz 2021-01-26 03:15:50 +00:00
parent 45ee6eca31
commit 8ee456da5f
3 changed files with 17 additions and 15 deletions

View File

@ -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);
});

View File

@ -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 <T> {
/**
* 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<T>) => {
this.test(descriptionArg, testFunctionArg, 'only');
},
};
private _tapPreTasks: PreTask[] = [];
private _tapTests: TapTest[] = [];
private _tapTestsOnly: TapTest[] = [];
private _tapTests: TapTest<any>[] = [];
private _tapTestsOnly: TapTest<any>[] = [];
/**
* Normal test function, will run one by one
@ -36,10 +36,10 @@ export class Tap {
*/
public test(
testDescription: string,
testFunction: ITestFunction,
testFunction: ITestFunction<T>,
modeArg: 'normal' | 'only' | 'skip' = 'normal'
) {
const localTest = new TapTest({
const localTest = new TapTest<T>({
description: testDescription,
testFunction,
parallel: false,

View File

@ -9,25 +9,25 @@ import { HrtMeasurement } from '@pushrocks/smarttime';
// interfaces
export type TTestStatus = 'success' | 'error' | 'pending' | 'errorAfterSuccess' | 'timeout';
export type ITestFunction = (tapTools?: TapTools) => Promise<any>;
export interface ITestFunction <T = unknown> { (tapTools?: TapTools): Promise<T> };
export class TapTest {
export class TapTest <T = unknown> {
public description: string;
public failureAllowed: boolean;
public hrtMeasurement: HrtMeasurement;
public parallel: boolean;
public status: TTestStatus;
public tapTools: TapTools;
public testFunction: ITestFunction;
public testFunction: ITestFunction<T>;
public testKey: number; // the testKey the position in the test qeue. Set upon calling .run()
private testDeferred: Deferred<TapTest> = plugins.smartpromise.defer();
public testPromise: Promise<TapTest> = this.testDeferred.promise;
private testResultDeferred: Deferred<any> = plugins.smartpromise.defer();
public testResultPromise: Promise<any> = this.testResultDeferred.promise;
private testDeferred: Deferred<TapTest<T>> = plugins.smartpromise.defer();
public testPromise: Promise<TapTest<T>> = this.testDeferred.promise;
private testResultDeferred: Deferred<T> = plugins.smartpromise.defer();
public testResultPromise: Promise<T> = this.testResultDeferred.promise;
/**
* constructor
*/
constructor(optionsArg: { description: string; testFunction: ITestFunction; parallel: boolean }) {
constructor(optionsArg: { description: string; testFunction: ITestFunction<T>; parallel: boolean }) {
this.description = optionsArg.description;
this.hrtMeasurement = new HrtMeasurement();
this.parallel = optionsArg.parallel;