Permalink
Browse files

Breaking: Use strict equality in RuleTester comparisons (fixes #9417) (

  • Loading branch information...
not-an-aardvark committed Mar 22, 2018
1 parent 0bc4a38 commit 2a7ecaa2ae24e0fd921341fbb8adccb9d7d0edc2
Showing with 31 additions and 5 deletions.
  1. +2 −4 lib/testers/rule-tester.js
  2. +1 −1 tests/lib/testers/no-test-runners.js
  3. +28 −0 tests/lib/testers/rule-tester.js
@@ -399,8 +399,7 @@ class RuleTester {
if (!lodash.isEqual(beforeAST, afterAST)) {
// Not using directly to avoid performance problem in node 6.1.0. See #6111
// eslint-disable-next-line no-restricted-properties
assert.deepEqual(beforeAST, afterAST, "Rule should not modify AST.");
assert.deepStrictEqual(beforeAST, afterAST, "Rule should not modify AST.");
}
}
@@ -569,8 +568,7 @@ class RuleTester {
} else {
const fixResult = SourceCodeFixer.applyFixes(item.code, messages);
// eslint-disable-next-line no-restricted-properties
assert.equal(fixResult.output, item.output, "Output is incorrect.");
assert.strictEqual(fixResult.output, item.output, "Output is incorrect.");
}
}
@@ -26,7 +26,7 @@ try {
{ code: "var foo = bar;", output: "invalid output", errors: 1 }
]
});
}, /Output is incorrect\. \(' foo = bar;' == 'invalid output'\)$/);
}, /Output is incorrect\. \(' foo = bar;' === 'invalid output'\)$/);
} finally {
it = tmpIt;
describe = tmpDescribe;
@@ -234,6 +234,34 @@ describe("RuleTester", () => {
}, /Output is incorrect/);
});
it("should use strict equality to compare output", () => {
const replaceProgramWith5Rule = {
create: context => ({
Program(node) {
context.report({ node, message: "bad", fix: fixer => fixer.replaceText(node, "5") });
}
})
};
assert.doesNotThrow(() => {
ruleTester.run("foo", replaceProgramWith5Rule, {
valid: [],
invalid: [
{ code: "var foo = bar;", output: "5", errors: 1 }
]
});
});
assert.throws(() => {
ruleTester.run("foo", replaceProgramWith5Rule, {
valid: [],
invalid: [
{ code: "var foo = bar;", output: 5, errors: 1 }
]
});
}, /Output is incorrect/);
});
it("should throw an error when the expected output doesn't match and errors is just a number", () => {
assert.throws(() => {

0 comments on commit 2a7ecaa

Please sign in to comment.