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-07-05 22:06:18 +00:00
|
|
|
import { TapWrap, ITapWrapFunction } from './tapbundle.classes.tapwrap'
|
2017-04-23 09:10:13 +00:00
|
|
|
export class Tap {
|
2017-07-05 22:06:18 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* skip a test
|
|
|
|
*/
|
2017-04-28 09:00:22 +00:00
|
|
|
skip = {
|
2017-07-05 22:06:18 +00:00
|
|
|
test: (descriptionArg: string, functionArg: ITestFunction) => {
|
|
|
|
console.log(`skipped test: ${descriptionArg}`)
|
2017-04-28 09:00:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
*/
|
2017-07-05 22:06:18 +00:00
|
|
|
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-07-05 22:06:18 +00:00
|
|
|
/**
|
|
|
|
* wraps function
|
|
|
|
*/
|
|
|
|
wrap (functionArg: ITapWrapFunction) {
|
|
|
|
return new TapWrap(functionArg)
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
*/
|
2017-07-05 22:06:18 +00:00
|
|
|
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
|
|
|
|
*/
|
2017-07-05 22:06:18 +00:00
|
|
|
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
|
|
|
|
*/
|
2017-07-05 22:06:18 +00:00
|
|
|
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++) {
|
2017-04-28 09:00:22 +00:00
|
|
|
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
|
|
|
|
*/
|
2017-07-05 22:06:18 +00:00
|
|
|
threw (err) {
|
2017-04-23 09:10:13 +00:00
|
|
|
console.log(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export let tap = new Tap()
|
|
|
|
|