diff --git a/tests/cli.js b/tests/cli.js index 1ec0a88a11..931e7caab3 100644 --- a/tests/cli.js +++ b/tests/cli.js @@ -264,6 +264,7 @@ exports.group = { test.done(); }, + // Overrides should work for files in the current directory testOverrides: function (test) { var dir = __dirname + "/../examples/"; var rep = require("../examples/reporter.js"); @@ -308,7 +309,53 @@ exports.group = { test.done(); }, - testOverridesMatchesRelativePaths: function (test) { + // Overrides should work for implicit relative paths (without a leading ./) + testOverridesMatchesImplicitRelativePaths: function (test) { + var dir = __dirname + "/../examples/"; + var rep = require("../examples/reporter.js"); + var config = { + "asi": true, + "overrides": { + "src/bar.js": { + "asi": false + } + } + }; + + this.sinon.stub(process, "cwd").returns(dir); + this.sinon.stub(rep, "reporter"); + this.sinon.stub(shjs, "cat") + .withArgs(sinon.match(/foo\.js$/)).returns("a()") + .withArgs(sinon.match(/bar\.js$/)).returns("a()") + .withArgs(sinon.match(/config\.json$/)) + .returns(JSON.stringify(config)); + + this.sinon.stub(shjs, "test") + .withArgs("-e", sinon.match(/foo\.js$/)).returns(true) + .withArgs("-e", sinon.match(/bar\.js$/)).returns(true) + .withArgs("-e", sinon.match(/config\.json$/)).returns(true); + + cli.exit.withArgs(0).returns(true) + .withArgs(1).throws("ProcessExit"); + + // Test successful file + cli.interpret([ + "node", "jshint", "src/foo.js", "--config", "config.json", "--reporter", "reporter.js" + ]); + test.ok(rep.reporter.args[0][0].length === 0); + + // Test overriden, failed file + cli.interpret([ + "node", "jshint", "src/bar.js", "--config", "config.json", "--reporter", "reporter.js" + ]); + test.ok(rep.reporter.args[1][0].length > 0, "Error was expected but not thrown"); + test.equal(rep.reporter.args[1][0][0].error.code, "W033"); + + test.done(); + }, + + // Overrides should work for explicit relative paths (with a leading ./) + testOverridesMatchesExplicitRelativePaths: function (test) { var dir = __dirname + "/../examples/"; var rep = require("../examples/reporter.js"); var config = {