-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
80 lines (69 loc) · 2.51 KB
/
test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import path from 'node:path';
import test from 'ava';
import stylelint from 'stylelint';
import tidy from '.';
const goodSheet = path.resolve(__dirname, 'fixture', 'good.css');
const badSheet = path.resolve(__dirname, 'fixture', 'bad.css');
const lintFile = (filePath) => {
return stylelint.lint({
config : tidy,
files : filePath
});
};
const lintText = (text) => {
return stylelint.lint({
config : tidy,
code : text
});
};
const getRules = (results) => {
const ruleIds = results[0].warnings.map((x) => {
return x.rule;
});
return [...new Set(ruleIds)];
};
test('smoke test', async (t) => {
const { errored, results } = await lintText('p {\n color: inherit;\n}\n');
t.false(errored);
t.deepEqual(getRules(results), []);
});
test('good stylesheet', async (t) => {
const { errored, results } = await lintFile(goodSheet);
t.false(errored);
t.deepEqual(getRules(results), []);
});
test('bad stylesheet', async (t) => {
const { errored, results } = await lintFile(badSheet);
t.true(errored);
t.deepEqual(getRules(results), [
'color-named',
'font-weight-notation',
'selector-type-no-unknown'
]);
});
test('disallows todos regardless of case', async (t) => {
const lowerCase = await lintText('/* todo: */\n');
const upperCase = await lintText('/* TODO: */\n');
t.true(lowerCase.errored);
t.true(upperCase.errored);
t.deepEqual(getRules(lowerCase.results), ['comment-word-disallowed-list']);
t.deepEqual(getRules(upperCase.results), ['comment-word-disallowed-list']);
});
test('allows multi-line comma separated selector list', async (t) => {
const { errored, results } = await lintText('div,\np {\n font-size: inherit;\n}\n');
t.false(errored);
t.deepEqual(getRules(results), []);
});
test('disallows one-line comma separated selector list', async (t) => {
const { errored, results } = await lintText('div,p {\n font-size: inherit;\n}\n');
t.true(errored);
t.deepEqual(getRules(results), ['selector-list-comma-space-after']);
});
test('requires single quotes even if it needs escaping', async (t) => {
const unescapedDouble = await lintText('a {\n content: "x\'y\'z";\n}\n');
const escapedSingle = await lintText('a {\n content: \'x\\\'y\\\'z\';\n}\n');
t.true(unescapedDouble.errored);
t.false(escapedSingle.errored);
t.deepEqual(getRules(unescapedDouble.results), ['string-quotes']);
t.deepEqual(getRules(escapedSingle.results), []);
});