From 21eb7cf37c509fe04a117875ac04ee7177a2e552 Mon Sep 17 00:00:00 2001 From: Tim Schaub Date: Mon, 13 Jan 2014 22:46:14 -0700 Subject: [PATCH 1/2] Reorder --- test/integration/filecount.js | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/test/integration/filecount.js b/test/integration/filecount.js index 2e8ef9fe..f3560210 100644 --- a/test/integration/filecount.js +++ b/test/integration/filecount.js @@ -1,21 +1,6 @@ var fs = require('fs'); var path = require('path'); - -/** - * Count the number of files in a directory. - * @param {string} dir Path to directory. - * @param {function(Error, number)} callback Callback. - */ -module.exports = exports = function(dir, callback) { - fs.readdir(dir, function(err, items) { - if (err) { - return callback(err); - } - numFiles(dir, items, callback); - }); -}; - function numFiles(dir, items, callback) { var total = items.length, files = 0, @@ -36,3 +21,18 @@ function numFiles(dir, items, callback) { }); }); } + + +/** + * Count the number of files in a directory. + * @param {string} dir Path to directory. + * @param {function(Error, number)} callback Callback. + */ +module.exports = exports = function(dir, callback) { + fs.readdir(dir, function(err, items) { + if (err) { + return callback(err); + } + numFiles(dir, items, callback); + }); +}; From 6a56e42295035f720cc64e3cbaa0da630b06b427 Mon Sep 17 00:00:00 2001 From: Tim Schaub Date: Mon, 13 Jan 2014 22:49:52 -0700 Subject: [PATCH 2/2] Lint and run tests --- package.json | 14 +++++-------- tasks.js | 55 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+), 9 deletions(-) create mode 100644 tasks.js diff --git a/package.json b/package.json index 39ea5a4d..9078fd23 100644 --- a/package.json +++ b/package.json @@ -30,18 +30,14 @@ } ], "scripts": { - "debug": "node --debug-brk ./node_modules/.bin/grunt cafemocha", - "test": "grunt --stack test", - "start": "grunt --stack start" + "debug": "node --debug-brk ./tasks.js test", + "test": "node ./tasks.js lint test" }, "devDependencies": { - "grunt-cli": "~0.1.11", - "grunt-contrib-jshint": "~0.8.0", - "grunt-cafe-mocha": "~0.1.10", - "grunt": "~0.4.2", "chai": "~1.8.1", - "grunt-contrib-watch": "~0.5.3", - "grunt-newer": "~0.6.0" + "jshint": "~2.4.1", + "mocha": "~1.17.0", + "glob": "~3.2.8" }, "dependencies": { "rewire": "~2.0.0" diff --git a/tasks.js b/tasks.js new file mode 100644 index 00000000..23275c45 --- /dev/null +++ b/tasks.js @@ -0,0 +1,55 @@ +var path = require('path'); + +var jshint = require('jshint/src/cli').run; +var glob = require('glob'); +var Mocha = require('mocha'); + +/** + * Run the linter. + * @param {function(Error)} done Callback. + */ +exports.lint = function(done) { + var args = ['lib', 'test', 'tasks.js']; + var passed = jshint({args: args}); + process.nextTick(function() { + done(passed ? null : new Error('JSHint failed')); + }); +}; + + +/** + * Run the tests. + * @param {function(Error)} done Callback. + */ +exports.test = function(done) { + var mocha = new Mocha(); + mocha.reporter('spec'); + mocha.ui('bdd'); + mocha.files = glob.sync('test/**/*.spec.js').map(function(file) { + return path.resolve(file); + }); + mocha.run(function(failures) { + done(failures ? new Error('Mocha failures') : null); + }); +}; + + +var tasks = process.argv.slice(2); + +function run(current) { + var task = tasks[current]; + if (task) { + exports[task](function(err) { + if (err) { + process.stderr.write(err.message + '\n'); + process.exit(1); + } else { + ++current; + run(current); + } + }); + } else { + process.exit(0); + } +} +run(0);