111 lines
7.3 KiB
JavaScript
111 lines
7.3 KiB
JavaScript
"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");
|
|
const tapbundle_classes_tapwrap_1 = require("./tapbundle.classes.tapwrap");
|
|
class Tap {
|
|
constructor() {
|
|
/**
|
|
* skip a test
|
|
*/
|
|
this.skip = {
|
|
test: (descriptionArg, functionArg) => {
|
|
console.log(`skipped test: ${descriptionArg}`);
|
|
}
|
|
};
|
|
this._tapTests = [];
|
|
}
|
|
/**
|
|
* 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._tapTests.push(localTest);
|
|
return localTest;
|
|
});
|
|
}
|
|
/**
|
|
* wraps function
|
|
*/
|
|
wrap(functionArg) {
|
|
return new tapbundle_classes_tapwrap_1.TapWrap(functionArg);
|
|
}
|
|
/**
|
|
* 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._tapTests.push(new tapbundle_classes_taptest_1.TapTest({
|
|
description: testDescription,
|
|
testFunction: testFunction,
|
|
parallel: true
|
|
}));
|
|
}
|
|
/**
|
|
* starts the test evaluation
|
|
*/
|
|
start(optionsArg) {
|
|
return __awaiter(this, void 0, void 0, function* () {
|
|
let promiseArray = [];
|
|
// safeguard against empty test array
|
|
if (this._tapTests.length === 0) {
|
|
console.log('no tests specified. Ending here!');
|
|
return;
|
|
}
|
|
console.log(`1..${this._tapTests.length}`);
|
|
for (let testKey = 0; testKey < this._tapTests.length; testKey++) {
|
|
let currentTest = this._tapTests[testKey];
|
|
let testPromise = currentTest.run(testKey);
|
|
if (currentTest.parallel) {
|
|
promiseArray.push(testPromise);
|
|
}
|
|
else {
|
|
yield testPromise;
|
|
}
|
|
}
|
|
yield Promise.all(promiseArray);
|
|
// 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);
|
|
}
|
|
});
|
|
}
|
|
/**
|
|
* handle errors
|
|
*/
|
|
threw(err) {
|
|
console.log(err);
|
|
}
|
|
}
|
|
exports.Tap = Tap;
|
|
exports.tap = new Tap();
|
|
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidGFwYnVuZGxlLmNsYXNzZXMudGFwLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHMvdGFwYnVuZGxlLmNsYXNzZXMudGFwLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7Ozs7Ozs7Ozs7QUFFQSwyRUFBb0U7QUFDcEUsMkVBQX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