textlint-tester
Mocha test helper library for textlint rule.
Installation
npm install -D textlint-tester
Usage
- Write tests by using
textlint-tester
- Run tests by Mocha
TextLintTester
TextLintTester#run(ruleName, rule, {valid=[], invalid=[]})
{string} ruleName
ruleName is name of thee rule{Function} rule
rule is the function of rule{string[]|object[]} valid
- e.g.)
["text", { text : "text" }]
- e.g.)
{object[]} invalid
- e.g.)
[{text: "text", errors: [ messages : "expected message" ]}
- e.g.)
example
var TextLintTester = require("textlint-tester");
// rules
var noTodo = require("textlint-rule-no-todo");
var maxNumberOfLine = require("textlint-rule-max-number-of-lines");
var tester = new TextLintTester();
// ruleName, rule, expected[]
tester.run("no-todo", noTodo, {
valid: [
"string, test desu",
{
text: "日本語 is Japanese."
}
],
invalid: [
// text, expected errors
{
text: "- [ ] string",
errors: [
{message: "found TODO: '- [ ] string'"}
]
},
{
text: "TODO: string",
errors: [
{message: "found TODO: 'TODO: string'"}
]
}
]
});
tester.run("max-number-of-lines", maxNumberOfLine, {
valid: [
"string, test desu",
{
text: "日本語 is Japanese."
}
],
invalid: [
{
text: `1
2
3
`,
options: {
max: 2
},
errors: [
{
ruleId: "max-number-of-lines",
message: "Document is too long(number of lines: 3)."
}
]
}
]
});
Tests
mocha test/
# npm test
Contributing
- Fork it!
- Create your feature branch:
git checkout -b my-new-feature
- Commit your changes:
git commit -am 'Add some feature'
- Push to the branch:
git push origin my-new-feature
- Submit a pull request :D
License
MIT