now includes mocha

This commit is contained in:
Philipp Kunz 2016-01-30 05:29:54 +01:00
parent 7c6b5afd5f
commit 8fb4a60fb3
9 changed files with 98 additions and 10 deletions

18
index.d.ts vendored
View File

@ -2,6 +2,7 @@
declare module NpmtsPlugins { declare module NpmtsPlugins {
var init: () => { var init: () => {
beautylog: any; beautylog: any;
fs: any;
gulp: any; gulp: any;
g: { g: {
insert: any; insert: any;
@ -10,18 +11,30 @@ declare module NpmtsPlugins {
typescript: any; typescript: any;
}; };
mergeStream: any; mergeStream: any;
mocha: any;
path: any; path: any;
q: any;
smartcli: any; smartcli: any;
}; };
} }
declare module NpmtsPaths { declare module NpmtsPaths {
var init: () => any; var init: () => any;
} }
declare module NpmtsOptions {
var run: () => any;
}
declare module NpmtsDefault { declare module NpmtsDefault {
var init: () => void; var run: () => any;
}
declare module NpmtsTests {
var run: () => any;
}
declare module NpmtsPromisechain {
var init: () => any;
} }
declare var plugins: { declare var plugins: {
beautylog: any; beautylog: any;
fs: any;
gulp: any; gulp: any;
g: { g: {
insert: any; insert: any;
@ -30,7 +43,10 @@ declare var plugins: {
typescript: any; typescript: any;
}; };
mergeStream: any; mergeStream: any;
mocha: any;
path: any; path: any;
q: any;
smartcli: any; smartcli: any;
}; };
declare var paths: any; declare var paths: any;
declare var promisechain: any;

View File

@ -6,6 +6,7 @@ var NpmtsPlugins;
NpmtsPlugins.init = function () { NpmtsPlugins.init = function () {
var plugins = { var plugins = {
beautylog: require("beautylog"), beautylog: require("beautylog"),
fs: require("fs"),
gulp: require("gulp"), gulp: require("gulp"),
g: { g: {
insert: require("gulp-insert"), insert: require("gulp-insert"),
@ -14,7 +15,9 @@ var NpmtsPlugins;
typescript: require("gulp-typescript") typescript: require("gulp-typescript")
}, },
mergeStream: require("merge2"), mergeStream: require("merge2"),
mocha: require("mocha"),
path: require("path"), path: require("path"),
q: require("q"),
smartcli: require("smartcli") smartcli: require("smartcli")
}; };
return plugins; return plugins;
@ -30,14 +33,25 @@ var NpmtsPaths;
paths.tsd = plugins.path.join(paths.cwd, "ts/tsd.json"); paths.tsd = plugins.path.join(paths.cwd, "ts/tsd.json");
paths.indexTS = plugins.path.join(paths.cwd, "ts/index.ts"); paths.indexTS = plugins.path.join(paths.cwd, "ts/index.ts");
paths.testTS = plugins.path.join(paths.cwd, "ts/test.ts"); paths.testTS = plugins.path.join(paths.cwd, "ts/test.ts");
paths.testDir = plugins.path.join(paths.cwd, "test/");
return paths; return paths;
}; };
})(NpmtsPaths || (NpmtsPaths = {})); })(NpmtsPaths || (NpmtsPaths = {}));
/// <reference path="./index.ts" /> /// <reference path="./index.ts" />
var NpmtsOptions;
(function (NpmtsOptions) {
NpmtsOptions.run = function () {
var done = plugins.q.defer();
done.resolve(); //TODO: check for options
return done.promise;
};
})(NpmtsOptions || (NpmtsOptions = {}));
/// <reference path="./index.ts" />
/// <reference path="./index.ts" /> /// <reference path="./index.ts" />
var NpmtsDefault; var NpmtsDefault;
(function (NpmtsDefault) { (function (NpmtsDefault) {
NpmtsDefault.init = function () { NpmtsDefault.run = function () {
var done = plugins.q.defer();
plugins.gulp.task("defaultTsd", function (cb) { plugins.gulp.task("defaultTsd", function (cb) {
if (!process.env.TRAVIS) { if (!process.env.TRAVIS) {
plugins.g.tsd({ plugins.g.tsd({
@ -71,18 +85,56 @@ var NpmtsDefault;
.pipe(plugins.g.typescript({ .pipe(plugins.g.typescript({
out: "test.js" out: "test.js"
})) }))
.pipe(plugins.gulp.dest(paths.cwd)); .pipe(plugins.gulp.dest(paths.testDir));
}); });
plugins.gulp.task("defaultCleanup", function (cb) { plugins.gulp.task("defaultCleanup", function (cb) {
plugins.beautylog.success("TypeScript for this module compiled successfully."); plugins.beautylog.success("TypeScript for this module compiled successfully.");
done.resolve();
cb(); cb();
}); });
plugins.gulp.task("default", function (cb) { plugins.gulp.task("default", function (cb) {
plugins.g.sequence("defaultTsd", "defaultIndexTS", "defaultTestTS", "defaultCleanup", cb); plugins.g.sequence("defaultTsd", "defaultIndexTS", "defaultTestTS", "defaultCleanup", cb);
}); });
plugins.gulp.start.apply(plugins.gulp, ['default']); plugins.gulp.start.apply(plugins.gulp, ['default']);
return done.promise;
}; };
})(NpmtsDefault || (NpmtsDefault = {})); })(NpmtsDefault || (NpmtsDefault = {}));
/// <reference path="./index.ts" />
var NpmtsTests;
(function (NpmtsTests) {
NpmtsTests.run = function () {
var done = plugins.q.defer();
plugins.beautylog.info("Now running mocha tests");
// Instantiate a Mocha instance.
var mocha = new plugins.mocha();
var testDir = paths.testDir;
// Add each .js file to the mocha instance
plugins.fs.readdirSync(testDir).filter(function (file) {
// Only keep the .js files
return file.substr(-3) === '.js';
}).forEach(function (file) {
mocha.addFile(plugins.path.join(testDir, file));
});
// Run the tests.
mocha.run(function (failures) {
process.on('exit', function () {
process.exit(failures);
});
});
return done.promise;
};
})(NpmtsTests || (NpmtsTests = {}));
/// <reference path="./index.ts" />
var NpmtsPromisechain;
(function (NpmtsPromisechain) {
NpmtsPromisechain.init = function () {
var promisechain;
NpmtsOptions.run()
.then(NpmtsDefault.run)
.then(NpmtsTests.run);
return promisechain;
};
})(NpmtsPromisechain || (NpmtsPromisechain = {}));
/// <reference path="./typings/tsd.d.ts" /> /// <reference path="./typings/tsd.d.ts" />
/// <reference path="./npmts.plugins.ts" /> /// <reference path="./npmts.plugins.ts" />
/// <reference path="./npmts.cli.ts" /> /// <reference path="./npmts.cli.ts" />
@ -90,6 +142,8 @@ var NpmtsDefault;
/// <reference path="./npmts.options.ts" /> /// <reference path="./npmts.options.ts" />
/// <reference path="./npmts.custom.ts" /> /// <reference path="./npmts.custom.ts" />
/// <reference path="./npmts.default.ts" /> /// <reference path="./npmts.default.ts" />
/// <reference path="./npmts.tests.ts" />
/// <reference path="./npmts.promisechain.ts" />
var plugins = NpmtsPlugins.init(); var plugins = NpmtsPlugins.init();
var paths = NpmtsPaths.init(); var paths = NpmtsPaths.init();
NpmtsDefault.init(); var promisechain = NpmtsPromisechain.init();

View File

@ -9,6 +9,5 @@
"author": "", "author": "",
"license": "ISC", "license": "ISC",
"dependencies": { "dependencies": {
"npmts": "*"
} }
} }

1
test/assets/test/test.js Normal file
View File

@ -0,0 +1 @@

View File

@ -10,4 +10,4 @@
var plugins = NpmtsPlugins.init(); var plugins = NpmtsPlugins.init();
var paths = NpmtsPaths.init(); var paths = NpmtsPaths.init();
NpmtsDefault.init(); var promisechain = NpmtsPromisechain.init();

View File

@ -1,7 +1,8 @@
/// <reference path="./index.ts" /> /// <reference path="./index.ts" />
module NpmtsDefault { module NpmtsDefault {
export var init = function() { export var run = function() {
var done = plugins.q.defer();
plugins.gulp.task("defaultTsd",function(cb){ plugins.gulp.task("defaultTsd",function(cb){
if(!process.env.TRAVIS) { if(!process.env.TRAVIS) {
plugins.g.tsd({ plugins.g.tsd({
@ -44,6 +45,7 @@ module NpmtsDefault {
plugins.gulp.task("defaultCleanup",function(cb){ plugins.gulp.task("defaultCleanup",function(cb){
plugins.beautylog.success("TypeScript for this module compiled successfully."); plugins.beautylog.success("TypeScript for this module compiled successfully.");
done.resolve();
cb(); cb();
}); });
@ -52,5 +54,6 @@ module NpmtsDefault {
}); });
plugins.gulp.start.apply(plugins.gulp, ['default']); plugins.gulp.start.apply(plugins.gulp, ['default']);
return done.promise;
} }
} }

View File

@ -0,0 +1,8 @@
/// <reference path="./index.ts" />
module NpmtsOptions {
export var run = function(){
var done = plugins.q.defer();
done.resolve(); //TODO: check for options
return done.promise;
}
}

View File

@ -1,6 +1,10 @@
/// <reference path="./index.ts" /> /// <reference path="./index.ts" />
module NpmtsPromisechain { module NpmtsPromisechain {
export var init = function(){ export var init = function(){
var promisechain;
NpmtsOptions.run()
.then(NpmtsDefault.run)
.then(NpmtsTests.run);
return promisechain;
} }
} }

View File

@ -1,10 +1,12 @@
/// <reference path="./index.ts" /> /// <reference path="./index.ts" />
module NpmtsTests { module NpmtsTests {
export var init = function() { export var run = function() {
var done = plugins.q.defer();
plugins.beautylog.info("Now running mocha tests");
// Instantiate a Mocha instance. // Instantiate a Mocha instance.
var mocha = new plugins.mocha(); var mocha = new plugins.mocha();
var testDir = 'some/dir/test'; var testDir = paths.testDir;
// Add each .js file to the mocha instance // Add each .js file to the mocha instance
plugins.fs.readdirSync(testDir).filter(function(file){ plugins.fs.readdirSync(testDir).filter(function(file){
@ -23,5 +25,6 @@ module NpmtsTests {
process.exit(failures); process.exit(failures);
}); });
}); });
return done.promise;
} }
} }