Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simple tasks #5

Merged
merged 2 commits into from
Jan 14, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 5 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
55 changes: 55 additions & 0 deletions tasks.js
Original file line number Diff line number Diff line change
@@ -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);
30 changes: 15 additions & 15 deletions test/integration/filecount.js
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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);
});
};