2016-09-06 15:21:25 +00:00
|
|
|
import plugins = require('./npmts.plugins')
|
|
|
|
import paths = require('./npmts.paths')
|
2016-10-02 18:35:13 +00:00
|
|
|
|
|
|
|
import * as q from 'q'
|
|
|
|
|
2016-09-06 15:21:25 +00:00
|
|
|
import { npmtsOra } from './npmts.promisechain'
|
2016-09-25 18:22:10 +00:00
|
|
|
import { INpmtsConfig } from './npmts.options'
|
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
|
|
|
*/
|
2016-09-25 18:22:10 +00:00
|
|
|
let mocha = function (configArg: INpmtsConfig) {
|
2016-09-06 15:21:25 +00:00
|
|
|
npmtsOra.text('Instrumentalizing and testing transpiled JS')
|
|
|
|
npmtsOra.end() // end npmtsOra for tests.
|
2016-10-02 18:35:13 +00:00
|
|
|
let done = q.defer()
|
2016-09-06 15:21:25 +00:00
|
|
|
plugins.gulp.src([plugins.path.join(paths.cwd, 'dist/*.js')])
|
2016-07-08 02:00:52 +00:00
|
|
|
.pipe(plugins.g.sourcemaps.init())
|
2016-07-16 17:05:12 +00:00
|
|
|
.pipe(plugins.g.babel({
|
2016-07-16 18:14:43 +00:00
|
|
|
presets: [
|
2016-09-06 15:21:25 +00:00
|
|
|
require.resolve('babel-preset-es2015')
|
2016-07-16 18:14:43 +00:00
|
|
|
]
|
2016-07-16 17:05:12 +00:00
|
|
|
}))
|
2016-07-16 18:54:52 +00:00
|
|
|
.pipe(plugins.g.istanbul({
|
|
|
|
}))
|
2016-07-08 02:00:52 +00:00
|
|
|
.pipe(plugins.g.sourcemaps.write())
|
2016-07-16 17:05:12 +00:00
|
|
|
.pipe(plugins.g.injectModules())
|
2016-09-06 15:21:25 +00:00
|
|
|
.on('finish', function () {
|
2016-09-25 18:22:10 +00:00
|
|
|
let localSmartstream = new plugins.smartstream.Smartstream([
|
|
|
|
plugins.gulp.src([plugins.path.join(paths.cwd, 'test/test.js')]),
|
|
|
|
plugins.g.babel({
|
2016-09-06 15:21:25 +00:00
|
|
|
presets: [
|
|
|
|
require.resolve('babel-preset-es2015')
|
|
|
|
]
|
2016-09-25 18:22:10 +00:00
|
|
|
}),
|
|
|
|
plugins.g.injectModules(),
|
|
|
|
plugins.g.mocha(),
|
|
|
|
plugins.g.istanbul.writeReports({
|
2016-09-06 15:21:25 +00:00
|
|
|
dir: plugins.path.join(paths.cwd, './coverage'),
|
|
|
|
reporters: ['lcovonly', 'json', 'text', 'text-summary']
|
2016-09-25 18:22:10 +00:00
|
|
|
})
|
|
|
|
])
|
|
|
|
localSmartstream.run()
|
|
|
|
.then(() => { done.resolve(configArg) }, (err) => {
|
|
|
|
plugins.beautylog.error('Tests failed!')
|
|
|
|
if (configArg.watch) {
|
2016-09-06 15:21:25 +00:00
|
|
|
done.resolve(configArg)
|
2016-09-25 18:22:10 +00:00
|
|
|
} else {
|
|
|
|
process.exit(1)
|
|
|
|
}
|
|
|
|
})
|
2016-09-06 15:21:25 +00:00
|
|
|
})
|
|
|
|
return done.promise
|
|
|
|
}
|
2016-02-09 04:39:31 +00:00
|
|
|
|
2016-09-25 18:22:10 +00:00
|
|
|
let coverage = function (configArg: INpmtsConfig) {
|
2016-10-02 18:35:13 +00:00
|
|
|
let done = q.defer()
|
2016-09-06 15:21:25 +00:00
|
|
|
plugins.smartcov.get.percentage(plugins.path.join(paths.coverageDir, 'lcov.info'), 2)
|
|
|
|
.then(function (percentageArg) {
|
|
|
|
if (percentageArg >= configArg.coverageTreshold) {
|
2016-03-29 23:32:41 +00:00
|
|
|
plugins.beautylog.ok(
|
2016-09-06 15:21:25 +00:00
|
|
|
`${percentageArg.toString()}% `
|
|
|
|
+ `coverage exceeds your treshold of `
|
|
|
|
+ `${configArg.coverageTreshold.toString()}%`
|
|
|
|
)
|
2016-03-29 23:32:41 +00:00
|
|
|
} else {
|
|
|
|
plugins.beautylog.warn(
|
2016-09-06 15:21:25 +00:00
|
|
|
`${percentageArg.toString()}% `
|
|
|
|
+ `coverage fails your treshold of `
|
|
|
|
+ `${configArg.coverageTreshold.toString()}%`
|
|
|
|
)
|
|
|
|
plugins.beautylog.error('exiting due to coverage failure')
|
2016-09-25 18:22:10 +00:00
|
|
|
if (!configArg.watch) { process.exit(1) }
|
2016-03-29 23:32:41 +00:00
|
|
|
}
|
2016-09-06 15:21:25 +00:00
|
|
|
done.resolve(configArg)
|
|
|
|
})
|
|
|
|
return done.promise
|
|
|
|
}
|
2016-03-29 23:32:41 +00:00
|
|
|
|
2016-09-25 18:22:10 +00:00
|
|
|
export let run = function (configArg: INpmtsConfig) {
|
2016-10-02 18:35:13 +00:00
|
|
|
let done = q.defer()
|
2016-09-06 15:21:25 +00:00
|
|
|
let config = configArg
|
|
|
|
if (config.test === true) {
|
|
|
|
npmtsOra.text('now starting tests')
|
2016-06-16 01:24:01 +00:00
|
|
|
plugins.beautylog.log(
|
2016-09-06 15:21:25 +00:00
|
|
|
'-------------------------------------------------------\n' +
|
|
|
|
'*************************** TESTS: ***************************\n' +
|
|
|
|
'--------------------------------------------------------------'
|
|
|
|
)
|
2016-02-09 04:39:31 +00:00
|
|
|
|
2016-07-15 16:18:11 +00:00
|
|
|
mocha(config)
|
2016-06-16 01:24:01 +00:00
|
|
|
.then(coverage)
|
|
|
|
.then(() => {
|
2016-09-06 15:21:25 +00:00
|
|
|
done.resolve(config)
|
|
|
|
})
|
2016-06-16 01:02:33 +00:00
|
|
|
} else {
|
2016-09-06 15:21:25 +00:00
|
|
|
npmtsOra.end()
|
|
|
|
done.resolve(config)
|
2016-06-16 01:02:33 +00:00
|
|
|
}
|
2016-09-06 15:21:25 +00:00
|
|
|
return done.promise
|
|
|
|
}
|