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

View File

@ -6,6 +6,7 @@ var NpmtsPlugins;
NpmtsPlugins.init = function () {
var plugins = {
beautylog: require("beautylog"),
fs: require("fs"),
gulp: require("gulp"),
g: {
insert: require("gulp-insert"),
@ -14,7 +15,9 @@ var NpmtsPlugins;
typescript: require("gulp-typescript")
},
mergeStream: require("merge2"),
mocha: require("mocha"),
path: require("path"),
q: require("q"),
smartcli: require("smartcli")
};
return plugins;
@ -30,14 +33,25 @@ var NpmtsPaths;
paths.tsd = plugins.path.join(paths.cwd, "ts/tsd.json");
paths.indexTS = plugins.path.join(paths.cwd, "ts/index.ts");
paths.testTS = plugins.path.join(paths.cwd, "ts/test.ts");
paths.testDir = plugins.path.join(paths.cwd, "test/");
return paths;
};
})(NpmtsPaths || (NpmtsPaths = {}));
/// <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" />
var NpmtsDefault;
(function (NpmtsDefault) {
NpmtsDefault.init = function () {
NpmtsDefault.run = function () {
var done = plugins.q.defer();
plugins.gulp.task("defaultTsd", function (cb) {
if (!process.env.TRAVIS) {
plugins.g.tsd({
@ -71,18 +85,56 @@ var NpmtsDefault;
.pipe(plugins.g.typescript({
out: "test.js"
}))
.pipe(plugins.gulp.dest(paths.cwd));
.pipe(plugins.gulp.dest(paths.testDir));
});
plugins.gulp.task("defaultCleanup", function (cb) {
plugins.beautylog.success("TypeScript for this module compiled successfully.");
done.resolve();
cb();
});
plugins.gulp.task("default", function (cb) {
plugins.g.sequence("defaultTsd", "defaultIndexTS", "defaultTestTS", "defaultCleanup", cb);
});
plugins.gulp.start.apply(plugins.gulp, ['default']);
return done.promise;
};
})(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="./npmts.plugins.ts" />
/// <reference path="./npmts.cli.ts" />
@ -90,6 +142,8 @@ var NpmtsDefault;
/// <reference path="./npmts.options.ts" />
/// <reference path="./npmts.custom.ts" />
/// <reference path="./npmts.default.ts" />
/// <reference path="./npmts.tests.ts" />
/// <reference path="./npmts.promisechain.ts" />
var plugins = NpmtsPlugins.init();
var paths = NpmtsPaths.init();
NpmtsDefault.init();
var promisechain = NpmtsPromisechain.init();

View File

@ -9,6 +9,5 @@
"author": "",
"license": "ISC",
"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 paths = NpmtsPaths.init();
NpmtsDefault.init();
var promisechain = NpmtsPromisechain.init();

View File

@ -1,7 +1,8 @@
/// <reference path="./index.ts" />
module NpmtsDefault {
export var init = function() {
export var run = function() {
var done = plugins.q.defer();
plugins.gulp.task("defaultTsd",function(cb){
if(!process.env.TRAVIS) {
plugins.g.tsd({
@ -44,6 +45,7 @@ module NpmtsDefault {
plugins.gulp.task("defaultCleanup",function(cb){
plugins.beautylog.success("TypeScript for this module compiled successfully.");
done.resolve();
cb();
});
@ -52,5 +54,6 @@ module NpmtsDefault {
});
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" />
module NpmtsPromisechain {
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" />
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.
var mocha = new plugins.mocha();
var testDir = 'some/dir/test';
var testDir = paths.testDir;
// Add each .js file to the mocha instance
plugins.fs.readdirSync(testDir).filter(function(file){
@ -23,5 +25,6 @@ module NpmtsTests {
process.exit(failures);
});
});
return done.promise;
}
}