tscoverage/dist/mod02/index.js

109 lines
3.7 KiB
JavaScript
Raw Normal View History

2016-03-12 09:21:16 +00:00
"use strict";
2016-10-21 15:48:52 +00:00
/* ------------------------------------------
* This module tests the compiled TypeScript files
* -------------------------------------------- */
const plugins = require("./mod02.plugins");
const paths = require("../npmts.paths");
2016-10-02 18:35:13 +00:00
const q = require("q");
2016-10-21 15:48:52 +00:00
const npmts_log_1 = require("../npmts.log");
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-22 21:23:16 +00:00
let mocha = function (configArg) {
2016-10-21 15:48:52 +00:00
npmts_log_1.npmtsOra.text('Instrumentalizing and testing transpiled JS');
npmts_log_1.npmtsOra.end(); // end npmtsOra for tests.
2016-10-02 18:35:13 +00:00
let done = q.defer();
2016-11-25 12:03:41 +00:00
let coverageSmartstream = new plugins.smartstream.Smartstream([
plugins.gulp.src([plugins.path.join(paths.cwd, './dist/**/*.js')]),
2016-11-24 23:36:44 +00:00
plugins.gulpSourcemaps.init(),
plugins.gulpBabel({
presets: [
require.resolve('babel-preset-es2015')
]
}),
plugins.gulpIstanbul({}),
plugins.gulpSourcemaps.write(),
2016-11-25 12:03:41 +00:00
plugins.gulpInjectModules(),
plugins.through2.obj((file, enc, cb) => {
2016-11-25 12:18:59 +00:00
cb();
2016-11-25 12:03:41 +00:00
}, (cb) => {
cb();
})
2016-11-24 23:36:44 +00:00
]);
let localSmartstream = new plugins.smartstream.Smartstream([
plugins.gulp.src([plugins.path.join(paths.cwd, 'test/test.js')]),
plugins.gulpBabel({
presets: [
require.resolve('babel-preset-es2015')
]
}),
plugins.gulpInjectModules(),
plugins.gulpMocha(),
plugins.gulpIstanbul.writeReports({
dir: plugins.path.join(paths.cwd, './coverage'),
reporters: ['lcovonly', 'json', 'text', 'text-summary']
})
]);
2016-11-25 12:03:41 +00:00
coverageSmartstream.run()
2016-11-24 23:36:44 +00:00
.then(() => {
2016-11-25 12:03:41 +00:00
plugins.beautylog.info('code is now transpiled to ES5, instrumented with istanbul, and injected for mocha!');
2016-11-24 23:36:44 +00:00
return localSmartstream.run()
2016-09-25 18:22:10 +00:00
.then(() => { done.resolve(configArg); }, (err) => {
plugins.beautylog.error('Tests failed!');
2016-10-21 15:48:52 +00:00
console.log(err);
2016-09-25 18:22:10 +00:00
if (configArg.watch) {
done.resolve(configArg);
}
else {
process.exit(1);
}
});
2016-11-24 23:36:44 +00:00
}, (err) => {
console.log(err);
2016-07-15 16:18:11 +00:00
});
2016-03-29 23:32:41 +00:00
return done.promise;
};
2016-09-22 21:23:16 +00:00
let coverage = function (configArg) {
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)
2016-03-29 23:32:41 +00:00
.then(function (percentageArg) {
if (percentageArg >= configArg.coverageTreshold) {
2016-09-22 21:23:16 +00:00
plugins.beautylog.ok(`${percentageArg.toString()}% `
+ `coverage exceeds your treshold of `
+ `${configArg.coverageTreshold.toString()}%`);
2016-03-29 23:32:41 +00:00
}
else {
2016-09-22 21:23:16 +00:00
plugins.beautylog.warn(`${percentageArg.toString()}% `
+ `coverage fails your treshold of `
+ `${configArg.coverageTreshold.toString()}%`);
2016-09-06 15:21:25 +00:00
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
}
done.resolve(configArg);
});
return done.promise;
};
2016-02-19 23:53:23 +00:00
exports.run = function (configArg) {
2016-10-02 18:35:13 +00:00
let done = q.defer();
2016-09-22 21:23:16 +00:00
let config = configArg;
2016-08-19 07:46:36 +00:00
if (config.test === true) {
2016-10-21 15:48:52 +00:00
npmts_log_1.npmtsOra.text('now starting tests');
2016-11-24 23:36:44 +00:00
plugins.beautylog.log('------------------------------------------------------\n' +
2016-09-06 15:21:25 +00:00
'*************************** TESTS: ***************************\n' +
'--------------------------------------------------------------');
2016-07-15 16:18:11 +00:00
mocha(config)
2016-06-16 01:02:33 +00:00
.then(coverage)
2016-09-22 21:23:16 +00:00
.then(() => {
2016-06-16 01:02:33 +00:00
done.resolve(config);
2016-11-25 12:03:41 +00:00
}).catch(err => { console.log(err); });
2016-06-16 01:02:33 +00:00
}
else {
2016-10-21 15:48:52 +00:00
npmts_log_1.npmtsOra.end();
2016-06-16 01:02:33 +00:00
done.resolve(config);
}
2016-02-19 23:53:23 +00:00
return done.promise;
};