tscoverage/dist/npmts.tests.js

80 lines
2.9 KiB
JavaScript
Raw Normal View History

2016-03-12 10:21:16 +01:00
"use strict";
2016-05-25 05:23:48 +02:00
require("typings-global");
2016-02-20 00:53:23 +01:00
var plugins = require("./npmts.plugins");
var paths = require("./npmts.paths");
2016-05-17 02:32:40 +02:00
var npmts_promisechain_1 = require("./npmts.promisechain");
2016-03-30 01:32:41 +02:00
/**
*
* @returns {*}
*/
2016-07-15 18:18:11 +02:00
var mocha = function (configArg) {
npmts_promisechain_1.npmtsOra.text("Instrumentalizing and testing transpiled JS");
npmts_promisechain_1.npmtsOra.end(); // end npmtsOra for tests.
2016-03-30 01:32:41 +02:00
var done = plugins.Q.defer();
var stream = plugins.gulp.src([plugins.path.join(paths.cwd, "dist/*.js")])
2016-07-08 04:00:52 +02:00
.pipe(plugins.g.sourcemaps.init())
2016-07-16 19:05:12 +02:00
.pipe(plugins.g.babel({
2016-07-16 20:14:43 +02:00
presets: [
2016-07-16 23:33:10 +02:00
require.resolve("babel-preset-es2015")
2016-07-16 20:14:43 +02:00
]
2016-07-16 19:05:12 +02:00
}))
.pipe(plugins.g.istanbul({}))
2016-07-08 04:00:52 +02:00
.pipe(plugins.g.sourcemaps.write())
2016-07-16 19:05:12 +02:00
.pipe(plugins.g.injectModules())
2016-07-15 18:18:11 +02:00
.on("finish", function () {
2016-07-15 19:27:53 +02:00
plugins.gulp.src([plugins.path.join(paths.cwd, "test/test.js")])
2016-07-16 19:05:12 +02:00
.pipe(plugins.g.babel({
2016-07-16 20:14:43 +02:00
presets: [
require.resolve("babel-preset-es2015")
2016-07-16 20:14:43 +02:00
]
2016-07-16 19:05:12 +02:00
}))
2016-07-15 18:18:11 +02:00
.pipe(plugins.g.injectModules())
.pipe(plugins.g.mocha())
.pipe(plugins.g.istanbul.writeReports({
dir: plugins.path.join(paths.cwd, "./coverage"),
reporters: ['lcovonly', 'json', 'text', 'text-summary']
}))
2016-07-15 18:18:11 +02:00
.pipe(plugins.g.gFunction(function () {
plugins.beautylog.ok("Tested!");
done.resolve(configArg);
}, "atEnd"));
});
2016-03-30 01:32:41 +02:00
return done.promise;
};
var coverage = function (configArg) {
var done = plugins.Q.defer();
2016-07-23 02:05:56 +02:00
plugins.smartcov.get.percentage(plugins.path.join(paths.coverageDir, "lcov.info"), 2)
2016-03-30 01:32:41 +02:00
.then(function (percentageArg) {
if (percentageArg >= configArg.coverageTreshold) {
2016-07-23 02:05:56 +02:00
plugins.beautylog.ok(percentageArg.toString() + "% coverage exceeds your treshold of " + configArg.coverageTreshold.toString() + "%");
2016-03-30 01:32:41 +02:00
}
else {
2016-07-23 02:05:56 +02:00
plugins.beautylog.warn(percentageArg.toString() + "% coverage fails your treshold of " + configArg.coverageTreshold.toString() + "%");
2016-03-30 01:32:41 +02:00
plugins.beautylog.error("exiting due to coverage failure");
process.exit(1);
}
done.resolve(configArg);
});
return done.promise;
};
2016-02-20 00:53:23 +01:00
exports.run = function (configArg) {
2016-02-22 22:22:39 +01:00
var done = plugins.Q.defer();
2016-02-20 00:53:23 +01:00
var config = configArg;
2016-08-19 09:46:36 +02:00
if (config.test === true) {
2016-06-16 03:02:33 +02:00
npmts_promisechain_1.npmtsOra.text("now starting tests");
plugins.beautylog.log("-------------------------------------------------------\n" +
"*************************** TESTS: ***************************\n" +
"--------------------------------------------------------------");
2016-07-15 18:18:11 +02:00
mocha(config)
2016-06-16 03:02:33 +02:00
.then(coverage)
.then(function () {
done.resolve(config);
});
}
else {
2016-06-16 03:24:01 +02:00
npmts_promisechain_1.npmtsOra.end();
2016-06-16 03:02:33 +02:00
done.resolve(config);
}
2016-02-20 00:53:23 +01:00
return done.promise;
};