Skip to content
This repository has been archived by the owner on Dec 19, 2023. It is now read-only.

Commit

Permalink
Updated for it v0.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
doug-martin committed Jan 12, 2013
1 parent 4d58201 commit a83741c
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 42 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
node_modules/
npm-debug.log
.idea
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
},
"devDependencies": {
"grunt": "~0.3.17",
"it": "0.0.5"
"it": "0.1.0"
},
"keywords": [
"gruntplugin",
Expand All @@ -40,6 +40,6 @@
"comb"
],
"dependencies": {
"comb": "~0.1.91"
"comb": "~0.2.1"
}
}
81 changes: 41 additions & 40 deletions tasks/it.js
Original file line number Diff line number Diff line change
Expand Up @@ -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!!!';
// });

};
}
;

0 comments on commit a83741c

Please sign in to comment.