
Security News
Node.js TSC Votes to Stop Distributing Corepack
Corepack will be phased out from future Node.js releases following a TSC vote.
textlint-tester
Advanced tools
Mocha test helper library for textlint rule.
npm install --save-dev textlint-tester mocha
textlint-tester
{string} ruleName
ruleName is a name of the rule.{Function} rule
rule is the exported function of the rule.{string[]|object[]} valid
valid is an array of text which should be passed.
object
if you want to specify some options. object
can have the following properties:
{string} text
: a text to be linted{object} options
: options to be passed to the rule{string} ext
: an extension key. Default: .md
(Markdown)valid
object example:
[
"text",
{ text : "text" },
{
text: "text",
options: {
"key": "value",
},
},
{
text: "<p>this sentence is parsed as HTML document.</p>",
ext: ".html",
},
]
{object[]} invalid
invalid is an array of object which should be failed.
object
can have the following properties:
{string} text
: a text to be linted.{string} output
: a fixed text.{string} ext
: an extension key.{object[]} errors
: an array of error objects which should be raised againt the text.invalid
object example:
[
{
text: "text",
output: "text",
ext: ".txt",
errors: [
{
messages: "expected message",
line: 1,
column: 1
}
]
}
]
test/example-test.js
:
const TextLintTester = require("textlint-tester");
const tester = new TextLintTester();
// rule
const rule = require("textlint-rule-no-todo");
// ruleName, rule, { valid, invalid }
tester.run("no-todo", rule, {
valid: [
"This is ok",
{
// text with options
text: "This is test",
options: {
"key": "value"
}
}
],
invalid: [
// line, column
{
text: "- [ ] string",
errors: [
{
message: "Found TODO: '- [ ] string'",
line: 1,
column: 3
}
]
},
// index
{
text: "- [ ] string",
errors: [
{
message: "Found TODO: '- [ ] string'",
index: 2
}
]
},
{
text: "TODO: string",
options: {"key": "value"},
errors: [
{
message: "found TODO: 'TODO: string'",
line: 1,
column: 1
}
]
},
{
text: "TODO: string",
output: "string", // <= fixed output
errors: [
{
message: "found TODO: 'TODO: string'",
line: 1,
column: 1
}
]
}
]
});
Run the tests:
$(npm bin)/mocha test/
git checkout -b my-new-feature
git commit -am 'Add some feature'
git push origin my-new-feature
MIT
FAQs
testing tool for textlint rule.
The npm package textlint-tester receives a total of 18,916 weekly downloads. As such, textlint-tester popularity was classified as popular.
We found that textlint-tester demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Corepack will be phased out from future Node.js releases following a TSC vote.
Research
Security News
Research uncovers Black Basta's plans to exploit package registries for ransomware delivery alongside evidence of similar attacks already targeting open source ecosystems.
Security News
Oxlint's beta release introduces 500+ built-in linting rules while delivering twice the speed of previous versions, with future support planned for custom plugins and improved IDE integration.