Home

Awesome

textlint-tester Build Status

Mocha test helper library for textlint rule.

Installation

npm install -D textlint-tester mocha

Usage

  1. Write tests by using textlint-tester
  2. Run tests by Mocha

TextLintTester

TextLintTester#run(ruleName, rule, {valid=[], invalid=[]})

valid object example:

[
    "text",
    { text : "text" },
    {
        text: "text",
        options: {
            "key": "value",
        },
    },
    {
        text: "<p>this sentence is parsed as HTML document.</p>",
        ext: ".html",
    },
]

invalid object example:

[
    {
        text: "text",
        output: "text",
        ext: ".txt",
        errors: [
            {
                messages: "expected message",
                line: 1,
                column: 1
            }
        ]
    }
]

Example

test/example-test.js:

var TextLintTester = require("textlint-tester");
var tester = new TextLintTester();
// rule
var rule = require("textlint-rule-no-todo");
// ruleName, rule, { valid, invalid }
tester.run("no-todo", rule, {
    valid: [
        "this is test",
        {
            // text with options
            text: "this is test",
            options: {
                "key": "value"
            }
        }
    ],
    invalid: [
        {
            text: "- [ ] string",
            errors: [
                {
                    message: "found TODO: '- [ ] string'"
                }
            ]
        },
        {
            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/

Tests

$(npm bin)/mocha test/
# npm test

Contributing

  1. Fork it!
  2. Create your feature branch: git checkout -b my-new-feature
  3. Commit your changes: git commit -am 'Add some feature'
  4. Push to the branch: git push origin my-new-feature
  5. Submit a pull request :D

License

MIT