tap now thows, fixes #1

This commit is contained in:
Philipp Kunz 2017-07-11 15:10:05 +02:00
parent 2b21566fe1
commit a03bcf4583
6 changed files with 84 additions and 28 deletions

View File

@ -7,7 +7,7 @@ export declare class Tap {
skip: {
test: (descriptionArg: string, functionArg: ITestFunction) => void;
};
private _tests;
private _tapTests;
/**
* Normal test function, will run one by one
* @param testDescription - A description of what the test does
@ -33,7 +33,9 @@ export declare class Tap {
/**
* starts the test evaluation
*/
start(): Promise<void>;
start(optionsArg?: {
throwOnError: boolean;
}): Promise<void>;
/**
* handle errors
*/

View File

@ -20,7 +20,7 @@ class Tap {
console.log(`skipped test: ${descriptionArg}`);
}
};
this._tests = [];
this._tapTests = [];
}
/**
* Normal test function, will run one by one
@ -34,7 +34,7 @@ class Tap {
testFunction: testFunction,
parallel: false
});
this._tests.push(localTest);
this._tapTests.push(localTest);
return localTest;
});
}
@ -50,7 +50,7 @@ class Tap {
* @param testFunction - A Function that returns a Promise and resolves or rejects
*/
testParallel(testDescription, testFunction) {
this._tests.push(new tapbundle_classes_taptest_1.TapTest({
this._tapTests.push(new tapbundle_classes_taptest_1.TapTest({
description: testDescription,
testFunction: testFunction,
parallel: true
@ -66,17 +66,17 @@ class Tap {
/**
* starts the test evaluation
*/
start() {
start(optionsArg) {
return __awaiter(this, void 0, void 0, function* () {
let promiseArray = [];
// safeguard against empty test array
if (this._tests.length === 0) {
if (this._tapTests.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];
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);
@ -86,6 +86,24 @@ class Tap {
}
}
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);
}
});
}
/**
@ -97,4 +115,4 @@ class Tap {
}
exports.Tap = Tap;
exports.tap = new Tap();
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidGFwYnVuZGxlLmNsYXNzZXMudGFwLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHMvdGFwYnVuZGxlLmNsYXNzZXMudGFwLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7Ozs7Ozs7Ozs7QUFFQSwyRUFBb0U7QUFDcEUsMkVBQXVFO0FBQ3ZFO0lBQUE7UUFFRTs7V0FFRztRQUNILFNBQUksR0FBRztZQUNMLElBQUksRUFBRSxDQUFDLGNBQXNCLEVBQUUsV0FBMEI7Z0JBQ3ZELE9BQU8sQ0FBQyxHQUFHLENBQUMsaUJBQWlCLGNBQWMsRUFBRSxDQUFDLENBQUE7WUFDaEQsQ0FBQztTQUNGLENBQUE7UUFFTyxXQUFNLEdBQWMsRUFBRSxDQUFBO0lBNkVoQyxDQUFDO0lBM0VDOzs7O09BSUc7SUFDRyxJQUFJLENBQUUsZUFBdUIsRUFBRSxZQUEyQjs7WUFDOUQsSUFBSSxTQUFTLEdBQUcsSUFBSSxtQ0FBTyxDQUFDO2dCQUMxQixXQUFXLEVBQUUsZUFBZTtnQkFDNUIsWUFBWSxFQUFFLFlBQVk7Z0JBQzFCLFFBQVEsRUFBRSxLQUFLO2FBQ2hCLENBQUMsQ0FBQTtZQUNGLElBQUksQ0FBQyxNQUFNLENBQUMsSUFBSSxDQUFDLFNBQVMsQ0FBQyxDQUFBO1lBQzNCLE1BQU0sQ0FBQy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FBQyxDQUFDO29CQUNqQyxXQUFXLENBQUMsSUFBSSxDQUNkLFFBQVEsT0FBTyxDQUFDLE9BQU8sR0FBRyxDQUFDLHVCQUF1QixPQUFPLENBQUMsTUFBTSxLQUFLOzBCQUNuRSxNQUFNLE9BQU8sQ0FBQyxXQUFXLElBQUk7MEJBQzdCLDJEQUEyRCxDQUM5RCxDQUFBO2dCQUNILENBQUM7WUFDSCxDQUFDO1lBRUQsc0JBQXNCO1lBQ3RCLEdBQUcsQ0FBQyxDQUFDLElBQUksVUFBVSxJQUFJLFdBQVcsQ0FBQyxDQUFDLENBQUM7Z0JBQ25DLE9BQU8sQ0FBQyxHQUFHLENBQUMsVUFBVSxDQUFDLENBQUE7WUFDekIsQ0FBQztZQUVELEVBQUUsQ0FBQyxDQUFDLFVBQVUsSUFBSSxVQUFVLENBQUMsWUFBWSxJQUFJLFdBQVcsQ0FBQyxNQUFNLEdBQUcsQ0FBQyxDQUFDLENBQUMsQ0FBQztnQkFDcEUsT0FBTyxDQUFDLElBQUksQ0FBQyxDQUFDLENBQUMsQ0FBQTtZQUNqQixDQUFDO1FBQ0gsQ0FBQztLQUFBO0lBRUQ7O09BRUc7SUFDSCxLQUFLLENBQUUsR0FBRztRQUNSLE9BQU8sQ0FBQyxHQUFHLENBQUMsR0FBRyxDQUFDLENBQUE7SUFDbEIsQ0FBQztDQUNGO0FBakhELGtCQWlIQztBQUVVLFFBQUEsR0FBRyxHQUFHLElBQUksR0FBRyxFQUFFLENBQUEifQ==

View File

@ -13,6 +13,7 @@ export declare class TapTest {
status: TTestStatus;
tapTools: TapTools;
testFunction: ITestFunction;
testKey: number;
testDeferred: Deferred<TapTest>;
testPromise: Promise<TapTest>;
/**

View File

@ -32,25 +32,30 @@ class TapTest {
run(testKeyArg) {
return __awaiter(this, void 0, void 0, function* () {
this.hrtMeasurement.start();
this.testKey = testKeyArg;
let testNumber = testKeyArg + 1;
try {
yield this.testFunction(this.tapTools);
if (this.status === 'timeout') {
throw new Error('Test succeeded, but timed out...');
}
this.hrtMeasurement.stop();
console.log(`ok ${testKeyArg + 1} - ${this.description} # time=${this.hrtMeasurement.milliSeconds}ms`);
console.log(`ok ${testNumber} - ${this.description} # time=${this.hrtMeasurement.milliSeconds}ms`);
this.status = 'success';
this.testDeferred.resolve(this);
}
catch (err) {
this.hrtMeasurement.stop();
console.log(`not ok ${testKeyArg + 1} - ${this.description} # time=${this.hrtMeasurement.milliSeconds}ms`);
console.log(`not ok ${testNumber} - ${this.description} # time=${this.hrtMeasurement.milliSeconds}ms`);
this.testDeferred.resolve(this);
// if the test has already succeeded before
if (this.status === 'success') {
this.status = 'errorAfterSuccess';
console.log('!!! ALERT !!!: weird behaviour, since test has been already successfull');
}
else {
this.status = 'error';
}
// if the test is allowed to fail
if (this.failureAllowed) {
console.log(`please note: failure allowed!`);
@ -61,4 +66,4 @@ class TapTest {
}
}
exports.TapTest = TapTest;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidGFwYnVuZGxlLmNsYXNzZXMudGFwdGVzdC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL3RhcGJ1bmRsZS5jbGFzc2VzLnRhcHRlc3QudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7Ozs7Ozs7OztBQUFBLCtDQUE4QztBQUU5Qyw2RUFBdUQ7QUFFdkQsc0JBQXNCO0FBQ3RCLGlDQUFzQztBQVd0QztJQVVFOztPQUVHO0lBQ0gsWUFBYSxVQUlaO1FBVEQsaUJBQVksR0FBc0IsT0FBTyxDQUFDLE1BQU0sQ0FBQyxLQUFLLEVBQUUsQ0FBQTtRQUN4RCxnQkFBVyxHQUFxQixJQUFJLENBQUMsWUFBWSxDQUFDLE9BQU8sQ0FBQTtRQVN2RCxJQUFJLENBQUMsV0FBVyxHQUFHLFVBQVUsQ0FBQyxXQUFXLENBQUE7UUFDekMsSUFBSSxDQUFDLGNBQWMsR0FBRyxJQ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IsT0FBTyxDQUFDLEdBQUcsQ0FBQywrQkFBK0IsQ0FBQyxDQUFBO2dCQUM5QyxDQUFDO2dCQUNELE9BQU8sQ0FBQyxHQUFHLENBQUMsR0FBRyxDQUFDLENBQUE7WUFDbEIsQ0FBQztRQUNILENBQUM7S0FBQTtDQUNGO0FBL0RELDBCQStEQyJ9

View File

@ -13,7 +13,7 @@ export class Tap {
}
}
private _tests: TapTest[] = []
private _tapTests: TapTest[] = []
/**
* Normal test function, will run one by one
@ -26,7 +26,7 @@ export class Tap {
testFunction: testFunction,
parallel: false
})
this._tests.push(localTest)
this._tapTests.push(localTest)
return localTest
}
@ -43,7 +43,7 @@ export class Tap {
* @param testFunction - A Function that returns a Promise and resolves or rejects
*/
testParallel(testDescription: string, testFunction: ITestFunction) {
this._tests.push(new TapTest({
this._tapTests.push(new TapTest({
description: testDescription,
testFunction: testFunction,
parallel: true
@ -62,18 +62,20 @@ export class Tap {
/**
* starts the test evaluation
*/
async start () {
async start(optionsArg?: {
throwOnError: boolean
}) {
let promiseArray: Promise<any>[] = []
// safeguard against empty test array
if (this._tests.length === 0) {
if (this._tapTests.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 ]
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)
@ -82,6 +84,29 @@ export class Tap {
}
}
await Promise.all(promiseArray)
// when tests have been run and all promises are fullfilled
let failReasons: string[] = []
let executionNotes: string[] = []
// 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)
}
}
/**

View File

@ -22,6 +22,7 @@ export class TapTest {
status: TTestStatus
tapTools: TapTools
testFunction: ITestFunction
testKey: number // the testKey the position in the test qeue. Set upon calling .run()
testDeferred: Deferred<TapTest> = plugins.smartq.defer()
testPromise: Promise<TapTest> = this.testDeferred.promise
/**
@ -45,24 +46,28 @@ export class TapTest {
*/
async run (testKeyArg: number) {
this.hrtMeasurement.start()
this.testKey = testKeyArg
let testNumber = testKeyArg + 1
try {
await this.testFunction(this.tapTools)
if (this.status === 'timeout') {
throw new Error ('Test succeeded, but timed out...')
}
this.hrtMeasurement.stop()
console.log(`ok ${testKeyArg + 1} - ${this.description} # time=${this.hrtMeasurement.milliSeconds}ms`)
console.log(`ok ${testNumber} - ${this.description} # time=${this.hrtMeasurement.milliSeconds}ms`)
this.status = 'success'
this.testDeferred.resolve(this)
} catch (err) {
this.hrtMeasurement.stop()
console.log(`not ok ${testKeyArg + 1} - ${this.description} # time=${this.hrtMeasurement.milliSeconds}ms`)
console.log(`not ok ${testNumber} - ${this.description} # time=${this.hrtMeasurement.milliSeconds}ms`)
this.testDeferred.resolve(this)
// if the test has already succeeded before
if (this.status === 'success') {
this.status = 'errorAfterSuccess'
console.log('!!! ALERT !!!: weird behaviour, since test has been already successfull')
} else {
this.status = 'error'
}
// if the test is allowed to fail