2016-03-12 09:21:16 +00:00
|
|
|
"use strict";
|
2017-01-15 19:01:10 +00:00
|
|
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
|
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
|
|
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
|
|
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
|
|
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
|
|
|
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
|
|
});
|
|
|
|
};
|
2017-02-27 21:19:14 +00:00
|
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
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");
|
2017-01-17 23:58:09 +00:00
|
|
|
const q = require("smartq");
|
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
|
|
|
*/
|
2017-03-04 20:49:10 +00:00
|
|
|
let tap = function (configArg) {
|
2016-10-02 18:35:13 +00:00
|
|
|
let done = q.defer();
|
2017-03-04 20:49:10 +00:00
|
|
|
/**
|
|
|
|
* the TabBuffer for npmts
|
|
|
|
*/
|
|
|
|
let npmtsTapBuffer = new plugins.tapbuffer.TabBuffer();
|
|
|
|
/**
|
|
|
|
* handle the testable files
|
|
|
|
*/
|
|
|
|
let testableFilesSmartstream = new plugins.smartstream.Smartstream([
|
2017-05-01 20:43:32 +00:00
|
|
|
plugins.smartgulp.src([plugins.path.join(paths.cwd, './ts/**/*.ts')]),
|
2016-11-24 23:36:44 +00:00
|
|
|
plugins.gulpSourcemaps.init(),
|
2017-01-15 19:01:10 +00:00
|
|
|
plugins.gulpTypeScript({
|
|
|
|
target: 'ES5',
|
|
|
|
emitDecoratorMetadata: true,
|
2017-01-15 19:12:12 +00:00
|
|
|
experimentalDecorators: true,
|
2017-01-20 17:38:02 +00:00
|
|
|
lib: ['DOM', 'ES5', 'ES2015.Promise', 'ES2015.Generator', 'ES2015.Iterable']
|
2016-11-24 23:36:44 +00:00
|
|
|
}),
|
2017-01-15 19:01:10 +00:00
|
|
|
plugins.gulpFunction.forEach((file) => __awaiter(this, void 0, void 0, function* () {
|
|
|
|
file.path = file.path.replace(paths.tsDir, paths.distDir);
|
|
|
|
})),
|
2017-05-13 08:21:55 +00:00
|
|
|
plugins.gulpSourcemaps.write(),
|
2017-03-04 20:49:10 +00:00
|
|
|
npmtsTapBuffer.pipeTestableFiles(),
|
|
|
|
plugins.smartstream.cleanPipe()
|
2016-11-24 23:36:44 +00:00
|
|
|
]);
|
2017-03-04 20:49:10 +00:00
|
|
|
/**
|
|
|
|
* handle the test files
|
|
|
|
*/
|
|
|
|
let testFilesSmartstream = new plugins.smartstream.Smartstream([
|
2017-05-01 20:43:32 +00:00
|
|
|
plugins.smartgulp.src([plugins.path.join(paths.cwd, 'test/*.ts')]),
|
2017-05-13 08:21:55 +00:00
|
|
|
plugins.gulpSourcemaps.init(),
|
2017-01-15 19:01:10 +00:00
|
|
|
plugins.gulpTypeScript({
|
|
|
|
target: 'ES5',
|
|
|
|
emitDecoratorMetadata: true,
|
2017-01-15 20:45:08 +00:00
|
|
|
experimentalDecorators: true,
|
2017-01-20 17:38:02 +00:00
|
|
|
lib: ['DOM', 'ES5', 'ES2015.Promise', 'ES2015.Generator', 'ES2015.Iterable']
|
2016-11-24 23:36:44 +00:00
|
|
|
}),
|
2017-05-13 08:21:55 +00:00
|
|
|
plugins.gulpSourcemaps.write(),
|
2017-03-04 20:49:10 +00:00
|
|
|
npmtsTapBuffer.pipeTestFiles(),
|
|
|
|
plugins.smartstream.cleanPipe()
|
2016-11-24 23:36:44 +00:00
|
|
|
]);
|
2017-03-04 20:49:10 +00:00
|
|
|
// lets run the smartstream
|
|
|
|
Promise.all([
|
|
|
|
testableFilesSmartstream.run(),
|
|
|
|
testFilesSmartstream.run()
|
|
|
|
]).then(() => __awaiter(this, void 0, void 0, function* () {
|
2017-03-31 17:18:18 +00:00
|
|
|
configArg.runData.coverageLcovInfo = yield npmtsTapBuffer.runTests();
|
2017-03-04 20:49:10 +00:00
|
|
|
done.resolve(configArg);
|
|
|
|
}), (err) => {
|
|
|
|
plugins.beautylog.error('Tests failed!');
|
2016-11-24 23:36:44 +00:00
|
|
|
console.log(err);
|
2017-03-04 20:49:10 +00:00
|
|
|
if (configArg.watch) {
|
|
|
|
done.resolve(configArg);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
process.exit(1);
|
|
|
|
}
|
2016-07-15 16:18:11 +00:00
|
|
|
});
|
2016-03-29 23:32:41 +00:00
|
|
|
return done.promise;
|
|
|
|
};
|
2017-03-31 17:18:18 +00:00
|
|
|
let handleCoverageData = (configArg) => __awaiter(this, void 0, void 0, function* () {
|
2017-05-04 22:01:21 +00:00
|
|
|
let coverageResult = 0; // the coverage in percent
|
|
|
|
if (configArg.runData.coverageLcovInfo) {
|
|
|
|
coverageResult = yield plugins.smartcov.get.percentageFromLcovString(configArg.runData.coverageLcovInfo, 2);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
plugins.beautylog.warn('Hey... Did your tests import and use your module that you are trying to test?');
|
|
|
|
}
|
2017-03-31 17:18:18 +00:00
|
|
|
if (coverageResult >= configArg.coverageTreshold) {
|
|
|
|
plugins.beautylog.ok(`${(coverageResult).toString()}% `
|
2017-03-04 20:49:10 +00:00
|
|
|
+ `coverage exceeds your treshold of `
|
|
|
|
+ `${configArg.coverageTreshold.toString()}%`);
|
|
|
|
}
|
|
|
|
else {
|
2017-03-31 17:18:18 +00:00
|
|
|
plugins.beautylog.warn(`${(coverageResult).toString()}% `
|
2017-03-04 20:49:10 +00:00
|
|
|
+ `coverage fails your treshold of `
|
|
|
|
+ `${configArg.coverageTreshold.toString()}%`);
|
|
|
|
plugins.beautylog.error('exiting due to coverage failure');
|
|
|
|
if (!configArg.watch) {
|
|
|
|
process.exit(1);
|
2016-03-29 23:32:41 +00:00
|
|
|
}
|
2017-03-04 20:49:10 +00:00
|
|
|
}
|
2017-03-31 17:18:18 +00:00
|
|
|
return configArg;
|
|
|
|
});
|
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) {
|
2017-01-21 22:23:00 +00:00
|
|
|
plugins.beautylog.ora.text('now starting tests');
|
2017-03-04 20:49:10 +00:00
|
|
|
plugins.beautylog.ora.end();
|
|
|
|
plugins.beautylog.log('ready for tapbuffer:');
|
2017-06-16 14:08:36 +00:00
|
|
|
if (configArg.coverage) {
|
|
|
|
tap(config)
|
|
|
|
.then(handleCoverageData)
|
|
|
|
.then(() => {
|
|
|
|
done.resolve(config);
|
|
|
|
}).catch(err => { console.log(err); });
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
tap(config)
|
|
|
|
.then(() => {
|
|
|
|
done.resolve(config);
|
|
|
|
}).catch(err => { console.log(err); });
|
|
|
|
}
|
2016-06-16 01:02:33 +00:00
|
|
|
}
|
|
|
|
else {
|
2017-01-21 22:23:00 +00:00
|
|
|
plugins.beautylog.ora.end();
|
2016-06-16 01:02:33 +00:00
|
|
|
done.resolve(config);
|
|
|
|
}
|
2016-02-19 23:53:23 +00:00
|
|
|
return done.promise;
|
|
|
|
};
|