Skip to content

Commit

Permalink
Nodelint: fix all {} and some other errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Sannis committed Sep 25, 2010
1 parent 1a06c48 commit b20b7d3
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 31 deletions.
16 changes: 12 additions & 4 deletions lib/testrunner.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,15 @@ var nodeunit = require('./nodeunit'),

exports.run = function (files) {

var red = function (str) { return "\u001B[31m" + str + "\u001B[39m"; };
var green = function (str) { return "\u001B[32m" + str + "\u001B[39m"; };
var bold = function (str) { return "\u001B[1m" + str + "\u001B[22m"; };
var red = function (str) {
return "\u001B[31m" + str + "\u001B[39m";
};
var green = function (str) {
return "\u001B[32m" + str + "\u001B[39m";
};
var bold = function (str) {
return "\u001B[1m" + str + "\u001B[22m";
};

var start = new Date().getTime();
var paths = files.map(function (p) {
Expand Down Expand Up @@ -78,7 +84,9 @@ if (module.id === '.') {
// load package.json and read version number
if (args.length === 1 && (args[0] === '-v' || args[0] === '--version')) {
fs.readFile(__dirname + '/../package.json', function (err, content) {
if (err) throw err;
if (err) {
throw err;
}
else {
var pkg = JSON.parse(content);
console.log(pkg.version);
Expand Down
29 changes: 21 additions & 8 deletions lib/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,12 @@ exports.assertion = function (obj) {
method: obj.method || '',
message: obj.message || (obj.error && obj.error.message) || '',
error: obj.error,
passed: function () { return !this.error; },
failed: function () { return Boolean(this.error); }
passed: function () {
return !this.error;
},
failed: function () {
return Boolean(this.error);
}
};
};

Expand Down Expand Up @@ -61,10 +65,11 @@ exports.assertionList = function (arr, duration) {
var assertWrapper = function (callback) {
return function (new_method, assert_method) {
return function () {
var a;
try {
assert[assert_method].apply(global, arguments);
var message = arguments[arguments.length - 1];
var a = exports.assertion({method: new_method, message: message});
a = exports.assertion({method: new_method, message: message});
}
catch (e) {
// deepEqual error message is a bit sucky, lets improve it!
Expand All @@ -88,7 +93,7 @@ var assertWrapper = function (callback) {
e.stack.split('\n').slice(1).join('\n')
);
}
var a = exports.assertion({method: new_method, error: e});
a = exports.assertion({method: new_method, error: e});
}
callback(a);
};
Expand All @@ -113,7 +118,9 @@ exports.test = function (name, start, options, callback) {

var wrapAssert = assertWrapper(function (a) {
a_list.push(a);
process.nextTick(function () { options.log(a) });
process.nextTick(function () {
options.log(a);
});
});

var test = {
Expand All @@ -125,12 +132,16 @@ exports.test = function (name, start, options, callback) {
);
var a1 = exports.assertion({method: 'expect', error: e});
a_list.push(a1);
process.nextTick(function () { options.log(a1); });
process.nextTick(function () {
options.log(a1);
});
}
if (err) {
var a2 = exports.assertion({error: err});
a_list.push(a2);
process.nextTick(function () { options.log(a2); });
process.nextTick(function () {
options.log(a2);
});
}
var end = new Date().getTime();
process.nextTick(function () {
Expand All @@ -148,7 +159,9 @@ exports.test = function (name, start, options, callback) {
};
// add all functions from the assert module
for (var k in assert) {
test[k] = wrapAssert(k, k);
if (assert.hasOwnProperty(k)) {
test[k] = wrapAssert(k, k);
}
}
return test;
};
Expand Down
12 changes: 9 additions & 3 deletions lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,17 @@ catch (e) {
exports.modulePaths = function (paths, callback) {
async.concat(paths, function (p, cb) {
fs.stat(p, function (err, stats) {
if (err) return cb(err);
if (stats.isFile()) return cb(null, [p]);
if (err) {
return cb(err);
}
if (stats.isFile()) {
return cb(null, [p]);
}
if (stats.isDirectory()) {
fs.readdir(p, function (err, files) {
if (err) return cb(err);
if (err) {
return cb(err);
}

// filter out any filenames with unsupported extensions
var modules = files.filter(function (filename) {
Expand Down
16 changes: 12 additions & 4 deletions test/test-base.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,12 +117,20 @@ exports.testNotDeepEqual = makeTest('notDeepEqual',
exports.testStrictEqual = makeTest('strictEqual', [1, 1], [1, true]);
exports.testNotStrictEqual = makeTest('notStrictEqual', [true, 1], [1, 1]);
exports.testThrows = makeTest('throws',
[function () {throw new Error('test');}],
[function () {return;}]
[function () {
throw new Error('test');
}],
[function () {
return;
}]
);
exports.testDoesNotThrows = makeTest('doesNotThrow',
[function () {return;}],
[function () {throw new Error('test');}]
[function () {
return;
}],
[function () {
throw new Error('test');
}]
);
exports.testIfError = makeTest('ifError', [false], [new Error('test')]);

Expand Down
46 changes: 34 additions & 12 deletions test/test-runfiles.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ var setup = function (fn) {
mock_module3: require('./fixtures/dir/mock_module3'),
mock_module4: require('./fixtures/dir/mock_module4')
};
fn.call(env, test)
fn.call(env, test);
};
};

Expand All @@ -28,10 +28,18 @@ exports.testRunFiles = setup(function (test) {
var modules = [];

var opts = {
moduleStart: function () { return 'moduleStart'; },
testDone: function () { return 'testDone'; },
testStart: function () { return 'testStart'; },
log: function () { return 'log'; },
moduleStart: function () {
return 'moduleStart';
},
testDone: function () {
return 'testDone';
},
testStart: function () {
return 'testStart';
},
log: function () {
return 'log';
},
done: function (assertions) {
test.equals(assertions.failures, 0, 'failures');
test.equals(assertions.length, 4, 'length');
Expand Down Expand Up @@ -59,7 +67,9 @@ exports.testRunFiles = setup(function (test) {
test.equals(options.log, opts.log);
test.ok(typeof name === "string");
runModule_calls.push(mod);
var m = [{failed: function () {return false;}}];
var m = [{failed: function () {
return false;
}}];
modules.push(m);
callback(null, m);
};
Expand Down Expand Up @@ -100,7 +110,9 @@ exports.testEmptyDir = function (test) {

// git doesn't like empty directories, so we have to create one
path.exists(dir2, function (exists) {
if (!exists) fs.mkdirSync(dir2, 777);
if (!exists) {
fs.mkdirSync(dir2, 777);
}

// runFiles on empty directory:
nodeunit.runFiles([dir2], {
Expand Down Expand Up @@ -148,10 +160,18 @@ if (CoffeeScript) {
var modules = [];

var opts = {
moduleStart: function () {return 'moduleStart';},
testDone: function () {return 'testDone';},
testStart: function () {return 'testStart';},
log: function () {return 'log';},
moduleStart: function () {
return 'moduleStart';
},
testDone: function () {
return 'testDone';
},
testStart: function () {
return 'testStart';
},
log: function () {
return 'log';
},
done: function (assertions) {
test.equals(assertions.failures, 0, 'failures');
test.equals(assertions.length, 1, 'length');
Expand Down Expand Up @@ -179,7 +199,9 @@ if (CoffeeScript) {
test.equals(options.log, opts.log);
test.ok(typeof name === "string");
runModule_calls.push(mod);
var m = [{failed: function () {return false;}}];
var m = [{failed: function () {
return false;
}}];
modules.push(m);
callback(null, m);
};
Expand Down

0 comments on commit b20b7d3

Please sign in to comment.