Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: check output in RuleTester when errors is a number (fixes #7640) #8097

Merged
merged 1 commit into from
Feb 18, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 4 additions & 5 deletions lib/testers/rule-tester.js
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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