stylelint-rule-tester

An easy way to test stylelint rules

stylelint-rule-tester

An easy way to test stylelintrules.

For documentation, read the comments (or if you would like to help write docs, please PR!).

For examples, check out the rule tests in stylelint.

Here's a quick example, though. Given the following test:

var ruleTester = require('stylelint-rule-tester');
var noEmptyBlocksRule = require('path/to/noEmptyBlocksRule');

var testRule = ruleTester(noEmptyBlocksRule, 'my-no-empty-blocks-rule');
var rejectionMessage = 'Please, no empty blocks!';

testRule('always', function(tr) {
  tr.ok('', 'empty');
  tr.ok('@import \'foo.css\';', 'blockless at-rule');

  tr.ok('a { color: pink; }', 'rule with a declaration');
  tr.ok('@media print { a { color: pink; } }', 'at-rule with a rule with a declaration');

  tr.notOk('a {}', rejectionMessage, 'empty rule block');
  tr.notOk('a { }', rejectionMessage, 'rule block with a single space');
  tr.notOk('a {\n}', rejectionMessage, 'rule block with a newline');
  tr.notOk('@media print {}', rejectionMessage, 'empty at-rule block');
  tr.notOk('@media print { a {} }', {
    message: rejectionMessage,
    line: 6,
    column: 3,
  }, 'at-rule block with an empty rule block');
});

The following TAP output will be logged:

TAP version 13
#
css: ""
rule: my-no-empty-blocks-rule
options: "always"
ok 1 empty should pass
#
css: "@import 'foo.css';"
rule: my-no-empty-blocks-rule
options: "always"
ok 2 blockless at-rule should pass
#
css: "a { color: pink; }"
rule: my-no-empty-blocks-rule
options: "always"
ok 3 rule with a declaration should pass
#
css: "@media print { a { color: pink; } }"
rule: my-no-empty-blocks-rule
options: "always"
ok 4 at-rule with a rule with a declaration should pass
#
css: "a {}"
rule: my-no-empty-blocks-rule
options: "always"
ok 5 empty rule block should warn
ok 6 empty rule block warning message should be "Please, no empty blocks!"
#
css: "a { }"
rule: my-no-empty-blocks-rule
options: "always"
ok 7 rule block with a single space should warn
ok 8 rule block with a single space warning message should be "Please, no empty blocks!"
#
css: "a {\n}"
rule: my-no-empty-blocks-rule
options: "always"
ok 9 rule block with a newline should warn
ok 10 rule block with a newline warning message should be "Please, no empty blocks!"
#
css: "@media print {}"
rule: my-no-empty-blocks-rule
options: "always"
ok 11 empty at-rule block should warn
ok 12 empty at-rule block warning message should be "Please, no empty blocks!"
#
css: "@media print { a {} }"
rule: my-no-empty-blocks-rule
options: "always"
ok 13 at-rule block with an empty rule block should warn
ok 14 at-rule block with an empty rule block warning message should be "Please, no empty blocks!"
ok 15 at-rule block with an empty rule block warning should be at line 6
ok 16 at-rule block with an empty rule block warning should be at column 3

1..16
# tests 16
# pass  16

# ok

HomePage

https://github.com/stylelint/stylelint-rule-tester#readme

Repository

https+https://github.com/stylelint/stylelint-rule-tester


上一篇:jest-css-modules-transform
下一篇:stylelint-csstree-validator

相关推荐

  • 基于vue的网页标尺辅助线工具(vue-ruler-tool)

    标尺辅助线.gif(https://img.javascriptcn.com/87baf358537b3822a2e5db7b79cfa4c5 "标尺辅助线.gif") 最近在网上找到一个...

    2 年前
  • web-component-tester

    webcomponenttester makes testing your web components a breeze NPM version(http://img.shields.io/npm...

    1 年前
  • vrsource-tslint-rules

    Extension rules for tslint Purpose This project includes a variety of tslint rules we have found ...

    1 年前
  • unified-lint-rule

    unified plugin to make it a bit easier to create linting rules unifiedlintrule Buildbuildbadgebui...

    2 年前
  • typings-tester

    TypeScript definition testing library Typings Tester npm versionnpmimagenpmurl Build Statustravisi...

    2 年前
  • typescript-definition-tester

    Purpose The purpose of this repository is to wrap the TypeScript compiler so that a consumer can...

    2 个月前
  • tslint-misc-rules

    Collection of miscellaneous TSLint rules Build Status(https://travisci.org/jwbay/tslintmiscrules.sv...

    1 年前
  • tslint-ionic-rules

    Common TypeScript lint rules/preferences for Ionic. TSLint rules for Ionic Common TypeScript lint...

    1 年前
  • tslint-eslint-rules

    Improve your TSLint with the missing ESLint Rules Build Status(https://travisci.org/buzinas/tslinte...

    1 年前
  • tree-layout-tester

    Tests cases for various tree layout algorithms treelayouttester ================== Checks a tree la...

    2 个月前

官方社区

扫码加入 JavaScript 社区