Skip to content

Commit ccd4b50

Browse files
Added tests
1 parent 94dcf2b commit ccd4b50

File tree

4 files changed

+107
-1
lines changed

4 files changed

+107
-1
lines changed

packages/stylelint-config-airbnb/package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66
"scripts": {
77
"prelint": "editorconfig-tools check . test/",
88
"lint": "eslint .",
9-
"test": "npm run --silent lint",
9+
"pretest": "npm run --silent lint",
10+
"test": "npm run --silent tests-only",
11+
"tests-only": "ava ./test/test-*.js",
1012
"travis": "npm run --silent test"
1113
},
1214
"repository": {
@@ -48,6 +50,7 @@
4850
"stylelint-scss": "^1.2.1"
4951
},
5052
"dependencies": {
53+
"ava": "0.23.0",
5154
"editorconfig-tools": "^0.1.1"
5255
}
5356
}
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
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

Comments
 (0)