Skip to content

Commit

Permalink
[[TEST]] Assert CLI behavior: stdin w/o filename
Browse files Browse the repository at this point in the history
Ensure that code specified via the standard input stream is linted even
in the absence of the `--filename` command-line argument.
  • Loading branch information
jugglinmike committed Nov 3, 2018
1 parent 3a8ef8b commit 71f2f1f
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions tests/cli.js
Expand Up @@ -1290,6 +1290,42 @@ exports.useStdin = {
test.done();
},

testNoFilename: function(test) {
var rep = require("../examples/reporter.js");
var errors = [];
this.sinon.stub(rep, "reporter", function (res) {
errors = errors.concat(res);
});

var dir = __dirname + "/../examples/";
this.sinon.stub(process, "cwd").returns(dir);

cli.interpret([
"node", "jshint", "--reporter=reporter.js", "-"
]);

this.stdin.send("void 0;");
this.stdin.end();

test.equal(errors.length, 0, "should not report errors");
test.equal(cli.exit.args[0][0], 0, "status code should be 2 when there is a linting error.");

errors.length = 0;
this.stdin.reset();

cli.interpret([
"node", "jshint", "--reporter=reporter.js", "-"
]);

this.stdin.send("? This is not JavaScript.");
this.stdin.end();

test.ok(errors.length > 0, "should report some number of errors");
test.equal(cli.exit.args[1][0], 2, "status code should be 2 when there is a linting error.");

test.done();
},

testFilenameOverridesOption: function (test) {
test.expect(4);
var rep = require("../examples/reporter.js");
Expand Down

0 comments on commit 71f2f1f

Please sign in to comment.