tscoverage/dist/npmts.tests.js

84 lines
3.0 KiB
JavaScript
Raw Permalink Normal View History

2016-03-12 09:21:16 +00:00
"use strict";
require("typings-global");
var plugins = require("./npmts.plugins");
var paths = require("./npmts.paths");
var npmts_promisechain_1 = require("./npmts.promisechain");
2016-03-29 23:32:41 +00:00
/**
*
* @returns {*}
*/
2016-07-15 16:18:11 +00:00
var mocha = function (configArg) {
2016-09-06 15:21:25 +00:00
npmts_promisechain_1.npmtsOra.text('Instrumentalizing and testing transpiled JS');
2016-07-15 16:18:11 +00:00
npmts_promisechain_1.npmtsOra.end(); // end npmtsOra for tests.
2016-03-29 23:32:41 +00:00
var done = plugins.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
}))
.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 () {
plugins.gulp.src([plugins.path.join(paths.cwd, 'test/test.js')])
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-15 16:18:11 +00:00
.pipe(plugins.g.injectModules())
.pipe(plugins.g.mocha())
.pipe(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-07-15 16:18:11 +00:00
.pipe(plugins.g.gFunction(function () {
2016-09-06 15:21:25 +00:00
plugins.beautylog.ok('Tested!');
2016-07-15 16:18:11 +00:00
done.resolve(configArg);
2016-09-06 15:21:25 +00:00
}, 'atEnd'));
2016-07-15 16:18:11 +00:00
});
2016-03-29 23:32:41 +00:00
return done.promise;
};
var coverage = function (configArg) {
var done = plugins.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) {
plugins.beautylog.ok(percentageArg.toString() + "% "
2016-09-06 15:21:25 +00:00
+ "coverage exceeds your treshold of "
+ (configArg.coverageTreshold.toString() + "%"));
2016-03-29 23:32:41 +00:00
}
else {
plugins.beautylog.warn(percentageArg.toString() + "% "
2016-09-06 15:21:25 +00:00
+ "coverage fails your treshold of "
+ (configArg.coverageTreshold.toString() + "%"));
plugins.beautylog.error('exiting due to coverage failure');
2016-03-29 23:32:41 +00:00
process.exit(1);
}
done.resolve(configArg);
});
return done.promise;
};
2016-02-19 23:53:23 +00:00
exports.run = function (configArg) {
2016-02-22 21:22:39 +00:00
var done = plugins.Q.defer();
2016-02-19 23:53:23 +00:00
var config = configArg;
2016-08-19 07:46:36 +00:00
if (config.test === true) {
2016-09-06 15:21:25 +00:00
npmts_promisechain_1.npmtsOra.text('now starting tests');
plugins.beautylog.log('-------------------------------------------------------\n' +
'*************************** TESTS: ***************************\n' +
'--------------------------------------------------------------');
2016-07-15 16:18:11 +00:00
mocha(config)
2016-06-16 01:02:33 +00:00
.then(coverage)
.then(function () {
done.resolve(config);
});
}
else {
2016-06-16 01:24:01 +00:00
npmts_promisechain_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;
};