Skip to content

Commit

Permalink
[[TEST]] Split the testOverridesMatchesRelativePaths into implicit …
Browse files Browse the repository at this point in the history
…and explicit versions

Check that matching relative paths works for both implicit (without a
leading `./`) and explicit (with a leading `./`) paths.
  • Loading branch information
leamingrad authored and jugglinmike committed Mar 21, 2020
1 parent e07f740 commit 23cd4a4
Showing 1 changed file with 48 additions and 1 deletion.
49 changes: 48 additions & 1 deletion tests/cli.js
Expand Up @@ -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");
Expand Down Expand Up @@ -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 = {
Expand Down

0 comments on commit 23cd4a4

Please sign in to comment.