tapbundle/dist/tapbundle.classes.tap.js

118 lines
7.6 KiB
JavaScript
Raw Normal View History

2017-04-28 07:49:57 +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 });
const tapbundle_classes_taptest_1 = require("./tapbundle.classes.taptest");
2017-07-05 22:06:18 +00:00
const tapbundle_classes_tapwrap_1 = require("./tapbundle.classes.tapwrap");
2017-04-28 07:49:57 +00:00
class Tap {
constructor() {
2017-07-05 22:06:18 +00:00
/**
* skip a test
*/
this.skip = {
2017-07-05 22:06:18 +00:00
test: (descriptionArg, functionArg) => {
console.log(`skipped test: ${descriptionArg}`);
}
};
2017-07-11 13:10:05 +00:00
this._tapTests = [];
2017-04-28 07:49:57 +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
*/
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
});
2017-07-11 13:10:05 +00:00
this._tapTests.push(localTest);
2017-04-28 07:49:57 +00:00
return localTest;
});
}
2017-07-05 22:06:18 +00:00
/**
* wraps function
*/
wrap(functionArg) {
return new tapbundle_classes_tapwrap_1.TapWrap(functionArg);
}
2017-04-28 07:49:57 +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
*/
testParallel(testDescription, testFunction) {
2017-07-11 13:10:05 +00:00
this._tapTests.push(new tapbundle_classes_taptest_1.TapTest({
2017-04-28 07:49:57 +00:00
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
*/
2017-07-11 13:10:05 +00:00
start(optionsArg) {
2017-04-28 07:49:57 +00:00
return __awaiter(this, void 0, void 0, function* () {
let promiseArray = [];
// safeguard against empty test array
2017-07-11 13:10:05 +00:00
if (this._tapTests.length === 0) {
2017-04-28 07:49:57 +00:00
console.log('no tests specified. Ending here!');
return;
}
2017-07-11 13:10:05 +00:00
console.log(`1..${this._tapTests.length}`);
for (let testKey = 0; testKey < this._tapTests.length; testKey++) {
let currentTest = this._tapTests[testKey];
2017-04-28 07:49:57 +00:00
let testPromise = currentTest.run(testKey);
if (currentTest.parallel) {
promiseArray.push(testPromise);
}
else {
yield testPromise;
}
}
yield Promise.all(promiseArray);
2017-07-11 13:10:05 +00:00
// when tests have been run and all promises are fullfilled
let failReasons = [];
let executionNotes = [];
// collect failed tests
for (let tapTest of this._tapTests) {
if (tapTest.status !== 'success') {
failReasons.push(`Test ${tapTest.testKey + 1} failed with status ${tapTest.status}:\n`
+ `|| ${tapTest.description}\n`
+ `|| for more information please take a look the logs above`);
}
}
// render fail Reasons
for (let failReason of failReasons) {
console.log(failReason);
}
if (optionsArg && optionsArg.throwOnError && failReasons.length > 0) {
process.exit(1);
}
2017-04-28 07:49:57 +00:00
});
}
/**
* handle errors
*/
threw(err) {
console.log(err);
}
}
exports.Tap = Tap;
exports.tap = new Tap();
2017-07-11 13:10:05 +00:00
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidGFwYnVuZGxlLmNsYXNzZXMudGFwLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHMvdGFwYnVuZGxlLmNsYXNzZXMudGFwLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7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