tapbundle/ts/tapbundle.classes.taptools.ts

63 lines
1.4 KiB
TypeScript
Raw Normal View History

2022-03-14 10:22:17 +00:00
import * as plugins from './tapbundle.plugins.js';
import { TapTest } from './tapbundle.classes.taptest.js';
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
2021-12-10 16:34:06 +00:00
constructor(TapTestArg: TapTest<any>) {
this._tapTest = TapTestArg;
2017-04-28 07:49:57 +00:00
}
/**
* allow failure
*/
2019-04-10 10:56:17 +00:00
public allowFailure() {
this._tapTest.failureAllowed = true;
2017-04-28 07:49:57 +00:00
}
/**
* async/await delay method
*/
2021-12-10 16:34:06 +00:00
public async delayFor(timeMilliArg: number) {
await plugins.smartdelay.delayFor(timeMilliArg);
2017-04-28 07:49:57 +00:00
}
2021-12-10 16:34:06 +00:00
public async delayForRandom(timeMilliMinArg: number, timeMilliMaxArg: number) {
await plugins.smartdelay.delayForRandom(timeMilliMinArg, timeMilliMaxArg);
2017-10-10 15:14:14 +00:00
}
2024-03-13 21:07:58 +00:00
public async coloredString(...args: Parameters<typeof plugins.consolecolor.coloredString>) {
return plugins.consolecolor.coloredString(...args);
}
2019-04-10 10:56:17 +00:00
public async timeout(timeMilliArg: number) {
const 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
}
}
2019-04-10 10:56:17 +00:00
public async returnError(throwingFuncArg: IPromiseFunc) {
let funcErr: Error;
2017-10-10 15:14:14 +00:00
try {
await throwingFuncArg();
2021-12-10 16:34:06 +00:00
} catch (err: any) {
funcErr = err;
2017-10-10 15:14:14 +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
}