2016-05-25 03:23:48 +00:00
|
|
|
import "typings-global";
|
2016-02-19 23:53:23 +00:00
|
|
|
import plugins = require("./npmts.plugins");
|
|
|
|
import paths = require("./npmts.paths");
|
2016-05-17 00:32:40 +00:00
|
|
|
import {npmtsOra} from "./npmts.promisechain";
|
2016-03-26 13:08:48 +00:00
|
|
|
|
2016-03-29 23:32:41 +00:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @returns {*}
|
|
|
|
*/
|
2016-07-15 16:18:11 +00:00
|
|
|
let mocha = function (configArg) {
|
|
|
|
npmtsOra.text("Instrumentalizing and testing transpiled JS");
|
|
|
|
npmtsOra.end(); // end npmtsOra for tests.
|
2016-03-29 23:32:41 +00:00
|
|
|
let done = plugins.Q.defer();
|
|
|
|
var stream = 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-07-16 21:33:10 +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-07-15 16:18:11 +00:00
|
|
|
.on("finish",function(){
|
2016-07-15 17:27:53 +00:00
|
|
|
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: [
|
|
|
|
plugins.path.join(paths.npmtsPackageRoot,"node_modules/babel-preset-es2015/index.js")
|
|
|
|
]
|
2016-07-16 17:05:12 +00:00
|
|
|
}))
|
2016-07-15 16:18:11 +00:00
|
|
|
.pipe(plugins.g.injectModules())
|
|
|
|
.pipe(plugins.g.mocha())
|
2016-07-16 18:54:52 +00:00
|
|
|
.pipe(plugins.g.istanbul.writeReports({
|
2016-07-18 17:06:00 +00:00
|
|
|
dir: plugins.path.join(paths.cwd,"./coverage"),
|
2016-07-16 18:54:52 +00:00
|
|
|
reporters: [ 'lcovonly', 'json', 'text', 'text-summary']
|
|
|
|
}))
|
2016-07-15 16:18:11 +00:00
|
|
|
.pipe(plugins.g.gFunction(function(){
|
|
|
|
plugins.beautylog.ok("Tested!");
|
|
|
|
done.resolve(configArg);
|
|
|
|
},"atEnd"));
|
|
|
|
});
|
2016-03-29 23:32:41 +00:00
|
|
|
return done.promise;
|
|
|
|
};
|
2016-02-09 04:39:31 +00:00
|
|
|
|
2016-03-29 23:32:41 +00:00
|
|
|
let coverage = function(configArg){
|
|
|
|
let done = plugins.Q.defer();
|
2016-07-23 00:05:56 +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(
|
2016-07-23 00:05:56 +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-07-23 00:05:56 +00:00
|
|
|
`${percentageArg.toString()}% coverage fails your treshold of ${configArg.coverageTreshold.toString()}%`
|
2016-03-29 23:32:41 +00:00
|
|
|
);
|
|
|
|
plugins.beautylog.error("exiting due to coverage failure");
|
|
|
|
process.exit(1);
|
|
|
|
}
|
|
|
|
done.resolve(configArg);
|
|
|
|
});
|
|
|
|
return done.promise;
|
|
|
|
};
|
|
|
|
|
|
|
|
export let run = function(configArg) {
|
|
|
|
let done = plugins.Q.defer();
|
|
|
|
let config = configArg;
|
2016-06-16 01:24:01 +00:00
|
|
|
if(config.notest != true){
|
|
|
|
npmtsOra.text("now starting tests");
|
|
|
|
plugins.beautylog.log(
|
|
|
|
"-------------------------------------------------------\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(() => {
|
|
|
|
done.resolve(config);
|
|
|
|
});
|
2016-06-16 01:02:33 +00:00
|
|
|
} else {
|
2016-06-16 01:24:01 +00:00
|
|
|
npmtsOra.end();
|
2016-06-16 01:02:33 +00:00
|
|
|
done.resolve(config);
|
|
|
|
}
|
2016-02-19 23:53:23 +00:00
|
|
|
return done.promise;
|
|
|
|
};
|