tapbundle/dist/tapbundle.tap.js

91 lines
5.4 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();
console.log(`ok ${testKeyArg + 1} - ${this.description}`);
}
catch (err) {
console.log(err);
}
});
}
}
exports.TapTest = TapTest;
class Tap {
constructor() {
this._tests = [];
}
test(testDescription, testFunction) {
return __awaiter(this, void 0, void 0, function* () {
this._tests.push(new TapTest({
description: testDescription,
testFunction: testFunction,
parallel: false
}));
});
}
testParallel(testDescription, testFunction) {
this._tests.push(new TapTest({
description: testDescription,
testFunction: testFunction,
parallel: true
}));
}
/**
* 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,eyJ2ZXJza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