feat(pretask): introduce new pretask functionality for setting up testing environment

This commit is contained in:
Philipp Kunz 2019-11-16 23:40:36 +01:00
parent bdcc94e723
commit 427878763e
4 changed files with 45 additions and 15 deletions

View File

@ -0,0 +1,19 @@
import * as plugins from './tapbundle.plugins';
import { TapTools } from './tapbundle.classes.taptools';
export interface IPreTaskFunction {
(tapTools?: TapTools): Promise<any>;
}
export class PreTask {
public preTaskFunction: IPreTaskFunction;
constructor(preTaskFunctionArg: IPreTaskFunction) {
this.preTaskFunction = preTaskFunctionArg;
}
public async run () {
await this.preTaskFunction(new TapTools(null));
}
}

View File

@ -1,5 +1,6 @@
import * as plugins from './tapbundle.plugins';
import { IPreTaskFunction, PreTask } from './tapbundle.classes.pretask';
import { TapTest, ITestFunction } from './tapbundle.classes.taptest';
import { TapWrap, ITapWrapFunction } from './tapbundle.classes.tapwrap';
export class Tap {
@ -25,6 +26,7 @@ export class Tap {
}
};
private _tapPreTasks: PreTask[] = [];
private _tapTests: TapTest[] = [];
private _tapTestsOnly: TapTest[] = [];
@ -51,6 +53,10 @@ export class Tap {
return localTest;
}
public preTask (functionArg: IPreTaskFunction) {
this._tapPreTasks.push(new PreTask(functionArg));
}
/**
* wraps function
*/
@ -82,6 +88,7 @@ export class Tap {
// safeguard against empty test array
if (this._tapTests.length === 0) {
console.log('no tests specified. Ending here!');
// TODO: throw proper error
return;
}
@ -93,6 +100,11 @@ export class Tap {
concerningTests = this._tapTests;
}
// lets run the pretasks
for (const preTask of this._tapPreTasks) {
await preTask.run();
}
console.log(`1..${concerningTests.length}`);
for (let testKey = 0; testKey < concerningTests.length; testKey++) {
const currentTest = concerningTests[testKey];

View File

@ -9,21 +9,19 @@ import { Deferred } from '@pushrocks/smartpromise';
// interfaces
export type TTestStatus = 'success' | 'error' | 'pending' | 'errorAfterSuccess' | 'timeout';
export interface ITestFunction {
(tapTools?: TapTools): Promise<any>;
}
export type ITestFunction = (tapTools?: TapTools) => Promise<any>;
export class TapTest {
description: string;
failureAllowed: boolean;
hrtMeasurement: HrtMeasurement;
parallel: boolean;
status: TTestStatus;
tapTools: TapTools;
testFunction: ITestFunction;
testKey: number; // the testKey the position in the test qeue. Set upon calling .run()
testDeferred: Deferred<TapTest> = plugins.smartpromise.defer();
testPromise: Promise<TapTest> = this.testDeferred.promise;
public description: string;
public failureAllowed: boolean;
public hrtMeasurement: HrtMeasurement;
public parallel: boolean;
public status: TTestStatus;
public tapTools: TapTools;
public testFunction: ITestFunction;
public testKey: number; // the testKey the position in the test qeue. Set upon calling .run()
public testDeferred: Deferred<TapTest> = plugins.smartpromise.defer();
public testPromise: Promise<TapTest> = this.testDeferred.promise;
/**
* constructor
*/
@ -39,10 +37,10 @@ export class TapTest {
/**
* run the test
*/
async run(testKeyArg: number) {
public async run(testKeyArg: number) {
this.hrtMeasurement.start();
this.testKey = testKeyArg;
let testNumber = testKeyArg + 1;
const testNumber = testKeyArg + 1;
try {
await this.testFunction(this.tapTools);
if (this.status === 'timeout') {

View File

@ -19,6 +19,7 @@ export class TapWrap {
* run the wrapFunction
*/
async run() {
// TODO: make sure it makes sense what we do here.
await this.wrapFunction();
}
}