From a83741ceb3016ec042755a4eb341a73eaae5cca3 Mon Sep 17 00:00:00 2001 From: Doug Martin Date: Sat, 12 Jan 2013 17:03:11 -0600 Subject: [PATCH] Updated for it v0.1.0 --- .gitignore | 1 + package.json | 4 +-- tasks/it.js | 81 ++++++++++++++++++++++++++-------------------------- 3 files changed, 44 insertions(+), 42 deletions(-) diff --git a/.gitignore b/.gitignore index 1ca9571..1ae40a4 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ node_modules/ npm-debug.log +.idea diff --git a/package.json b/package.json index c57c4ae..63122bd 100644 --- a/package.json +++ b/package.json @@ -30,7 +30,7 @@ }, "devDependencies": { "grunt": "~0.3.17", - "it": "0.0.5" + "it": "0.1.0" }, "keywords": [ "gruntplugin", @@ -40,6 +40,6 @@ "comb" ], "dependencies": { - "comb": "~0.1.91" + "comb": "~0.2.1" } } diff --git a/tasks/it.js b/tasks/it.js index a57f383..a532fee 100644 --- a/tasks/it.js +++ b/tasks/it.js @@ -23,51 +23,52 @@ module.exports = function (grunt) { // }); grunt.registerMultiTask('it', 'execute it unit tests', function () { - var it = require('it'), - comb = require('comb'), - config = grunt.config.get('it'), - files = config.files, - path = require('path'); + var it = require('it'), + comb = require('comb'), + config = grunt.config.get('it'), + files = config.files, + path = require('path'), + Module = require("module").Module, + _require = Module.prototype.require; - var filepaths = grunt.file.expandFiles(this.file.src); - grunt.file.clearRequireCache(filepaths); + //ensure then we call get the same it + Module.prototype.require = function require(mod) { + if (mod === "it") { + return it; + } else { + return _require.apply(this, arguments); + } + }; - var paths = filepaths.map(path.resolve), - options = this.data.options || {}, - reporter = options.reporter || 'dotmatrix'; + var filepaths = grunt.file.expandFiles(this.file.src); + grunt.file.clearRequireCache(filepaths); - // set the process environment - process.env.NODE_ENV = options.environment || 'test'; + var paths = filepaths.map(path.resolve), + options = this.data.options || {}, + reporter = options.reporter || 'dotmatrix'; - var done = this.async(); - return comb.serial(comb.array.compact(paths.map(function (f) { - var suite = require(f); - suite.reporter = reporter; - return suite.run ? suite.run.bind(suite) : null; - }))).then(function (results) { - var its = {}; - var errors = 0; - results.forEach(function (summary) { - comb(summary).forEach(function (testData) { - comb(testData.summaries).forEach(function (summaryData) { - if (summaryData.status === 'failed') { - errors++; - } - }); - }); - comb.merge(its, summary); + // set the process environment + process.env.NODE_ENV = options.environment || 'test'; + + var done = this.async(); + it.reporter(reporter); + paths.forEach(function (f) { + require(f); + }); + it.run().then(function (results) { + console.log(results); + done(0 === results); }); - it.printSummary(its); - done(0 === errors); - }); - }); + } + ); - // ========================================================================== - // HELPERS - // ========================================================================== +// ========================================================================== +// HELPERS +// ========================================================================== - // grunt.registerHelper('it', function () { - // return 'it!!!'; - // }); +// grunt.registerHelper('it', function () { +// return 'it!!!'; +// }); -}; +} +;