-
-
Notifications
You must be signed in to change notification settings - Fork 111
/
Copy pathindex.test.mjs
101 lines (82 loc) · 2.35 KB
/
index.test.mjs
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
import { beforeEach, describe, it } from 'node:test'; // eslint-disable-line n/no-unsupported-features/node-builtins
import assert from 'node:assert/strict';
import fs from 'node:fs';
import stylelint from 'stylelint';
import config from '../index.js';
describe('flags no warnings with valid css', () => {
const validCss = fs.readFileSync('./__tests__/valid.css', 'utf-8');
let result;
beforeEach(async () => {
result = await stylelint.lint({
code: validCss,
config,
});
});
it('did not error', () => {
assert.equal(result.errored, false);
});
it('flags no warnings', () => {
assert.equal(result.results[0].warnings.length, 0);
});
});
describe('flags warnings with invalid css', () => {
const invalidCss = fs.readFileSync('./__tests__/invalid.css', 'utf-8');
let result;
beforeEach(async () => {
result = await stylelint.lint({
code: invalidCss,
config,
});
});
it('did error', () => {
assert.equal(result.errored, true);
});
it('flags warnings', () => {
assert.equal(result.results[0].warnings.length, 5);
});
it('correct warning text', () => {
assert.deepEqual(
result.results[0].warnings.map((w) => w.text),
[
'Expected custom media query name "--FOO" to be kebab-case',
'Expected custom property name "--FOO" to be kebab-case',
'Expected keyframe name "FOO" to be kebab-case',
'Expected class selector ".FOO" to be kebab-case',
'Expected id selector "#FOO" to be kebab-case',
],
);
});
it('correct rule flagged', () => {
assert.deepEqual(
result.results[0].warnings.map((w) => w.rule),
[
'custom-media-pattern',
'custom-property-pattern',
'keyframes-name-pattern',
'selector-class-pattern',
'selector-id-pattern',
],
);
});
it('correct severity flagged', () => {
assert.equal(result.results[0].warnings[0].severity, 'error');
});
it('correct line number', () => {
assert.equal(result.results[0].warnings[0].line, 1);
});
it('correct column number', () => {
assert.equal(result.results[0].warnings[0].column, 15);
});
});
describe('deprecated rules are excluded', () => {
const ruleNames = Object.keys(config.rules);
it('is not empty', () => {
assert.ok(ruleNames.length > 0);
});
for (const ruleName of ruleNames) {
it(`${ruleName}`, async () => {
const rule = await stylelint.rules[ruleName];
assert.ok(!rule.meta.deprecated);
});
}
});