2018-06-28 21:34:41 +00:00
|
|
|
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 {
|
2018-06-28 21:34:41 +00:00
|
|
|
(): Promise<any>;
|
2017-10-10 15:14:14 +00:00
|
|
|
}
|
|
|
|
|
2017-04-28 07:49:57 +00:00
|
|
|
export class TapTools {
|
|
|
|
/**
|
|
|
|
* the referenced TapTest
|
|
|
|
*/
|
2018-06-28 21:34:41 +00:00
|
|
|
private _tapTest: TapTest;
|
2017-04-28 07:49:57 +00:00
|
|
|
|
2018-06-28 21:34:41 +00:00
|
|
|
constructor(TapTestArg) {
|
|
|
|
this._tapTest = TapTestArg;
|
2017-04-28 07:49:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* allow failure
|
|
|
|
*/
|
2019-04-10 10:56:17 +00:00
|
|
|
public allowFailure() {
|
2018-06-28 21:34:41 +00:00
|
|
|
this._tapTest.failureAllowed = true;
|
2017-04-28 07:49:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* async/await delay method
|
|
|
|
*/
|
2019-04-10 10:56:17 +00:00
|
|
|
public async delayFor(timeMilliArg) {
|
2018-06-28 21:34:41 +00:00
|
|
|
await plugins.smartdelay.delayFor(timeMilliArg);
|
2017-04-28 07:49:57 +00:00
|
|
|
}
|
|
|
|
|
2019-04-10 10:56:17 +00:00
|
|
|
public async delayForRandom(timeMilliMinArg, timeMilliMaxArg) {
|
2018-06-28 21:34:41 +00:00
|
|
|
await plugins.smartdelay.delayForRandom(timeMilliMinArg, timeMilliMaxArg);
|
2017-10-10 15:14:14 +00:00
|
|
|
}
|
|
|
|
|
2019-04-10 10:56:17 +00:00
|
|
|
public async timeout(timeMilliArg: number) {
|
|
|
|
const timeout = new plugins.smartdelay.Timeout(timeMilliArg);
|
2018-06-28 21:34:41 +00:00
|
|
|
timeout.makeUnrefed();
|
|
|
|
await timeout.promise;
|
2017-04-28 07:49:57 +00:00
|
|
|
if (this._tapTest.status === 'pending') {
|
2018-06-28 21:34:41 +00:00
|
|
|
this._tapTest.status = 'timeout';
|
2017-04-28 07:49:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-10 10:56:17 +00:00
|
|
|
public async checkIterationLeak(iterationfuncArg: IPromiseFunc) {
|
2019-08-22 21:57:27 +00:00
|
|
|
console.log('iteration leakage checks disabled for now due to incompatibilities with node v12');
|
2019-04-10 10:56:17 +00:00
|
|
|
}
|
2017-10-10 15:14:14 +00:00
|
|
|
|
2019-04-10 10:56:17 +00:00
|
|
|
public async returnError(throwingFuncArg: IPromiseFunc) {
|
2018-06-28 21:34:41 +00:00
|
|
|
let funcErr: Error;
|
2017-10-10 15:14:14 +00:00
|
|
|
try {
|
2018-06-28 21:34:41 +00:00
|
|
|
await throwingFuncArg();
|
2017-10-10 15:14:14 +00:00
|
|
|
} catch (err) {
|
2018-06-28 21:34:41 +00:00
|
|
|
funcErr = err;
|
2017-10-10 15:14:14 +00:00
|
|
|
}
|
2018-06-28 21:34:41 +00:00
|
|
|
return funcErr;
|
2017-10-10 15:14:14 +00:00
|
|
|
}
|
2019-04-10 10:56:17 +00:00
|
|
|
|
2019-04-10 10:56:55 +00:00
|
|
|
public defer() {
|
2019-04-10 10:56:17 +00:00
|
|
|
return plugins.smartpromise.defer();
|
|
|
|
}
|
2017-04-28 07:49:57 +00:00
|
|
|
}
|