tapbundle/ts/tapbundle.classes.tap.ts

86 lines
2.1 KiB
TypeScript
Raw Permalink Normal View History

2017-04-23 09:10:13 +00:00
import * as plugins from './tapbundle.plugins'
2017-04-28 07:49:57 +00:00
import { TapTest, ITestFunction } from './tapbundle.classes.taptest'
2017-04-23 09:10:13 +00:00
export class Tap {
skip = {
test: (...args) => {
console.log('skipped')
}
}
2017-04-23 09:10:13 +00:00
private _tests: TapTest[] = []
2017-04-23 12:35:16 +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
*/
async test(testDescription: string, testFunction: ITestFunction) {
2017-04-28 07:49:57 +00:00
let localTest = new TapTest({
2017-04-23 09:10:13 +00:00
description: testDescription,
testFunction: testFunction,
parallel: false
2017-04-28 07:49:57 +00:00
})
this._tests.push(localTest)
return localTest
2017-04-23 09:10:13 +00:00
}
2017-04-23 12:35:16 +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: string, testFunction: ITestFunction) {
2017-04-23 09:10:13 +00:00
this._tests.push(new TapTest({
description: testDescription,
testFunction: testFunction,
parallel: true
}))
}
2017-04-23 12:35:16 +00:00
/**
* 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: string, testFunction: ITestFunction) {
2017-04-23 12:35:16 +00:00
}
2017-04-23 09:10:13 +00:00
/**
* starts the test evaluation
*/
async start() {
2017-04-23 09:10:13 +00:00
let promiseArray: Promise<any>[] = []
// 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 ]
2017-04-23 09:10:13 +00:00
let testPromise = currentTest.run(testKey)
if (currentTest.parallel) {
promiseArray.push(testPromise)
} else {
await testPromise
}
}
await Promise.all(promiseArray)
}
/**
* handle errors
*/
threw(err) {
2017-04-23 09:10:13 +00:00
console.log(err)
}
}
export let tap = new Tap()