From 23cd4a452b2586f38f90d4360494fdd94e9686d2 Mon Sep 17 00:00:00 2001 From: James Owen Date: Sun, 14 Apr 2019 13:11:50 +0200 Subject: [PATCH] [[TEST]] Split the `testOverridesMatchesRelativePaths` into implicit and explicit versions Check that matching relative paths works for both implicit (without a leading `./`) and explicit (with a leading `./`) paths. --- tests/cli.js | 49 ++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 48 insertions(+), 1 deletion(-) 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 = {