tapbundle/ts/tapbundle.classes.taptools.ts

59 lines
1.2 KiB
TypeScript
Raw Normal View History

import * as plugins from './tapbundle.plugins';
import { TapTest } from './tapbundle.classes.taptest';
2017-04-28 07:49:57 +00:00
2017-10-10 15:14:14 +00:00
export interface IPromiseFunc {
(): Promise<any>;
2017-10-10 15:14:14 +00:00
}
2017-04-28 07:49:57 +00:00
export class TapTools {
/**
* the referenced TapTest
*/
private _tapTest: TapTest;
2017-04-28 07:49:57 +00:00
constructor(TapTestArg) {
this._tapTest = TapTestArg;
2017-04-28 07:49:57 +00:00
}
/**
* allow failure
*/
allowFailure() {
this._tapTest.failureAllowed = true;
2017-04-28 07:49:57 +00:00
}
/**
* async/await delay method
*/
async delayFor(timeMilliArg) {
await plugins.smartdelay.delayFor(timeMilliArg);
2017-04-28 07:49:57 +00:00
}
async delayForRandom(timeMilliMinArg, timeMilliMaxArg) {
await plugins.smartdelay.delayForRandom(timeMilliMinArg, timeMilliMaxArg);
2017-10-10 15:14:14 +00:00
}
async timeout(timeMilliArg: number) {
let timeout = new plugins.smartdelay.Timeout(timeMilliArg);
timeout.makeUnrefed();
await timeout.promise;
2017-04-28 07:49:57 +00:00
if (this._tapTest.status === 'pending') {
this._tapTest.status = 'timeout';
2017-04-28 07:49:57 +00:00
}
}
async checkIterationLeak(iterationfuncArg: IPromiseFunc) {
await plugins.leakage.iterate.async(iterationfuncArg);
2017-10-10 15:14:14 +00:00
}
async returnError(throwingFuncArg: IPromiseFunc) {
let funcErr: Error;
2017-10-10 15:14:14 +00:00
try {
await throwingFuncArg();
2017-10-10 15:14:14 +00:00
} catch (err) {
funcErr = err;
2017-10-10 15:14:14 +00:00
}
return funcErr;
2017-10-10 15:14:14 +00:00
}
2017-04-28 07:49:57 +00:00
}