Skip to content

Commit

Permalink
Fix: check output in RuleTester when errors is a number (fixes #7640) (
Browse files Browse the repository at this point in the history
  • Loading branch information
alberto committed Feb 18, 2017
1 parent cfb65c5 commit daf6f26
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 17 deletions.
9 changes: 4 additions & 5 deletions lib/testers/rule-tester.js
Expand Up @@ -494,13 +494,12 @@ RuleTester.prototype = {
assert.fail(messages[i], null, "Error should be a string or object.");
}
}
}

if (item.hasOwnProperty("output")) {
const fixResult = SourceCodeFixer.applyFixes(eslint.getSourceCode(), messages);

assert.equal(fixResult.output, item.output, "Output is incorrect.");
}
if (item.hasOwnProperty("output")) {
const fixResult = SourceCodeFixer.applyFixes(eslint.getSourceCode(), messages);

assert.equal(fixResult.output, item.output, "Output is incorrect.");
}

assertASTDidntChange(result.beforeAST, result.afterAST);
Expand Down
24 changes: 12 additions & 12 deletions tests/lib/rules/spaced-comment.js
Expand Up @@ -385,18 +385,6 @@ ruleTester.run("spaced-comment", rule, {
markers: ["/", "!<"]
}]
},
{
code: invalidShebangProgram,
output: "#!/path/to/node\n#!/second/shebang\nvar a = 3;",
errors: 1,
options: ["always"]
},
{
code: invalidShebangProgram,
output: "#!/path/to/node\n#!/second/shebang\nvar a = 3;",
errors: 1,
options: ["never"]
},
{
code: "var a = 1; /* A valid comment starting with space */",
output: "var a = 1; /*A valid comment starting with space */",
Expand Down Expand Up @@ -584,6 +572,18 @@ ruleTester.run("spaced-comment", rule, {
message: "Unexpected space or tab before '*/' in comment.",
type: "Block"
}]
},

// Parser errors
{
code: invalidShebangProgram,
errors: 1,
options: ["always"]
},
{
code: invalidShebangProgram,
errors: 1,
options: ["never"]
}
]

Expand Down
14 changes: 14 additions & 0 deletions tests/lib/testers/rule-tester.js
Expand Up @@ -181,6 +181,20 @@ describe("RuleTester", () => {
}, /Output is incorrect/);
});

it("should throw an error when the expected output doesn't match and errors is just a number", () => {

assert.throws(() => {
ruleTester.run("no-var", require("../../fixtures/testers/rule-tester/no-var"), {
valid: [
"bar = baz;"
],
invalid: [
{ code: "var foo = bar;", output: "foo = bar", errors: 1 }
]
});
}, /Output is incorrect/);
});

it("should throw an error if invalid code specifies wrong type", () => {

assert.throws(() => {
Expand Down

0 comments on commit daf6f26

Please sign in to comment.