Compare commits

..

4 Commits

Author SHA1 Message Date
05defe6031 3.2.12 2021-01-26 03:19:50 +00:00
f4bb17dea1 fix(core): update 2021-01-26 03:19:49 +00:00
1023a94ff2 3.2.11 2021-01-26 03:15:50 +00:00
8ee456da5f fix(core): update 2021-01-26 03:15:50 +00:00
5 changed files with 23 additions and 21 deletions

2
package-lock.json generated
View File

@ -1,6 +1,6 @@
{ {
"name": "@pushrocks/tapbundle", "name": "@pushrocks/tapbundle",
"version": "3.2.10", "version": "3.2.12",
"lockfileVersion": 1, "lockfileVersion": 1,
"requires": true, "requires": true,
"dependencies": { "dependencies": {

View File

@ -1,7 +1,7 @@
{ {
"name": "@pushrocks/tapbundle", "name": "@pushrocks/tapbundle",
"private": false, "private": false,
"version": "3.2.10", "version": "3.2.12",
"description": "tap bundled for tapbuffer", "description": "tap bundled for tapbuffer",
"main": "dist_ts/index.js", "main": "dist_ts/index.js",
"typings": "dist_ts/index.d.ts", "typings": "dist_ts/index.d.ts",

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(); tools.allowFailure();
expect(false).to.be.true; expect(false).to.be.true;
return 'hello';
}); });
const test5 = tap.test('my 5th test -> should pass in about 500ms', async (tools) => { const test5 = tap.test('my 5th test -> should pass in about 500ms', async (tools) => {
const test4Result = await test4.testResultPromise;
tools.timeout(1000); tools.timeout(1000);
await tools.delayFor(500); await tools.delayFor(500);
}); });

View File

@ -2,16 +2,16 @@ import * as plugins from './tapbundle.plugins';
import { IPreTaskFunction, PreTask } from './tapbundle.classes.pretask'; import { IPreTaskFunction, PreTask } from './tapbundle.classes.pretask';
import { TapTest, ITestFunction } from './tapbundle.classes.taptest'; import { TapTest, ITestFunction } from './tapbundle.classes.taptest';
export class Tap { export class Tap <T> {
/** /**
* skips a test * skips a test
* tests marked with tap.skip.test() are never executed * tests marked with tap.skip.test() are never executed
*/ */
public skip = { public skip = {
test: (descriptionArg: string, functionArg: ITestFunction) => { test: (descriptionArg: string, functionArg: ITestFunction<T>) => {
console.log(`skipped test: ${descriptionArg}`); console.log(`skipped test: ${descriptionArg}`);
}, },
testParallel: (descriptionArg: string, functionArg: ITestFunction) => { testParallel: (descriptionArg: string, functionArg: ITestFunction<T>) => {
console.log(`skipped test: ${descriptionArg}`); console.log(`skipped test: ${descriptionArg}`);
}, },
}; };
@ -20,14 +20,14 @@ export class Tap {
* only executes tests marked as ONLY * only executes tests marked as ONLY
*/ */
public only = { public only = {
test: (descriptionArg: string, testFunctionArg: ITestFunction) => { test: (descriptionArg: string, testFunctionArg: ITestFunction<T>) => {
this.test(descriptionArg, testFunctionArg, 'only'); this.test(descriptionArg, testFunctionArg, 'only');
}, },
}; };
private _tapPreTasks: PreTask[] = []; private _tapPreTasks: PreTask[] = [];
private _tapTests: TapTest[] = []; private _tapTests: TapTest<any>[] = [];
private _tapTestsOnly: TapTest[] = []; private _tapTestsOnly: TapTest<any>[] = [];
/** /**
* Normal test function, will run one by one * Normal test function, will run one by one
@ -36,10 +36,10 @@ export class Tap {
*/ */
public test( public test(
testDescription: string, testDescription: string,
testFunction: ITestFunction, testFunction: ITestFunction<T>,
modeArg: 'normal' | 'only' | 'skip' = 'normal' modeArg: 'normal' | 'only' | 'skip' = 'normal'
) { ): TapTest<T> {
const localTest = new TapTest({ const localTest = new TapTest<T>({
description: testDescription, description: testDescription,
testFunction, testFunction,
parallel: false, parallel: false,
@ -61,7 +61,7 @@ export class Tap {
* @param testDescription - A description of what the test does * @param testDescription - A description of what the test does
* @param testFunction - A Function that returns a Promise and resolves or rejects * @param testFunction - A Function that returns a Promise and resolves or rejects
*/ */
public testParallel(testDescription: string, testFunction: ITestFunction) { public testParallel(testDescription: string, testFunction: ITestFunction<T>) {
this._tapTests.push( this._tapTests.push(
new TapTest({ new TapTest({
description: testDescription, description: testDescription,

View File

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