Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Docs: Adding rule summary to README.
More details, such as a quick summary of what the rule does, can be added later if needed.
- Loading branch information
1 parent
fd0ba50
commit 8cbb8b9
Showing
2 changed files
with
77 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/** | ||
* @fileoverview Unit tests for the README. | ||
* @author Kevin Partington | ||
*/ | ||
"use strict"; | ||
|
||
//------------------------------------------------------------------------------ | ||
// Requirements | ||
//------------------------------------------------------------------------------ | ||
|
||
var assert = require("chai").assert, | ||
fs = require("fs"), | ||
path = require("path"); | ||
|
||
//------------------------------------------------------------------------------ | ||
// Tests | ||
//------------------------------------------------------------------------------ | ||
|
||
describe("README", function () { | ||
var ruleGroupRegex = /## Available Rules[\s\S]*(?:\n(?=##)|$)/, | ||
ruleRegex = /^\* \[([a-z-]+)\]\(\.\/docs\/rules\/\1\.md\)$/gm, | ||
fileContents, | ||
availableRules; | ||
|
||
before(function (done) { | ||
fs.readFile("./README.md", "utf8", function (err, contents) { | ||
if (err) throw err; | ||
|
||
fileContents = contents; | ||
|
||
fs.readdir("./lib/rules", function (err, files) { | ||
if (err) throw err; | ||
|
||
availableRules = files.map(function (file) { | ||
return path.basename(file, ".js"); | ||
}); | ||
|
||
done(); | ||
}); | ||
}); | ||
}); | ||
|
||
it("should find the rules", function () { | ||
var match = ruleGroupRegex.exec(fileContents), | ||
foundRules = [], | ||
ruleSection; | ||
|
||
assert.ok(match, "Rule section should be present"); | ||
|
||
ruleSection = match[0]; | ||
|
||
while ((match = ruleRegex.exec(ruleSection)) !== null) { | ||
foundRules.push(match[1]); | ||
} | ||
|
||
assert.deepEqual(foundRules, availableRules, "Rules in README should match available rules"); | ||
}); | ||
}); |