|
| 1 | + |
| 2 | +import fs from 'fs'; |
| 3 | +import stylelint from 'stylelint'; |
| 4 | +import test from 'ava'; |
| 5 | +import config from '../'; |
| 6 | + |
| 7 | +const validCss = fs.readFileSync('./test/test-base-valid.css', 'utf-8'); |
| 8 | +const invalidCss = fs.readFileSync('./test/test-base-invalid.css', 'utf-8'); |
| 9 | + |
| 10 | +test('no warnings with valid css', t => { |
| 11 | + const isValid = stylelint.lint({ |
| 12 | + code: validCss, |
| 13 | + config, |
| 14 | + }) |
| 15 | + .then(data => { |
| 16 | + const { errored, results } = data; |
| 17 | + const { warnings } = results[0]; |
| 18 | + t.falsy(errored, 'no errored'); |
| 19 | + t.is(warnings.length, 0, 'flags no warnings'); |
| 20 | + }); |
| 21 | + |
| 22 | + return isValid; |
| 23 | +}); |
| 24 | + |
| 25 | +test('a warning with invalid css', t => { |
| 26 | + const isValid = stylelint.lint({ |
| 27 | + code: invalidCss, |
| 28 | + config, |
| 29 | + }) |
| 30 | + .then(data => { |
| 31 | + const { errored, results } = data; |
| 32 | + const { warnings } = results[0]; |
| 33 | + t.truthy(errored, 'errored'); |
| 34 | + t.is(warnings.length, 13, 'flags one warning'); |
| 35 | + |
| 36 | + t.is(warnings[0].text, |
| 37 | + 'Expected single space before "{" (block-opening-brace-space-before)', |
| 38 | + 'correct warning text' |
| 39 | + ); |
| 40 | + |
| 41 | + t.is(warnings[1].text, |
| 42 | + 'Expected single space after ":" (declaration-colon-space-after)', |
| 43 | + 'correct warning text' |
| 44 | + ); |
| 45 | + |
| 46 | + t.is(warnings[2].text, |
| 47 | + 'Expected single space after ":" (declaration-colon-space-after)', |
| 48 | + 'correct warning text' |
| 49 | + ); |
| 50 | + |
| 51 | + t.is(warnings[3].text, |
| 52 | + 'Expected indentation of 2 spaces (indentation)', |
| 53 | + 'correct warning text' |
| 54 | + ); |
| 55 | + |
| 56 | + t.is(warnings[4].text, |
| 57 | + 'Expected indentation of 2 spaces (indentation)', |
| 58 | + 'correct warning text' |
| 59 | + ); |
| 60 | + |
| 61 | + t.is(warnings[5].text, |
| 62 | + 'Expected empty line before non-nested rule (rule-non-nested-empty-line-before)', |
| 63 | + 'correct warning text' |
| 64 | + ); |
| 65 | + |
| 66 | + t.is(warnings[6].text, |
| 67 | + 'Expected empty line before non-nested rule (rule-non-nested-empty-line-before)', |
| 68 | + 'correct warning text' |
| 69 | + ); |
| 70 | + |
| 71 | + t.is(warnings[7].text, |
| 72 | + 'Expected newline after "," (selector-list-comma-newline-after)', |
| 73 | + 'correct warning text' |
| 74 | + ); |
| 75 | + |
| 76 | + t.is(warnings[8].text, |
| 77 | + 'Expected newline after "," (selector-list-comma-newline-after)', |
| 78 | + 'correct warning text' |
| 79 | + ); |
| 80 | + |
| 81 | + t.is(warnings[9].text, |
| 82 | + 'Unexpected id selector (selector-no-id)', |
| 83 | + 'correct warning text' |
| 84 | + ); |
| 85 | + |
| 86 | + t.is(warnings[10].text, |
| 87 | + 'Unexpected value "none" for property "border" (declaration-property-value-blacklist)', |
| 88 | + 'correct warning text' |
| 89 | + ); |
| 90 | + |
| 91 | + t.is(warnings[11].text, |
| 92 | + 'Unexpected value "none" for property "border" (declaration-property-value-blacklist)', |
| 93 | + 'correct warning text' |
| 94 | + ); |
| 95 | + |
| 96 | + t.is(warnings[12].text, |
| 97 | + 'Unexpected value "none" for property "border" (declaration-property-value-blacklist)', |
| 98 | + 'correct warning text' |
| 99 | + ); |
| 100 | + }); |
| 101 | + |
| 102 | + return isValid; |
| 103 | +}); |
0 commit comments