Compare commits
14 Commits
Author | SHA1 | Date | |
---|---|---|---|
d81a8006b1 | |||
5fa4c1cd85 | |||
fc609858ff | |||
19ecca0179 | |||
ff55e596cb | |||
ed8c8312c2 | |||
a6dd8de0db | |||
081347b23b | |||
f23575a8a2 | |||
b2dbc9160b | |||
1e8ab2d7a2 | |||
427878763e | |||
bdcc94e723 | |||
3ac46b2363 |
11295
package-lock.json
generated
11295
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
19
package.json
19
package.json
@ -1,13 +1,13 @@
|
|||||||
{
|
{
|
||||||
"name": "@pushrocks/tapbundle",
|
"name": "@pushrocks/tapbundle",
|
||||||
"private": false,
|
"private": false,
|
||||||
"version": "3.0.14",
|
"version": "3.2.5",
|
||||||
"description": "tap bundled for tapbuffer",
|
"description": "tap bundled for tapbuffer",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
"typings": "dist/index.d.ts",
|
"typings": "dist/index.d.ts",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "(tstest test/)",
|
"test": "(tstest test/)",
|
||||||
"build": "(tsbuild)"
|
"build": "(tsbuild --web)"
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
@ -20,18 +20,19 @@
|
|||||||
},
|
},
|
||||||
"homepage": "https://gitlab.com/pushrocks/tapbundle#README",
|
"homepage": "https://gitlab.com/pushrocks/tapbundle#README",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@pushrocks/early": "^3.0.3",
|
"@pushrocks/smartdelay": "^2.0.9",
|
||||||
"@pushrocks/smartdelay": "^2.0.3",
|
"@pushrocks/smartenv": "^4.0.10",
|
||||||
"@pushrocks/smartpromise": "^3.0.2",
|
"@pushrocks/smartpromise": "^3.0.2",
|
||||||
|
"@pushrocks/smarttime": "^3.0.19",
|
||||||
"smartchai": "^2.0.1"
|
"smartchai": "^2.0.1"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@gitzone/tsbuild": "^2.1.11",
|
"@gitzone/tsbuild": "^2.1.24",
|
||||||
"@gitzone/tsrun": "^1.2.8",
|
"@gitzone/tsrun": "^1.2.12",
|
||||||
"@gitzone/tstest": "^1.0.24",
|
"@gitzone/tstest": "^1.0.36",
|
||||||
"@types/node": "^12.7.2",
|
"@types/node": "^14.0.19",
|
||||||
"randomstring": "^1.1.5",
|
"randomstring": "^1.1.5",
|
||||||
"tslint": "^5.19.0",
|
"tslint": "^6.1.2",
|
||||||
"tslint-config-prettier": "^1.18.0"
|
"tslint-config-prettier": "^1.18.0"
|
||||||
},
|
},
|
||||||
"files": [
|
"files": [
|
||||||
|
40
test/test.browser.ts
Normal file
40
test/test.browser.ts
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
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;
|
||||||
|
});
|
||||||
|
|
||||||
|
const test2 = tap.test('my second test', async tools => {
|
||||||
|
await tools.delayFor(50);
|
||||||
|
});
|
||||||
|
|
||||||
|
const test3 = tap.test(
|
||||||
|
'my third test -> test2 should take longer than test1 and endure at least 1000ms',
|
||||||
|
async () => {
|
||||||
|
expect((await test1).hrtMeasurement.milliSeconds < (await test2).hrtMeasurement.milliSeconds).to
|
||||||
|
.be.true;
|
||||||
|
expect((await test2).hrtMeasurement.milliSeconds > 10).to.be.true;
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
const test4 = tap.skip.test('my 4th test -> should fail', async tools => {
|
||||||
|
tools.allowFailure();
|
||||||
|
expect(false).to.be.true;
|
||||||
|
});
|
||||||
|
|
||||||
|
const test5 = tap.test('my 5th test -> should pass in about 500ms', async tools => {
|
||||||
|
tools.timeout(1000);
|
||||||
|
await tools.delayFor(500);
|
||||||
|
});
|
||||||
|
|
||||||
|
const test6 = tap.skip.test('my 6th test -> should fail after 1000ms', async tools => {
|
||||||
|
tools.allowFailure();
|
||||||
|
tools.timeout(1000);
|
||||||
|
await tools.delayFor(100);
|
||||||
|
});
|
||||||
|
|
||||||
|
tap.start();
|
@ -1,5 +1,9 @@
|
|||||||
import { tap, expect } from '../ts/index';
|
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 () => {
|
const test1 = tap.test('my first test -> expect true to be true', async () => {
|
||||||
return expect(true).to.be.true;
|
return expect(true).to.be.true;
|
||||||
});
|
});
|
||||||
|
22
ts/tapbundle.classes.pretask.ts
Normal file
22
ts/tapbundle.classes.pretask.ts
Normal 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));
|
||||||
|
}
|
||||||
|
}
|
@ -1,5 +1,6 @@
|
|||||||
import * as plugins from './tapbundle.plugins';
|
import * as plugins from './tapbundle.plugins';
|
||||||
|
|
||||||
|
import { IPreTaskFunction, PreTask } from './tapbundle.classes.pretask';
|
||||||
import { TapTest, ITestFunction } from './tapbundle.classes.taptest';
|
import { TapTest, ITestFunction } from './tapbundle.classes.taptest';
|
||||||
import { TapWrap, ITapWrapFunction } from './tapbundle.classes.tapwrap';
|
import { TapWrap, ITapWrapFunction } from './tapbundle.classes.tapwrap';
|
||||||
export class Tap {
|
export class Tap {
|
||||||
@ -7,7 +8,7 @@ export class Tap {
|
|||||||
* skips a test
|
* skips a test
|
||||||
* tests marked with tap.skip.test() are never executed
|
* tests marked with tap.skip.test() are never executed
|
||||||
*/
|
*/
|
||||||
skip = {
|
public skip = {
|
||||||
test: (descriptionArg: string, functionArg: ITestFunction) => {
|
test: (descriptionArg: string, functionArg: ITestFunction) => {
|
||||||
console.log(`skipped test: ${descriptionArg}`);
|
console.log(`skipped test: ${descriptionArg}`);
|
||||||
},
|
},
|
||||||
@ -19,12 +20,13 @@ export class Tap {
|
|||||||
/**
|
/**
|
||||||
* only executes tests marked as ONLY
|
* only executes tests marked as ONLY
|
||||||
*/
|
*/
|
||||||
only = {
|
public only = {
|
||||||
test: (descriptionArg: string, testFunctionArg: ITestFunction) => {
|
test: (descriptionArg: string, testFunctionArg: ITestFunction) => {
|
||||||
this.test(descriptionArg, testFunctionArg, 'only');
|
this.test(descriptionArg, testFunctionArg, 'only');
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
private _tapPreTasks: PreTask[] = [];
|
||||||
private _tapTests: TapTest[] = [];
|
private _tapTests: TapTest[] = [];
|
||||||
private _tapTestsOnly: TapTest[] = [];
|
private _tapTestsOnly: TapTest[] = [];
|
||||||
|
|
||||||
@ -33,14 +35,14 @@ 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
|
||||||
*/
|
*/
|
||||||
async test(
|
public async test(
|
||||||
testDescription: string,
|
testDescription: string,
|
||||||
testFunction: ITestFunction,
|
testFunction: ITestFunction,
|
||||||
modeArg: 'normal' | 'only' | 'skip' = 'normal'
|
modeArg: 'normal' | 'only' | 'skip' = 'normal'
|
||||||
) {
|
) {
|
||||||
let localTest = new TapTest({
|
const localTest = new TapTest({
|
||||||
description: testDescription,
|
description: testDescription,
|
||||||
testFunction: testFunction,
|
testFunction,
|
||||||
parallel: false
|
parallel: false
|
||||||
});
|
});
|
||||||
if (modeArg === 'normal') {
|
if (modeArg === 'normal') {
|
||||||
@ -51,10 +53,14 @@ export class Tap {
|
|||||||
return localTest;
|
return localTest;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public preTask (descriptionArg: string, functionArg: IPreTaskFunction) {
|
||||||
|
this._tapPreTasks.push(new PreTask(descriptionArg, functionArg));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* wraps function
|
* wraps function
|
||||||
*/
|
*/
|
||||||
wrap(functionArg: ITapWrapFunction) {
|
public wrap(functionArg: ITapWrapFunction) {
|
||||||
return new TapWrap(functionArg);
|
return new TapWrap(functionArg);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -63,11 +69,11 @@ 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
|
||||||
*/
|
*/
|
||||||
testParallel(testDescription: string, testFunction: ITestFunction) {
|
public testParallel(testDescription: string, testFunction: ITestFunction) {
|
||||||
this._tapTests.push(
|
this._tapTests.push(
|
||||||
new TapTest({
|
new TapTest({
|
||||||
description: testDescription,
|
description: testDescription,
|
||||||
testFunction: testFunction,
|
testFunction,
|
||||||
parallel: true
|
parallel: true
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
@ -76,12 +82,18 @@ export class Tap {
|
|||||||
/**
|
/**
|
||||||
* starts the test evaluation
|
* starts the test evaluation
|
||||||
*/
|
*/
|
||||||
async start(optionsArg?: { throwOnError: boolean }) {
|
public async start(optionsArg?: { throwOnError: boolean }) {
|
||||||
let promiseArray: Promise<any>[] = [];
|
// lets set the tapbundle promise
|
||||||
|
const smartenvInstance = new plugins.smartenv.Smartenv();
|
||||||
|
smartenvInstance.isBrowser ? globalThis.tapbundleDeferred = plugins.smartpromise.defer() : null;
|
||||||
|
|
||||||
|
// lets continue with running the tests
|
||||||
|
const promiseArray: Array<Promise<any>> = [];
|
||||||
|
|
||||||
// safeguard against empty test array
|
// safeguard against empty test array
|
||||||
if (this._tapTests.length === 0) {
|
if (this._tapTests.length === 0) {
|
||||||
console.log('no tests specified. Ending here!');
|
console.log('no tests specified. Ending here!');
|
||||||
|
// TODO: throw proper error
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -93,10 +105,15 @@ export class Tap {
|
|||||||
concerningTests = this._tapTests;
|
concerningTests = this._tapTests;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// lets run the pretasks
|
||||||
|
for (const preTask of this._tapPreTasks) {
|
||||||
|
await preTask.run();
|
||||||
|
}
|
||||||
|
|
||||||
console.log(`1..${concerningTests.length}`);
|
console.log(`1..${concerningTests.length}`);
|
||||||
for (let testKey = 0; testKey < concerningTests.length; testKey++) {
|
for (let testKey = 0; testKey < concerningTests.length; testKey++) {
|
||||||
let currentTest = concerningTests[testKey];
|
const currentTest = concerningTests[testKey];
|
||||||
let testPromise = currentTest.run(testKey);
|
const testPromise = currentTest.run(testKey);
|
||||||
if (currentTest.parallel) {
|
if (currentTest.parallel) {
|
||||||
promiseArray.push(testPromise);
|
promiseArray.push(testPromise);
|
||||||
} else {
|
} else {
|
||||||
@ -106,10 +123,10 @@ export class Tap {
|
|||||||
await Promise.all(promiseArray);
|
await Promise.all(promiseArray);
|
||||||
|
|
||||||
// when tests have been run and all promises are fullfilled
|
// when tests have been run and all promises are fullfilled
|
||||||
let failReasons: string[] = [];
|
const failReasons: string[] = [];
|
||||||
let executionNotes: string[] = [];
|
const executionNotes: string[] = [];
|
||||||
// collect failed tests
|
// collect failed tests
|
||||||
for (let tapTest of concerningTests) {
|
for (const tapTest of concerningTests) {
|
||||||
if (tapTest.status !== 'success') {
|
if (tapTest.status !== 'success') {
|
||||||
failReasons.push(
|
failReasons.push(
|
||||||
`Test ${tapTest.testKey + 1} failed with status ${tapTest.status}:\n` +
|
`Test ${tapTest.testKey + 1} failed with status ${tapTest.status}:\n` +
|
||||||
@ -120,7 +137,7 @@ export class Tap {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// render fail Reasons
|
// render fail Reasons
|
||||||
for (let failReason of failReasons) {
|
for (const failReason of failReasons) {
|
||||||
console.log(failReason);
|
console.log(failReason);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -132,7 +149,7 @@ export class Tap {
|
|||||||
/**
|
/**
|
||||||
* handle errors
|
* handle errors
|
||||||
*/
|
*/
|
||||||
threw(err) {
|
public threw(err) {
|
||||||
console.log(err);
|
console.log(err);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,27 +3,25 @@ import { tapCreator } from './tapbundle.tapcreator';
|
|||||||
import { TapTools } from './tapbundle.classes.taptools';
|
import { TapTools } from './tapbundle.classes.taptools';
|
||||||
|
|
||||||
// imported interfaces
|
// imported interfaces
|
||||||
import { HrtMeasurement } from '@pushrocks/early';
|
|
||||||
import { Deferred } from '@pushrocks/smartpromise';
|
import { Deferred } from '@pushrocks/smartpromise';
|
||||||
|
import { HrtMeasurement } from '@pushrocks/smarttime';
|
||||||
|
|
||||||
// interfaces
|
// interfaces
|
||||||
export type TTestStatus = 'success' | 'error' | 'pending' | 'errorAfterSuccess' | 'timeout';
|
export type TTestStatus = 'success' | 'error' | 'pending' | 'errorAfterSuccess' | 'timeout';
|
||||||
|
|
||||||
export interface ITestFunction {
|
export type ITestFunction = (tapTools?: TapTools) => Promise<any>;
|
||||||
(tapTools?: TapTools): Promise<any>;
|
|
||||||
}
|
|
||||||
|
|
||||||
export class TapTest {
|
export class TapTest {
|
||||||
description: string;
|
public description: string;
|
||||||
failureAllowed: boolean;
|
public failureAllowed: boolean;
|
||||||
hrtMeasurement: HrtMeasurement;
|
public hrtMeasurement: HrtMeasurement;
|
||||||
parallel: boolean;
|
public parallel: boolean;
|
||||||
status: TTestStatus;
|
public status: TTestStatus;
|
||||||
tapTools: TapTools;
|
public tapTools: TapTools;
|
||||||
testFunction: ITestFunction;
|
public testFunction: ITestFunction;
|
||||||
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()
|
||||||
testDeferred: Deferred<TapTest> = plugins.smartpromise.defer();
|
public testDeferred: Deferred<TapTest> = plugins.smartpromise.defer();
|
||||||
testPromise: Promise<TapTest> = this.testDeferred.promise;
|
public testPromise: Promise<TapTest> = this.testDeferred.promise;
|
||||||
/**
|
/**
|
||||||
* constructor
|
* constructor
|
||||||
*/
|
*/
|
||||||
@ -39,11 +37,12 @@ export class TapTest {
|
|||||||
/**
|
/**
|
||||||
* run the test
|
* run the test
|
||||||
*/
|
*/
|
||||||
async run(testKeyArg: number) {
|
public async run(testKeyArg: number) {
|
||||||
this.hrtMeasurement.start();
|
this.hrtMeasurement.start();
|
||||||
this.testKey = testKeyArg;
|
this.testKey = testKeyArg;
|
||||||
let testNumber = testKeyArg + 1;
|
const testNumber = testKeyArg + 1;
|
||||||
try {
|
try {
|
||||||
|
|
||||||
await this.testFunction(this.tapTools);
|
await this.testFunction(this.tapTools);
|
||||||
if (this.status === 'timeout') {
|
if (this.status === 'timeout') {
|
||||||
throw new Error('Test succeeded, but timed out...');
|
throw new Error('Test succeeded, but timed out...');
|
||||||
|
@ -19,6 +19,7 @@ export class TapWrap {
|
|||||||
* run the wrapFunction
|
* run the wrapFunction
|
||||||
*/
|
*/
|
||||||
async run() {
|
async run() {
|
||||||
|
// TODO: make sure it makes sense what we do here.
|
||||||
await this.wrapFunction();
|
await this.wrapFunction();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
// pushrocks
|
// pushrocks
|
||||||
import * as early from '@pushrocks/early';
|
|
||||||
import * as smartdelay from '@pushrocks/smartdelay';
|
import * as smartdelay from '@pushrocks/smartdelay';
|
||||||
|
import * as smartenv from '@pushrocks/smartenv';
|
||||||
import * as smartpromise from '@pushrocks/smartpromise';
|
import * as smartpromise from '@pushrocks/smartpromise';
|
||||||
|
|
||||||
export { early, smartdelay, smartpromise };
|
export { smartdelay, smartenv, smartpromise };
|
||||||
|
|
||||||
// third party
|
// third party
|
||||||
/* import * as leakage from 'leakage';
|
/* import * as leakage from 'leakage';
|
||||||
|
Reference in New Issue
Block a user