diff --git a/dist/index.d.ts b/dist/index.d.ts index b3e321b..fbcea5e 100644 --- a/dist/index.d.ts +++ b/dist/index.d.ts @@ -1,4 +1,4 @@ import 'typings-global'; import { expect } from 'smartchai'; -import { tap } from './tapbundle.tap'; +import { tap } from './tapbundle.classes.tap'; export { tap, expect }; diff --git a/dist/index.js b/dist/index.js index 4c15298..cca1728 100644 --- a/dist/index.js +++ b/dist/index.js @@ -3,6 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true }); require("typings-global"); const smartchai_1 = require("smartchai"); exports.expect = smartchai_1.expect; -const tapbundle_tap_1 = require("./tapbundle.tap"); -exports.tap = tapbundle_tap_1.tap; -//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOztBQUFBLDBCQUF1QjtBQUN2Qix5Q0FBa0M7QUFNaEMsaUJBTk8sa0JBQU0sQ0FNUDtBQUxSLG1EQUFxQztBQUluQyxjQUpPLG1CQUFHLENBSVAifQ== \ No newline at end of file +const tapbundle_classes_tap_1 = require("./tapbundle.classes.tap"); +exports.tap = tapbundle_classes_tap_1.tap; +//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOztBQUFBLDBCQUF1QjtBQUN2Qix5Q0FBa0M7QUFNaEMsb0NBQU07QUFMUixtRUFBNkM7QUFJM0MsMENBQUcifQ== \ No newline at end of file diff --git a/dist/tapbundle.tap.d.ts b/dist/tapbundle.classes.tap.d.ts similarity index 63% rename from dist/tapbundle.tap.d.ts rename to dist/tapbundle.classes.tap.d.ts index bc1b4aa..b793d62 100644 --- a/dist/tapbundle.tap.d.ts +++ b/dist/tapbundle.classes.tap.d.ts @@ -1,27 +1,4 @@ -import { HrtMeasurement } from 'early'; -export declare type TTestStatus = 'success' | 'error' | 'pending' | 'errorAfterSuccess'; -export interface ITestFunction { - (): Promise; -} -export declare class TapTest { - description: string; - parallel: boolean; - hrtMeasurement: HrtMeasurement; - testFunction: ITestFunction; - status: TTestStatus; - /** - * constructor - */ - constructor(optionsArg: { - description: string; - testFunction: ITestFunction; - parallel: boolean; - }); - /** - * run the test - */ - run(testKeyArg: number): Promise; -} +import { TapTest, ITestFunction } from './tapbundle.classes.taptest'; export declare class Tap { private _tests; /** @@ -29,7 +6,7 @@ export declare class Tap { * @param testDescription - A description of what the test does * @param testFunction - A Function that returns a Promise and resolves or rejects */ - test(testDescription: string, testFunction: ITestFunction): Promise; + test(testDescription: string, testFunction: ITestFunction): Promise; /** * A parallel test that will not be waited for before the next starts. * @param testDescription - A description of what the test does diff --git a/dist/tapbundle.classes.tap.js b/dist/tapbundle.classes.tap.js new file mode 100644 index 0000000..0e8eea8 --- /dev/null +++ b/dist/tapbundle.classes.tap.js @@ -0,0 +1,85 @@ +"use strict"; +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; +Object.defineProperty(exports, "__esModule", { value: true }); +const tapbundle_classes_taptest_1 = require("./tapbundle.classes.taptest"); +class Tap { + constructor() { + this._tests = []; + } + /** + * Normal test function, will run one by one + * @param testDescription - A description of what the test does + * @param testFunction - A Function that returns a Promise and resolves or rejects + */ + test(testDescription, testFunction) { + return __awaiter(this, void 0, void 0, function* () { + let localTest = new tapbundle_classes_taptest_1.TapTest({ + description: testDescription, + testFunction: testFunction, + parallel: false + }); + this._tests.push(localTest); + return localTest; + }); + } + /** + * A parallel test that will not be waited for before the next starts. + * @param testDescription - A description of what the test does + * @param testFunction - A Function that returns a Promise and resolves or rejects + */ + testParallel(testDescription, testFunction) { + this._tests.push(new tapbundle_classes_taptest_1.TapTest({ + description: testDescription, + testFunction: testFunction, + parallel: true + })); + } + /** + * tests leakage + * @param testDescription - A description of what the test does + * @param testFunction - A Function that returns a Promise and resolves or rejects + */ + testLeakage(testDescription, testFunction) { + } + /** + * starts the test evaluation + */ + start() { + return __awaiter(this, void 0, void 0, function* () { + let promiseArray = []; + // safeguard against empty test array + if (this._tests.length === 0) { + console.log('no tests specified. Ending here!'); + return; + } + console.log(`1..${this._tests.length}`); + for (let testKey = 0; testKey < this._tests.length; testKey++) { + let currentTest = this._tests[testKey]; + let testPromise = currentTest.run(testKey); + if (currentTest.parallel) { + promiseArray.push(testPromise); + } + else { + yield testPromise; + } + } + yield Promise.all(promiseArray); + }); + } + /** + * handle errors + */ + threw(err) { + console.log(err); + } +} +exports.Tap = Tap; +exports.tap = new Tap(); +//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidGFwYnVuZGxlLmNsYXNzZXMudGFwLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHMvdGFwYnVuZGxlLmNsYXNzZXMudGFwLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7Ozs7Ozs7Ozs7QUFFQSwyRUFBb0U7QUFFcEU7SUFBQTtRQUNVLFdBQU0sR0FBYyxFQUFFLENBQUE7SUFzRWhDLENBQUM7SUFwRUM7Ozs7T0FJRztJQUNHLElBQUksQ0FBRSxlQUF1QixFQUFFLFlBQTJCOztZQUM5RCxJQUFJLFNBQVMsR0FBRyxJQUFJLG1DQUFPLENBQUM7Z0JBQzFCLFdBQVcsRUFBRSxlQUFlO2dCQUM1QixZQUFZLEVBQUUsWUFBWTtnQkFDMUIs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QUFHLElBQUksQ0FBQyxNQUFNLENBQUMsT0FBTyxDQUFDLENBQUE7Z0JBQ3RDLElBQUksV0FBVyxHQUFHLFdBQVcsQ0FBQyxHQUFHLENBQUMsT0FBTyxDQUFDLENBQUE7Z0JBQzFDLEVBQUUsQ0FBQyxDQUFDLFdBQVcsQ0FBQyxRQUFRLENBQUMsQ0FBQyxDQUFDO29CQUN6QixZQUFZLENBQUMsSUFBSSxDQUFDLFdBQVcsQ0FBQyxDQUFBO2dCQUNoQyxDQUFDO2dCQUFDLElBQUksQ0FBQyxDQUFDO29CQUNOLE1BQU0sV0FBVyxDQUFBO2dCQUNuQixDQUFDO1lBQ0gsQ0FBQztZQUNELE1BQU0sT0FBTyxDQUFDLEdBQUcsQ0FBQyxZQUFZLENBQUMsQ0FBQTtRQUNqQyxDQUFDO0tBQUE7SUFFRDs7T0FFRztJQUNILEtBQUssQ0FBRSxHQUFHO1FBQ1IsT0FBTyxDQUFDLEdBQUcsQ0FBQyxHQUFHLENBQUMsQ0FBQTtJQUNsQixDQUFDO0NBQ0Y7QUF2RUQsa0JBdUVDO0FBRVUsUUFBQSxHQUFHLEdBQUcsSUFBSSxHQUFHLEVBQUUsQ0FBQSJ9 \ No newline at end of file diff --git a/dist/tapbundle.classes.taptest.d.ts b/dist/tapbundle.classes.taptest.d.ts new file mode 100644 index 0000000..22bd02a --- /dev/null +++ b/dist/tapbundle.classes.taptest.d.ts @@ -0,0 +1,27 @@ +import { TapTools } from './tapbundle.classes.taptools'; +import { HrtMeasurement } from 'early'; +export declare type TTestStatus = 'success' | 'error' | 'pending' | 'errorAfterSuccess' | 'timeout'; +export interface ITestFunction { + (tapTools?: TapTools): Promise; +} +export declare class TapTest { + description: string; + failureAllowed: boolean; + hrtMeasurement: HrtMeasurement; + parallel: boolean; + status: TTestStatus; + tapTools: TapTools; + testFunction: ITestFunction; + /** + * constructor + */ + constructor(optionsArg: { + description: string; + testFunction: ITestFunction; + parallel: boolean; + }); + /** + * run the test + */ + run(testKeyArg: number): Promise; +} diff --git a/dist/tapbundle.classes.taptest.js b/dist/tapbundle.classes.taptest.js new file mode 100644 index 0000000..6038beb --- /dev/null +++ b/dist/tapbundle.classes.taptest.js @@ -0,0 +1,57 @@ +"use strict"; +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; +Object.defineProperty(exports, "__esModule", { value: true }); +const tapbundle_classes_taptools_1 = require("./tapbundle.classes.taptools"); +// imported interfaces +const early_1 = require("early"); +class TapTest { + /** + * constructor + */ + constructor(optionsArg) { + this.description = optionsArg.description; + this.hrtMeasurement = new early_1.HrtMeasurement(); + this.parallel = optionsArg.parallel; + this.status = 'pending'; + this.tapTools = new tapbundle_classes_taptools_1.TapTools(this); + this.testFunction = optionsArg.testFunction; + } + /** + * run the test + */ + run(testKeyArg) { + return __awaiter(this, void 0, void 0, function* () { + this.hrtMeasurement.start(); + try { + yield this.testFunction(this.tapTools); + if (this.status === 'timeout') { + throw new Error('Test succeeded, but timed out...'); + } + this.hrtMeasurement.stop(); + console.log(`ok ${testKeyArg + 1} - ${this.description} # time=${this.hrtMeasurement.milliSeconds}ms`); + this.status = 'success'; + } + catch (err) { + this.hrtMeasurement.stop(); + console.log(`not ok ${testKeyArg + 1} - ${this.description} # time=${this.hrtMeasurement.milliSeconds}ms`); + if (this.status === 'success') { + this.status = 'errorAfterSuccess'; + console.log('!!! ALERT !!!: weird behaviour, since test has been already successfull'); + } + if (this.failureAllowed) { + console.log(`please note: failure allowed!`); + } + console.log(err); + } + }); + } +} +exports.TapTest = TapTest; +//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJma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c9 --- /dev/null +++ b/dist/tapbundle.classes.taptools.d.ts @@ -0,0 +1,16 @@ +export declare class TapTools { + /** + * the referenced TapTest + */ + private _tapTest; + constructor(TapTestArg: any); + /** + * allow failure + */ + allowFailure(): void; + /** + * async/await delay method + */ + delayFor(timeMilliArg: any): Promise; + timeout(timeMilliArg: number): Promise; +} diff --git a/dist/tapbundle.classes.taptools.js b/dist/tapbundle.classes.taptools.js new file mode 100644 index 0000000..b5c8e23 --- /dev/null +++ b/dist/tapbundle.classes.taptools.js @@ -0,0 +1,40 @@ +"use strict"; +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; +Object.defineProperty(exports, "__esModule", { value: true }); +const plugins = require("./tapbundle.plugins"); +class TapTools { + constructor(TapTestArg) { + this._tapTest = TapTestArg; + } + /** + * allow failure + */ + allowFailure() { + this._tapTest.failureAllowed = true; + } + /** + * async/await delay method + */ + delayFor(timeMilliArg) { + return __awaiter(this, void 0, void 0, function* () { + yield plugins.smartdelay.delayFor(timeMilliArg); + }); + } + timeout(timeMilliArg) { + return __awaiter(this, void 0, void 0, function* () { + yield plugins.smartdelay.delayFor(timeMilliArg); + if (this._tapTest.status === 'pending') { + this._tapTest.status = 'timeout'; + } + }); + } +} +exports.TapTools = TapTools; +//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidGFwYnVuZGxlLmNsYXNzZXMudGFwdG9vbHMuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy90YXBidW5kbGUuY2xhc3Nlcy50YXB0b29scy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7Ozs7Ozs7O0FBQUEsK0NBQThDO0FBRzlDO0lBT0UsWUFBWSxVQUFVO1FBQ3BCLElBQUksQ0FBQyxRQUFRLEdBQUcsVUFBVSxDQUFBO0lBQzVCLENBQUM7SUFFRDs7T0FFRztJQUNILFlBQVk7UUFDVixJQUFJLENBQUMsUUFBUSxDQUFDLGNBQWMsR0FBRyxJQUFJLENBQUE7SUFDckMsQ0FBQztJQUVEOztPQUVHO0lBQ0csUUFBUSxDQUFDLFlBQVk7O1lBQ3pCLE1BQU0sT0FBTyxDQUFDLFVBQVUsQ0FBQyxRQUFRLENBQUMsWUFBWSxDQUFDLENBQUE7UUFDakQsQ0FBQztLQUFBO0lBRUssT0FBTyxDQUFFLFlBQW9COztZQUNqQyxNQUFNLE9BQU8sQ0FBQyxVQUFVLENBQUMsUUFBUSxDQUFDLFlBQVksQ0FBQyxDQUFBO1lBQy9DLEVBQUUsQ0FBQyxDQUFDLElBQUksQ0FBQyxRQUFRLENBQUMsTUFBTSxLQUFLLFNBQVMsQ0FBQyxDQUFDLENBQUM7Z0JBQ3ZDLElBQUksQ0FBQyxRQUFRLENBQUMsTUFBTSxHQUFHLFNBQVMsQ0FBQTtZQUNsQyxDQUFDO1FBQ0gsQ0FBQztLQUFBO0NBRUY7QUFoQ0QsNEJBZ0NDIn0= \ No newline at end of file diff --git a/dist/tapbundle.plugins.d.ts b/dist/tapbundle.plugins.d.ts index a98a49c..096d036 100644 --- a/dist/tapbundle.plugins.d.ts +++ b/dist/tapbundle.plugins.d.ts @@ -1,5 +1,6 @@ import 'typings-global'; import * as early from 'early'; import * as leakage from 'leakage'; +import * as smartdelay from 'smartdelay'; import * as smartq from 'smartq'; -export { early, smartq, leakage }; +export { early, smartdelay, smartq, leakage }; diff --git a/dist/tapbundle.plugins.js b/dist/tapbundle.plugins.js index a966453..542026e 100644 --- a/dist/tapbundle.plugins.js +++ b/dist/tapbundle.plugins.js @@ -5,6 +5,8 @@ const early = require("early"); exports.early = early; const leakage = require("leakage"); exports.leakage = leakage; +const smartdelay = require("smartdelay"); +exports.smartdelay = smartdelay; const smartq = require("smartq"); exports.smartq = smartq; -//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidGFwYnVuZGxlLnBsdWdpbnMuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy90YXBidW5kbGUucGx1Z2lucy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOztBQUFBLDBCQUF1QjtBQUN2QiwrQkFBOEI7QUFLNUIsc0JBQUs7QUFKUCxtQ0FBa0M7QUFNaEMsMEJBQU87QUFMVCxpQ0FBZ0M7QUFJOUIsd0JBQU0ifQ== \ No newline at end of file +//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidGFwYnVuZGxlLnBsdWdpbnMuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy90YXBidW5kbGUucGx1Z2lucy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOztBQUFBLDBCQUF1QjtBQUN2QiwrQkFBOEI7QUFNNUIsc0JBQUs7QUFMUCxtQ0FBa0M7QUFRaEMsMEJBQU87QUFQVCx5Q0FBd0M7QUFLdEMsZ0NBQVU7QUFKWixpQ0FBZ0M7QUFLOUIsd0JBQU0ifQ== \ No newline at end of file diff --git a/dist/tapbundle.tap.js b/dist/tapbundle.tap.js deleted file mode 100644 index c4c8e40..0000000 --- a/dist/tapbundle.tap.js +++ /dev/null @@ -1,120 +0,0 @@ -"use strict"; -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -Object.defineProperty(exports, "__esModule", { value: true }); -// imported interfaces -const early_1 = require("early"); -class TapTest { - /** - * constructor - */ - constructor(optionsArg) { - this.description = optionsArg.description; - this.testFunction = optionsArg.testFunction; - this.parallel = optionsArg.parallel; - this.status = 'pending'; - this.hrtMeasurement = new early_1.HrtMeasurement(); - } - /** - * run the test - */ - run(testKeyArg) { - return __awaiter(this, void 0, void 0, function* () { - this.hrtMeasurement.start(); - try { - yield this.testFunction(); - this.hrtMeasurement.stop(); - console.log(`ok ${testKeyArg + 1} - ${this.description} # time=${this.hrtMeasurement.milliSeconds}ms`); - this.status = 'success'; - } - catch (err) { - this.hrtMeasurement.stop(); - console.log(`not ok ${testKeyArg + 1} - ${this.description} # time=${this.hrtMeasurement.milliSeconds}ms`); - if (this.status === 'success') { - this.status = 'errorAfterSuccess'; - console.log('!!! ALERT !!!: weird behaviour, since test has been already successfull'); - } - console.log(err); - } - }); - } -} -exports.TapTest = TapTest; -class Tap { - constructor() { - this._tests = []; - } - /** - * Normal test function, will run one by one - * @param testDescription - A description of what the test does - * @param testFunction - A Function that returns a Promise and resolves or rejects - */ - test(testDescription, testFunction) { - return __awaiter(this, void 0, void 0, function* () { - this._tests.push(new TapTest({ - description: testDescription, - testFunction: testFunction, - parallel: false - })); - }); - } - /** - * A parallel test that will not be waited for before the next starts. - * @param testDescription - A description of what the test does - * @param testFunction - A Function that returns a Promise and resolves or rejects - */ - testParallel(testDescription, testFunction) { - this._tests.push(new TapTest({ - description: testDescription, - testFunction: testFunction, - parallel: true - })); - } - /** - * tests leakage - * @param testDescription - A description of what the test does - * @param testFunction - A Function that returns a Promise and resolves or rejects - */ - testLeakage(testDescription, testFunction) { - } - /** - * starts the test evaluation - */ - start() { - return __awaiter(this, void 0, void 0, function* () { - let promiseArray = []; - // safeguard against empty test array - if (this._tests.length === 0) { - console.log('no tests specified. Ending here!'); - return; - } - console.log(`1..${this._tests.length}`); - for (let testKey = 0; testKey < this._tests.length; testKey++) { - let currentTest = this._tests[testKey]; - let testPromise = currentTest.run(testKey); - if (currentTest.parallel) { - promiseArray.push(testPromise); - } - else { - yield testPromise; - } - } - yield Promise.all(promiseArray); - }); - } - /** - * handle errors - */ - threw(err) { - console.log(err); - } -} -exports.Tap = Tap; -exports.tap = new Tap(); -//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidGFwYnVuZGxlLnRhcC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL3RhcGJ1bmRsZS50YXAudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7Ozs7Ozs7OztBQUlBLHNCQUFzQjtBQUN0QixpQ0FBc0M7QUFVdEM7SUFPRTs7T0FFRztJQUNILFlBQWEsVUFJWjtRQUNDLElBQUksQ0FBQyxXQUFXLEdBQUcsVUFBVSxDQUFDLFdBQVcsQ0FBQTtRQUN6QyxJQUFJLENBQUMsWUFBWSxHQUFHLFVBQVUsQ0FBQyxZQUFZLENBQUE7UUFDM0MsSUFBSSxDQUFDLFFBQVEsR0FBRyxVQUFVLENBQUMsUUFBUSxDQUFBO1FBQ25DLElBQUksQ0FBQyxNQUFNLEdBQUcsU0FBUyxDQUFBO1FBQ3ZCLElBQUksQ0FBQyxjQUFjLEdBQUcsSUFBSSxzQkFBYyxFQUFFLENBQUE7SUFDNUMsQ0FBQztJQUVEOztPQUVHO0lBQ0csR0FBRyxDQUFFLFVBQWtCOztZQUMzQixJQUFJLENBQUMsY0FBYyxDQUFDLEtBQUssRUFBRSxDQUFBO1lBQzNCLElBQUksQ0FBQztnQkFDSCxNQUFNLElBQUksQ0FBQyxZQUFZLEVBQUUsQ0FBQTtnQkFDekIsSUFBSSxDQUFDLGNBQWMsQ0FBQyxJQUFJLEVBQUUsQ0FBQTtnQkFDMUIsT0FBTyxDQUFDLEdBQUcsQ0FBQyxNQUFNLFVBQVUsR0FBRyxDQUFDLE1BQU0sSUFBSS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FdBQVcsQ0FBQyxRQUFRLENBQUMsQ0FBQyxDQUFDO29CQUN6QixZQUFZLENBQUMsSUFBSSxDQUFDLFdBQVcsQ0FBQyxDQUFBO2dCQUNoQyxDQUFDO2dCQUFDLElBQUksQ0FBQyxDQUFDO29CQUNOLE1BQU0sV0FBVyxDQUFBO2dCQUNuQixDQUFDO1lBQ0gsQ0FBQztZQUNELE1BQU0sT0FBTyxDQUFDLEdBQUcsQ0FBQyxZQUFZLENBQUMsQ0FBQTtRQUNqQyxDQUFDO0tBQUE7SUFFRDs7T0FFRztJQUNILEtBQUssQ0FBRSxHQUFHO1FBQ1IsT0FBTyxDQUFDLEdBQUcsQ0FBQyxHQUFHLENBQUMsQ0FBQTtJQUNsQixDQUFDO0NBQ0Y7QUFyRUQsa0JBcUVDO0FBRVUsUUFBQSxHQUFHLEdBQUcsSUFBSSxHQUFHLEVBQUUsQ0FBQSJ9 \ No newline at end of file diff --git a/package.json b/package.json index b409758..4eb087c 100644 --- a/package.json +++ b/package.json @@ -21,6 +21,7 @@ "early": "^2.1.1", "leakage": "^0.2.0", "smartchai": "^1.0.3", + "smartdelay": "^1.0.1", "smartq": "^1.1.1", "typings-global": "^1.0.16" } diff --git a/test/test.ts b/test/test.ts index 06f31ec..02553e8 100644 --- a/test/test.ts +++ b/test/test.ts @@ -1,7 +1,32 @@ import { tap, expect } from '../dist/index' -tap.test('my first test', async () => { +let test1 = tap.test('my first test -> expect true to be true', async () => { return expect(true).to.be.true }) +let test2 = tap.test('my second test', async (tools) => { + await tools.delayFor(1000) +}) + +let 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 > 1000).to.be.true +}) + +let test4 = tap.test('my 4th test -> should fail', async (tools) => { + tools.allowFailure() + expect(false).to.be.true +}) + +let test5 = tap.test('my 5th test -> should pass in about 500ms', async (tools) => { + tools.timeout(1000) + await tools.delayFor(500) +}) + +let test6 = tap.test('my 6th test -> should fail after 1000ms', async (tools) => { + tools.allowFailure() + tools.timeout(1000) + await tools.delayFor(2000) +}) + tap.start() diff --git a/ts/index.ts b/ts/index.ts index c432d86..1f1000a 100644 --- a/ts/index.ts +++ b/ts/index.ts @@ -1,6 +1,6 @@ import 'typings-global' import { expect } from 'smartchai' -import { tap } from './tapbundle.tap' +import { tap } from './tapbundle.classes.tap' export { diff --git a/ts/tapbundle.tap.ts b/ts/tapbundle.classes.tap.ts similarity index 55% rename from ts/tapbundle.tap.ts rename to ts/tapbundle.classes.tap.ts index 37a343b..ab01142 100644 --- a/ts/tapbundle.tap.ts +++ b/ts/tapbundle.classes.tap.ts @@ -1,61 +1,6 @@ import * as plugins from './tapbundle.plugins' -import { tapCreator } from './tapbundle.tapcreator' - -// imported interfaces -import { HrtMeasurement } from 'early' - -// interfaces -export type TTestStatus = 'success' | 'error' | 'pending' | 'errorAfterSuccess' - -export interface ITestFunction { - (): Promise -} - - -export class TapTest { - description: string - parallel: boolean - hrtMeasurement: HrtMeasurement - testFunction: ITestFunction - status: TTestStatus - - /** - * constructor - */ - constructor (optionsArg: { - description: string, - testFunction: ITestFunction, - parallel: boolean - }) { - this.description = optionsArg.description - this.testFunction = optionsArg.testFunction - this.parallel = optionsArg.parallel - this.status = 'pending' - this.hrtMeasurement = new HrtMeasurement() - } - - /** - * run the test - */ - async run (testKeyArg: number) { - this.hrtMeasurement.start() - try { - await this.testFunction() - this.hrtMeasurement.stop() - console.log(`ok ${testKeyArg + 1} - ${this.description} # time=${this.hrtMeasurement.milliSeconds}ms`) - this.status = 'success' - } catch (err) { - this.hrtMeasurement.stop() - console.log(`not ok ${testKeyArg + 1} - ${this.description} # time=${this.hrtMeasurement.milliSeconds}ms`) - if (this.status === 'success') { - this.status = 'errorAfterSuccess' - console.log('!!! ALERT !!!: weird behaviour, since test has been already successfull') - } - console.log(err) - } - } -} +import { TapTest, ITestFunction } from './tapbundle.classes.taptest' export class Tap { private _tests: TapTest[] = [] @@ -66,11 +11,13 @@ export class Tap { * @param testFunction - A Function that returns a Promise and resolves or rejects */ async test (testDescription: string, testFunction: ITestFunction) { - this._tests.push(new TapTest({ + let localTest = new TapTest({ description: testDescription, testFunction: testFunction, parallel: false - })) + }) + this._tests.push(localTest) + return localTest } /** diff --git a/ts/tapbundle.classes.taptest.ts b/ts/tapbundle.classes.taptest.ts new file mode 100644 index 0000000..6591eaf --- /dev/null +++ b/ts/tapbundle.classes.taptest.ts @@ -0,0 +1,65 @@ +import { tapCreator } from './tapbundle.tapcreator' +import { TapTools } from './tapbundle.classes.taptools' + +// imported interfaces +import { HrtMeasurement } from 'early' + +// interfaces +export type TTestStatus = 'success' | 'error' | 'pending' | 'errorAfterSuccess' | 'timeout' + +export interface ITestFunction { + (tapTools?: TapTools): Promise +} + + +export class TapTest { + description: string + failureAllowed: boolean + hrtMeasurement: HrtMeasurement + parallel: boolean + status: TTestStatus + tapTools: TapTools + testFunction: ITestFunction + /** + * constructor + */ + constructor (optionsArg: { + description: string, + testFunction: ITestFunction, + parallel: boolean + }) { + this.description = optionsArg.description + this.hrtMeasurement = new HrtMeasurement() + this.parallel = optionsArg.parallel + this.status = 'pending' + this.tapTools = new TapTools(this) + this.testFunction = optionsArg.testFunction + } + + /** + * run the test + */ + async run (testKeyArg: number) { + this.hrtMeasurement.start() + try { + await this.testFunction(this.tapTools) + if (this.status === 'timeout') { + throw new Error ('Test succeeded, but timed out...') + } + this.hrtMeasurement.stop() + console.log(`ok ${testKeyArg + 1} - ${this.description} # time=${this.hrtMeasurement.milliSeconds}ms`) + this.status = 'success' + } catch (err) { + this.hrtMeasurement.stop() + console.log(`not ok ${testKeyArg + 1} - ${this.description} # time=${this.hrtMeasurement.milliSeconds}ms`) + if (this.status === 'success') { + this.status = 'errorAfterSuccess' + console.log('!!! ALERT !!!: weird behaviour, since test has been already successfull') + } + if(this.failureAllowed) { + console.log(`please note: failure allowed!`) + } + console.log(err) + } + } +} diff --git a/ts/tapbundle.classes.taptools.ts b/ts/tapbundle.classes.taptools.ts new file mode 100644 index 0000000..e3b0b6a --- /dev/null +++ b/ts/tapbundle.classes.taptools.ts @@ -0,0 +1,36 @@ +import * as plugins from './tapbundle.plugins' +import { TapTest } from './tapbundle.classes.taptest' + +export class TapTools { + + /** + * the referenced TapTest + */ + private _tapTest: TapTest + + constructor(TapTestArg) { + this._tapTest = TapTestArg + } + + /** + * allow failure + */ + allowFailure() { + this._tapTest.failureAllowed = true + } + + /** + * async/await delay method + */ + async delayFor(timeMilliArg) { + await plugins.smartdelay.delayFor(timeMilliArg) + } + + async timeout (timeMilliArg: number) { + await plugins.smartdelay.delayFor(timeMilliArg) + if (this._tapTest.status === 'pending') { + this._tapTest.status = 'timeout' + } + } + +} diff --git a/ts/tapbundle.plugins.ts b/ts/tapbundle.plugins.ts index b160e46..a9a89d5 100644 --- a/ts/tapbundle.plugins.ts +++ b/ts/tapbundle.plugins.ts @@ -1,10 +1,12 @@ import 'typings-global' import * as early from 'early' import * as leakage from 'leakage' +import * as smartdelay from 'smartdelay' import * as smartq from 'smartq' export { early, + smartdelay, smartq, leakage } diff --git a/yarn.lock b/yarn.lock index bf2228b..0d36596 100644 --- a/yarn.lock +++ b/yarn.lock @@ -210,6 +210,12 @@ smartchai@^1.0.3: chai-as-promised "^6.0.0" chai-string "^1.3.0" +smartdelay@^1.0.1: + version "1.0.1" + resolved "https://registry.yarnpkg.com/smartdelay/-/smartdelay-1.0.1.tgz#687f8bcc09d7c62c9c5a8a1771c1aba3aff54156" + dependencies: + typings-global "^1.0.14" + smartq@^1.1.1: version "1.1.1" resolved "https://registry.yarnpkg.com/smartq/-/smartq-1.1.1.tgz#efb358705260d41ae18aef7ffd815f7b6fe17dd3"