2016-10-21 15:48:52 +00:00
|
|
|
/* ------------------------------------------
|
|
|
|
* This module tests the compiled TypeScript files
|
|
|
|
* -------------------------------------------- */
|
|
|
|
import plugins = require('./mod02.plugins')
|
|
|
|
import paths = require('../npmts.paths')
|
2016-10-02 18:35:13 +00:00
|
|
|
|
2017-01-17 23:58:09 +00:00
|
|
|
import * as q from 'smartq'
|
2016-10-02 18:35:13 +00:00
|
|
|
|
2016-10-21 15:48:52 +00:00
|
|
|
import { INpmtsConfig } from '../npmts.config'
|
2016-03-26 13:08:48 +00:00
|
|
|
|
2016-03-29 23:32:41 +00:00
|
|
|
/**
|
2016-09-25 18:22:10 +00:00
|
|
|
* runs mocha
|
|
|
|
* @returns INpmtsConfig
|
2016-03-29 23:32:41 +00:00
|
|
|
*/
|
2017-03-04 20:49:10 +00:00
|
|
|
let tap = function (configArg: INpmtsConfig) {
|
|
|
|
let done = q.defer()
|
2016-11-25 12:03:41 +00:00
|
|
|
|
2017-03-04 20:49:10 +00:00
|
|
|
/**
|
|
|
|
* the TabBuffer for npmts
|
|
|
|
*/
|
|
|
|
let npmtsTapBuffer = new plugins.tapbuffer.TabBuffer()
|
2016-11-25 12:03:41 +00:00
|
|
|
|
2017-03-04 20:49:10 +00:00
|
|
|
/**
|
|
|
|
* handle the testable files
|
|
|
|
*/
|
|
|
|
let testableFilesSmartstream = new plugins.smartstream.Smartstream([
|
|
|
|
plugins.gulp.src([ plugins.path.join(paths.cwd, './ts/**/*.ts') ]),
|
|
|
|
plugins.gulpSourcemaps.init(),
|
|
|
|
plugins.gulpTypeScript({
|
|
|
|
target: 'ES5',
|
|
|
|
emitDecoratorMetadata: true,
|
|
|
|
experimentalDecorators: true,
|
|
|
|
lib: [ 'DOM', 'ES5', 'ES2015.Promise', 'ES2015.Generator', 'ES2015.Iterable' ]
|
|
|
|
}),
|
|
|
|
plugins.gulpSourcemaps.write(),
|
|
|
|
plugins.gulpFunction.forEach(async file => {
|
|
|
|
file.path = file.path.replace(paths.tsDir, paths.distDir)
|
|
|
|
}),
|
|
|
|
npmtsTapBuffer.pipeTestableFiles(),
|
|
|
|
plugins.smartstream.cleanPipe()
|
|
|
|
])
|
|
|
|
|
|
|
|
/**
|
|
|
|
* handle the test files
|
|
|
|
*/
|
|
|
|
let testFilesSmartstream = new plugins.smartstream.Smartstream([
|
|
|
|
plugins.gulp.src([ plugins.path.join(paths.cwd, 'test/test.ts') ]),
|
|
|
|
plugins.gulpTypeScript({
|
|
|
|
target: 'ES5',
|
|
|
|
emitDecoratorMetadata: true,
|
|
|
|
experimentalDecorators: true,
|
|
|
|
lib: [ 'DOM', 'ES5', 'ES2015.Promise', 'ES2015.Generator', 'ES2015.Iterable' ]
|
|
|
|
}),
|
|
|
|
npmtsTapBuffer.pipeTestFiles(),
|
|
|
|
plugins.smartstream.cleanPipe()
|
|
|
|
])
|
|
|
|
|
|
|
|
// lets run the smartstream
|
|
|
|
Promise.all([
|
|
|
|
testableFilesSmartstream.run(),
|
|
|
|
testFilesSmartstream.run()
|
|
|
|
]).then(
|
|
|
|
async () => {
|
|
|
|
await npmtsTapBuffer.runTests()
|
|
|
|
done.resolve(configArg)
|
|
|
|
}, (err) => {
|
|
|
|
plugins.beautylog.error('Tests failed!')
|
|
|
|
console.log(err)
|
|
|
|
if (configArg.watch) {
|
|
|
|
done.resolve(configArg)
|
|
|
|
} else {
|
|
|
|
process.exit(1)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
return done.promise
|
2016-09-06 15:21:25 +00:00
|
|
|
}
|
2016-02-09 04:39:31 +00:00
|
|
|
|
2017-03-04 20:49:10 +00:00
|
|
|
let handleCoverageData = function (configArg: INpmtsConfig) {
|
|
|
|
let done = q.defer()
|
|
|
|
if (71 >= configArg.coverageTreshold) {
|
|
|
|
plugins.beautylog.ok(
|
|
|
|
`${(71).toString()}% `
|
|
|
|
+ `coverage exceeds your treshold of `
|
|
|
|
+ `${configArg.coverageTreshold.toString()}%`
|
|
|
|
)
|
|
|
|
} else {
|
|
|
|
plugins.beautylog.warn(
|
|
|
|
`${(71).toString()}% `
|
|
|
|
+ `coverage fails your treshold of `
|
|
|
|
+ `${configArg.coverageTreshold.toString()}%`
|
|
|
|
)
|
|
|
|
plugins.beautylog.error('exiting due to coverage failure')
|
|
|
|
if (!configArg.watch) { process.exit(1) }
|
|
|
|
}
|
|
|
|
done.resolve(configArg)
|
|
|
|
return done.promise
|
2016-09-06 15:21:25 +00:00
|
|
|
}
|
2016-03-29 23:32:41 +00:00
|
|
|
|
2016-09-25 18:22:10 +00:00
|
|
|
export let run = function (configArg: INpmtsConfig) {
|
2017-03-04 20:49:10 +00:00
|
|
|
let done = q.defer<INpmtsConfig>()
|
|
|
|
let config = configArg
|
|
|
|
if (config.test === true) {
|
|
|
|
plugins.beautylog.ora.text('now starting tests')
|
|
|
|
plugins.beautylog.ora.end()
|
|
|
|
plugins.beautylog.log('ready for tapbuffer:')
|
2016-02-09 04:39:31 +00:00
|
|
|
|
2017-03-04 20:49:10 +00:00
|
|
|
tap(config)
|
|
|
|
.then(handleCoverageData)
|
|
|
|
.then(() => {
|
2016-09-06 15:21:25 +00:00
|
|
|
done.resolve(config)
|
2017-03-04 20:49:10 +00:00
|
|
|
}).catch(err => { console.log(err) })
|
|
|
|
} else {
|
|
|
|
plugins.beautylog.ora.end()
|
|
|
|
done.resolve(config)
|
|
|
|
}
|
|
|
|
return done.promise
|
2016-09-06 15:21:25 +00:00
|
|
|
}
|