tapbundle/dist/tapbundle.tap.js

114 lines
7.0 KiB
JavaScript
Raw Normal View History

2017-04-23 09:10:13 +00:00
"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 });
class TapTest {
/**
* constructor
*/
constructor(optionsArg) {
this.description = optionsArg.description;
this.testFunction = optionsArg.testFunction;
this.parallel = optionsArg.parallel;
this.status = 'pending';
}
/**
* run the test
*/
run(testKeyArg) {
return __awaiter(this, void 0, void 0, function* () {
try {
yield this.testFunction();
2017-04-23 12:35:16 +00:00
console.log(`ok ${testKeyArg + 1} - ${this.description} # time=20.040ms`);
this.status = 'success';
2017-04-23 09:10:13 +00:00
}
catch (err) {
2017-04-23 12:35:16 +00:00
console.log(`not ok ${testKeyArg + 1} - ${this.description} # time=20.040ms`);
if (this.status === 'success') {
this.status = 'errorAfterSuccess';
console.log('!!! ALERT !!!: weird behaviour, since test has been already successfull');
}
2017-04-23 09:10:13 +00:00
console.log(err);
}
});
}
}
exports.TapTest = TapTest;
class Tap {
constructor() {
this._tests = [];
}
2017-04-23 12:35:16 +00:00
/**
* 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
*/
2017-04-23 09:10:13 +00:00
test(testDescription, testFunction) {
return __awaiter(this, void 0, void 0, function* () {
this._tests.push(new TapTest({
description: testDescription,
testFunction: testFunction,
parallel: false
}));
});
}
2017-04-23 12:35:16 +00:00
/**
* 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
*/
2017-04-23 09:10:13 +00:00
testParallel(testDescription, testFunction) {
this._tests.push(new TapTest({
description: testDescription,
testFunction: testFunction,
parallel: true
}));
}
2017-04-23 12:35:16 +00:00
/**
* 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) {
}
2017-04-23 09:10:13 +00:00
/**
* 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();
2017-04-23 12:35:16 +00:00
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidGFwYnVuZGxlLnRhcC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL3RhcGJ1bmRsZS50YXAudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7Ozs7Ozs7OztBQVlBO0lBT0U7O09BRUc7SUFDSCxZQUFhLFVBSVo7UUFDQyxJQUFJLENBQUMsV0FBVyxHQUFHLFVBQVUsQ0FBQyxXQUFXLENBQUE7UUFDekMsSUFBSSxDQUFDLFlBQVksR0FBRyxVQUFVLENBQUMsWUFBWSxDQUFBO1FBQzNDLElBQUksQ0FBQyxRQUFRLEdBQUcsVUFBVSxDQUFDLFFBQVEsQ0FBQTtRQUNuQyxJQUFJLENBQUMsTUFBTSxHQUFHLFNBQVMsQ0FBQTtJQUN6QixDQUFDO0lBRUQ7O09BRUc7SUFDRyxHQUFHLENBQUUsVUFBa0I7O1lBQzNCLElBQUksQ0FBQztnQkF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