Compare commits

...

2 Commits

Author SHA1 Message Date
de780538a5 3.0.6 2018-09-02 23:54:59 +02:00
28b1f0bfed fix(core): add tap.only option 2018-09-02 23:54:59 +02:00
3 changed files with 35 additions and 9 deletions

2
package-lock.json generated
View File

@ -1,6 +1,6 @@
{ {
"name": "@pushrocks/tapbundle", "name": "@pushrocks/tapbundle",
"version": "3.0.5", "version": "3.0.6",
"lockfileVersion": 1, "lockfileVersion": 1,
"requires": true, "requires": true,
"dependencies": { "dependencies": {

View File

@ -1,7 +1,7 @@
{ {
"name": "@pushrocks/tapbundle", "name": "@pushrocks/tapbundle",
"private": false, "private": false,
"version": "3.0.5", "version": "3.0.6",
"description": "tap bundled for tapbuffer", "description": "tap bundled for tapbuffer",
"main": "dist/index.js", "main": "dist/index.js",
"typings": "dist/index.d.ts", "typings": "dist/index.d.ts",

View File

@ -4,28 +4,46 @@ import { TapTest, ITestFunction } from './tapbundle.classes.taptest';
import { TapWrap, ITapWrapFunction } from './tapbundle.classes.tapwrap'; import { TapWrap, ITapWrapFunction } from './tapbundle.classes.tapwrap';
export class Tap { export class Tap {
/** /**
* skip a test * skips a test
* tests marked with tap.skip.test() are never executed
*/ */
skip = { skip = {
test: (descriptionArg: string, functionArg: ITestFunction) => { test: (descriptionArg: string, functionArg: ITestFunction) => {
console.log(`skipped test: ${descriptionArg}`); console.log(`skipped test: ${descriptionArg}`);
},
testParallel: (descriptionArg: string, functionArg: ITestFunction) => {
console.log(`skipped test: ${descriptionArg}`);
} }
}; };
/**
* only executes tests marked as ONLY
*/
only = {
test: (descriptionArg: string, testFunctionArg: ITestFunction) => {
this.test(descriptionArg, testFunctionArg, 'only');
}
}
private _tapTests: TapTest[] = []; private _tapTests: TapTest[] = [];
private _tapTestsOnly: TapTest[] = [];
/** /**
* Normal test function, will run one by one * Normal test function, will run one by one
* @param testDescription - A description of what the test does * @param testDescription - A description of what the test does
* @param testFunction - A Function that returns a Promise and resolves or rejects * @param testFunction - A Function that returns a Promise and resolves or rejects
*/ */
async test(testDescription: string, testFunction: ITestFunction) { async test(testDescription: string, testFunction: ITestFunction, modeArg: 'normal' | 'only' | 'skip' = 'normal' ) {
let localTest = new TapTest({ let localTest = new TapTest({
description: testDescription, description: testDescription,
testFunction: testFunction, testFunction: testFunction,
parallel: false parallel: false
}); });
if(modeArg === 'normal') {
this._tapTests.push(localTest); this._tapTests.push(localTest);
} else if (modeArg === 'only') {
this._tapTestsOnly.push(localTest);
}
return localTest; return localTest;
} }
@ -63,9 +81,17 @@ export class Tap {
return; return;
} }
console.log(`1..${this._tapTests.length}`); // determine which tests to run
for (let testKey = 0; testKey < this._tapTests.length; testKey++) { let concerningTests: TapTest[];
let currentTest = this._tapTests[testKey]; if(this._tapTestsOnly.length > 0) {
concerningTests = this._tapTestsOnly;
} else {
concerningTests = this._tapTests;
}
console.log(`1..${concerningTests.length}`);
for (let testKey = 0; testKey < concerningTests.length; testKey++) {
let currentTest = concerningTests[testKey];
let testPromise = currentTest.run(testKey); let testPromise = currentTest.run(testKey);
if (currentTest.parallel) { if (currentTest.parallel) {
promiseArray.push(testPromise); promiseArray.push(testPromise);
@ -79,7 +105,7 @@ export class Tap {
let failReasons: string[] = []; let failReasons: string[] = [];
let executionNotes: string[] = []; let executionNotes: string[] = [];
// collect failed tests // collect failed tests
for (let tapTest of this._tapTests) { for (let tapTest of concerningTests) {
if (tapTest.status !== 'success') { if (tapTest.status !== 'success') {
failReasons.push( failReasons.push(
`Test ${tapTest.testKey + 1} failed with status ${tapTest.status}:\n` + `Test ${tapTest.testKey + 1} failed with status ${tapTest.status}:\n` +