Skip to content

Commit

Permalink
Normalizing expected output in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nickdeis committed Apr 27, 2020
1 parent 535fe31 commit 65b2157
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,4 @@ node_js:
- "12"
os:
- linux
- osx
- windows
15 changes: 11 additions & 4 deletions tests/lib/rules/notice.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,25 +55,32 @@ function createToleranceTestCase(nonMatchingTolerance) {
};
}

/**
* Since we norm the output of templates, we need to norm the expected output of --fix
*/
function readAndNormalize(rpath){
return fs.readFileSync(__dirname + rpath, "utf8").replace(/\r\n/g, "\n");
}

ruleTester.run("notice", rule, {
invalid: [
{
code: noStyle,
options: [{ mustMatch, template }],
errors: [{ message: COULD_NOT_FIND }],
output: fs.readFileSync(__dirname + "/fix-result-1.js", "utf8")
output: readAndNormalize("/fix-result-1.js")
},
{
code: notExact,
options: [{ mustMatch, template }],
errors: [{ message: COULD_NOT_FIND }],
output: fs.readFileSync(__dirname + "/fix-result-2.js", "utf8")
output: readAndNormalize("/fix-result-2.js")
},
{
code: notExact,
options: [{ mustMatch, template, onNonMatchingHeader: "replace" }],
errors: [{ message: COULD_NOT_FIND }],
output: fs.readFileSync(__dirname + "/fix-result-3.js", "utf8")
output: readAndNormalize("/fix-result-3.js")
},
{
code: notExact,
Expand All @@ -93,7 +100,7 @@ ruleTester.run("notice", rule, {
code: noStyle,
options: [{ mustMatch, template, messages: { whenFailedToMatch: "Custom message" } }],
errors: [{ message: "Custom message" }],
output: fs.readFileSync(__dirname + "/fix-result-1.js", "utf8")
output: readAndNormalize("/fix-result-1.js")
},
/**
* Test the case where no template file is set, should COULD_NOT_FIND error with no autofixes suggested
Expand Down

0 comments on commit 65b2157

Please sign in to comment.