update to latest standards

This commit is contained in:
PhilKunz External
2017-04-28 07:49:57 +00:00
committed by Phil Kunz
parent 8be85e1b35
commit 03614fe2ef
19 changed files with 378 additions and 211 deletions

View File

@ -1,6 +1,6 @@
import 'typings-global'
import { expect } from 'smartchai'
import { tap } from './tapbundle.tap'
import { tap } from './tapbundle.classes.tap'
export {

View File

@ -1,61 +1,6 @@
import * as plugins from './tapbundle.plugins'
import { tapCreator } from './tapbundle.tapcreator'
// imported interfaces
import { HrtMeasurement } from 'early'
// interfaces
export type TTestStatus = 'success' | 'error' | 'pending' | 'errorAfterSuccess'
export interface ITestFunction {
(): Promise<any>
}
export class TapTest {
description: string
parallel: boolean
hrtMeasurement: HrtMeasurement
testFunction: ITestFunction
status: TTestStatus
/**
* constructor
*/
constructor (optionsArg: {
description: string,
testFunction: ITestFunction,
parallel: boolean
}) {
this.description = optionsArg.description
this.testFunction = optionsArg.testFunction
this.parallel = optionsArg.parallel
this.status = 'pending'
this.hrtMeasurement = new HrtMeasurement()
}
/**
* run the test
*/
async run (testKeyArg: number) {
this.hrtMeasurement.start()
try {
await this.testFunction()
this.hrtMeasurement.stop()
console.log(`ok ${testKeyArg + 1} - ${this.description} # time=${this.hrtMeasurement.milliSeconds}ms`)
this.status = 'success'
} catch (err) {
this.hrtMeasurement.stop()
console.log(`not ok ${testKeyArg + 1} - ${this.description} # time=${this.hrtMeasurement.milliSeconds}ms`)
if (this.status === 'success') {
this.status = 'errorAfterSuccess'
console.log('!!! ALERT !!!: weird behaviour, since test has been already successfull')
}
console.log(err)
}
}
}
import { TapTest, ITestFunction } from './tapbundle.classes.taptest'
export class Tap {
private _tests: TapTest[] = []
@ -66,11 +11,13 @@ export class Tap {
* @param testFunction - A Function that returns a Promise and resolves or rejects
*/
async test (testDescription: string, testFunction: ITestFunction) {
this._tests.push(new TapTest({
let localTest = new TapTest({
description: testDescription,
testFunction: testFunction,
parallel: false
}))
})
this._tests.push(localTest)
return localTest
}
/**

View File

@ -0,0 +1,65 @@
import { tapCreator } from './tapbundle.tapcreator'
import { TapTools } from './tapbundle.classes.taptools'
// imported interfaces
import { HrtMeasurement } from 'early'
// interfaces
export type TTestStatus = 'success' | 'error' | 'pending' | 'errorAfterSuccess' | 'timeout'
export interface ITestFunction {
(tapTools?: TapTools): Promise<any>
}
export class TapTest {
description: string
failureAllowed: boolean
hrtMeasurement: HrtMeasurement
parallel: boolean
status: TTestStatus
tapTools: TapTools
testFunction: ITestFunction
/**
* constructor
*/
constructor (optionsArg: {
description: string,
testFunction: ITestFunction,
parallel: boolean
}) {
this.description = optionsArg.description
this.hrtMeasurement = new HrtMeasurement()
this.parallel = optionsArg.parallel
this.status = 'pending'
this.tapTools = new TapTools(this)
this.testFunction = optionsArg.testFunction
}
/**
* run the test
*/
async run (testKeyArg: number) {
this.hrtMeasurement.start()
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`)
this.status = 'success'
} catch (err) {
this.hrtMeasurement.stop()
console.log(`not ok ${testKeyArg + 1} - ${this.description} # time=${this.hrtMeasurement.milliSeconds}ms`)
if (this.status === 'success') {
this.status = 'errorAfterSuccess'
console.log('!!! ALERT !!!: weird behaviour, since test has been already successfull')
}
if(this.failureAllowed) {
console.log(`please note: failure allowed!`)
}
console.log(err)
}
}
}

View File

@ -0,0 +1,36 @@
import * as plugins from './tapbundle.plugins'
import { TapTest } from './tapbundle.classes.taptest'
export class TapTools {
/**
* the referenced TapTest
*/
private _tapTest: TapTest
constructor(TapTestArg) {
this._tapTest = TapTestArg
}
/**
* allow failure
*/
allowFailure() {
this._tapTest.failureAllowed = true
}
/**
* async/await delay method
*/
async delayFor(timeMilliArg) {
await plugins.smartdelay.delayFor(timeMilliArg)
}
async timeout (timeMilliArg: number) {
await plugins.smartdelay.delayFor(timeMilliArg)
if (this._tapTest.status === 'pending') {
this._tapTest.status = 'timeout'
}
}
}

View File

@ -1,10 +1,12 @@
import 'typings-global'
import * as early from 'early'
import * as leakage from 'leakage'
import * as smartdelay from 'smartdelay'
import * as smartq from 'smartq'
export {
early,
smartdelay,
smartq,
leakage
}