"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,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidGFwYnVuZGxlLnRhcC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL3RhcGJ1bmRsZS50YXAudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7Ozs7Ozs7OztBQUlBLHNCQUFzQjtBQUN0QixpQ0FBc0M7QUFVdEM7SUFPRTs7T0FFRztJQUNILFlBQWEsVUFJWjtRQUNDLElBQUksQ0FBQyxXQUFXLEdBQUcsVUFBVSxDQUFDLFdBQVcsQ0FBQTtRQUN6QyxJQUFJLENBQUMsWUFBWSxHQUFHLFVBQVUsQ0FBQyxZQUFZLENBQUE7UUFDM0MsSUFBSSxDQUFDLFFBQVEsR0FBRyxVQUFVLENBQUMsUUFBUSxDQUFBO1FBQ25DLElBQUksQ0FBQyxNQUFNLEdBQUcsU0FBUyxDQUFBO1FBQ3ZCLElBQUksQ0FBQyxjQUFjLEdBQUcsSUFBSSxzQkFBYyxFQUFFLENBQUE7SUFDNUMsQ0FBQztJQUVEOztPQUVHO0lBQ0csR0FBRyxDQUFFLFVBQWtCOztZQUMzQixJQUFJLENBQUMsY0FBYyxDQUFDLEtBQUssRUFBRSxDQUFBO1lBQzNCLElBQUksQ0FBQztnQkFDSCxNQUFNLElBQUksQ0FBQyxZQUFZLEVBQUUsQ0FBQTtnQkFDekIsSUFBSSxDQUFDLGNBQWMsQ0FBQyxJQUFJLEVBQ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