Compare commits

...

6 Commits

Author SHA1 Message Date
f23575a8a2 3.2.1 2020-03-15 16:36:26 +00:00
b2dbc9160b fix(core): update 2020-03-15 16:36:25 +00:00
1e8ab2d7a2 3.2.0 2019-11-16 23:40:38 +01:00
427878763e feat(pretask): introduce new pretask functionality for setting up testing environment 2019-11-16 23:40:36 +01:00
bdcc94e723 3.1.0 2019-11-16 19:22:21 +01:00
3ac46b2363 feat(tools): can now ensure certain directories 2019-11-16 19:22:20 +01:00
9 changed files with 583 additions and 782 deletions

1248
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -1,7 +1,7 @@
{
"name": "@pushrocks/tapbundle",
"private": false,
"version": "3.0.14",
"version": "3.2.1",
"description": "tap bundled for tapbuffer",
"main": "dist/index.js",
"typings": "dist/index.d.ts",
@ -22,16 +22,17 @@
"dependencies": {
"@pushrocks/early": "^3.0.3",
"@pushrocks/smartdelay": "^2.0.3",
"@pushrocks/smartfile": "^7.0.9",
"@pushrocks/smartpromise": "^3.0.2",
"smartchai": "^2.0.1"
},
"devDependencies": {
"@gitzone/tsbuild": "^2.1.11",
"@gitzone/tsbuild": "^2.1.20",
"@gitzone/tsrun": "^1.2.8",
"@gitzone/tstest": "^1.0.24",
"@types/node": "^12.7.2",
"@types/node": "^13.9.0",
"randomstring": "^1.1.5",
"tslint": "^5.19.0",
"tslint": "^6.1.0",
"tslint-config-prettier": "^1.18.0"
},
"files": [

View File

@ -1,5 +1,9 @@
import { tap, expect } from '../ts/index';
tap.preTask('hi there', async () => {
console.log('this is a pretask');
})
const test1 = tap.test('my first test -> expect true to be true', async () => {
return expect(true).to.be.true;
});

View File

@ -0,0 +1,22 @@
import * as plugins from './tapbundle.plugins';
import { TapTools } from './tapbundle.classes.taptools';
export interface IPreTaskFunction {
(tapTools?: TapTools): Promise<any>;
}
export class PreTask {
public description: string;
public preTaskFunction: IPreTaskFunction;
constructor(descriptionArg: string, preTaskFunctionArg: IPreTaskFunction) {
this.description = descriptionArg;
this.preTaskFunction = preTaskFunctionArg;
}
public async run () {
console.log(`::__PRETASK: ${this.description}`);
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 {
@ -7,7 +8,7 @@ export class Tap {
* skips a test
* tests marked with tap.skip.test() are never executed
*/
skip = {
public skip = {
test: (descriptionArg: string, functionArg: ITestFunction) => {
console.log(`skipped test: ${descriptionArg}`);
},
@ -19,12 +20,13 @@ export class Tap {
/**
* only executes tests marked as ONLY
*/
only = {
public only = {
test: (descriptionArg: string, testFunctionArg: ITestFunction) => {
this.test(descriptionArg, testFunctionArg, 'only');
}
};
private _tapPreTasks: PreTask[] = [];
private _tapTests: TapTest[] = [];
private _tapTestsOnly: TapTest[] = [];
@ -33,14 +35,14 @@ export class Tap {
* @param testDescription - A description of what the test does
* @param testFunction - A Function that returns a Promise and resolves or rejects
*/
async test(
public async test(
testDescription: string,
testFunction: ITestFunction,
modeArg: 'normal' | 'only' | 'skip' = 'normal'
) {
let localTest = new TapTest({
const localTest = new TapTest({
description: testDescription,
testFunction: testFunction,
testFunction,
parallel: false
});
if (modeArg === 'normal') {
@ -51,10 +53,14 @@ export class Tap {
return localTest;
}
public preTask (descriptionArg: string, functionArg: IPreTaskFunction) {
this._tapPreTasks.push(new PreTask(descriptionArg, functionArg));
}
/**
* wraps function
*/
wrap(functionArg: ITapWrapFunction) {
public wrap(functionArg: ITapWrapFunction) {
return new TapWrap(functionArg);
}
@ -63,11 +69,11 @@ export class Tap {
* @param testDescription - A description of what the test does
* @param testFunction - A Function that returns a Promise and resolves or rejects
*/
testParallel(testDescription: string, testFunction: ITestFunction) {
public testParallel(testDescription: string, testFunction: ITestFunction) {
this._tapTests.push(
new TapTest({
description: testDescription,
testFunction: testFunction,
testFunction,
parallel: true
})
);
@ -76,12 +82,13 @@ export class Tap {
/**
* starts the test evaluation
*/
async start(optionsArg?: { throwOnError: boolean }) {
let promiseArray: Promise<any>[] = [];
public async start(optionsArg?: { throwOnError: boolean }) {
const promiseArray: Array<Promise<any>> = [];
// safeguard against empty test array
if (this._tapTests.length === 0) {
console.log('no tests specified. Ending here!');
// TODO: throw proper error
return;
}
@ -93,10 +100,15 @@ 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++) {
let currentTest = concerningTests[testKey];
let testPromise = currentTest.run(testKey);
const currentTest = concerningTests[testKey];
const testPromise = currentTest.run(testKey);
if (currentTest.parallel) {
promiseArray.push(testPromise);
} else {
@ -106,10 +118,10 @@ export class Tap {
await Promise.all(promiseArray);
// when tests have been run and all promises are fullfilled
let failReasons: string[] = [];
let executionNotes: string[] = [];
const failReasons: string[] = [];
const executionNotes: string[] = [];
// collect failed tests
for (let tapTest of concerningTests) {
for (const tapTest of concerningTests) {
if (tapTest.status !== 'success') {
failReasons.push(
`Test ${tapTest.testKey + 1} failed with status ${tapTest.status}:\n` +
@ -120,7 +132,7 @@ export class Tap {
}
// render fail Reasons
for (let failReason of failReasons) {
for (const failReason of failReasons) {
console.log(failReason);
}
@ -132,7 +144,7 @@ export class Tap {
/**
* handle errors
*/
threw(err) {
public threw(err) {
console.log(err);
}
}

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

@ -42,6 +42,10 @@ export class TapTools {
}
}
public async ensureDir(pathArg: string) {
await plugins.smartfile.fs.ensureDir(pathArg);
}
public async checkIterationLeak(iterationfuncArg: IPromiseFunc) {
console.log('iteration leakage checks disabled for now due to incompatibilities with node v12');
}

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();
}
}

View File

@ -1,9 +1,10 @@
// pushrocks
import * as early from '@pushrocks/early';
import * as smartdelay from '@pushrocks/smartdelay';
import * as smartfile from '@pushrocks/smartfile';
import * as smartpromise from '@pushrocks/smartpromise';
export { early, smartdelay, smartpromise };
export { early, smartfile, smartdelay, smartpromise };
// third party
/* import * as leakage from 'leakage';