-
Notifications
You must be signed in to change notification settings - Fork 76
/
sassMsgFormatter.test.js
89 lines (86 loc) · 3.14 KB
/
sassMsgFormatter.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
81
82
83
84
85
86
87
88
89
const formatter = require('./sassMsgFormatter');
const chalk = require('chalk');
const ERROR = chalk.bold.red;
const WARNING = chalk.yellow;
const URL = chalk.underline.cyan;
const TITLE = chalk.bgYellow;
const exampleOne = {
source: 'test1.js',
errored: true,
warnings: [
{
severity: 'error',
line: 21,
column: 33,
rule: 'declaration-property-unit-blacklist',
text: 'Unexpected value in property "color"',
},
],
};
const exampleTwo = {
source: 'test2.js',
errored: true,
warnings: [
{
severity: 'error',
line: 123,
column: 76,
rule: 'declaration-property-value-blacklist',
text: 'Unexpected value in "font-family"',
},
],
};
describe('sassMsgFormatter', () => {
it('filters for errors', () => {
// this function should return false unless errored is equal to true
expect(formatter.filterForErrors({ errored: undefined })).toBeFalsy();
expect(formatter.filterForErrors({ errored: true })).toBeTruthy();
expect(formatter.filterForErrors({ errored: false })).toBeFalsy();
expect(formatter.filterForErrors({ errored: null })).toBeFalsy();
});
it('generates error icons', () => {
// expect(generateErrorIcon('error')).toEqual(ERROR('ERROR'));
expect(formatter.generateErrorIcon('error')).toContain('ERROR');
expect(formatter.generateErrorIcon('warning')).toContain('warning');
expect(formatter.generateErrorIcon(undefined)).toHaveLength(0);
});
it('formats tabbing', () => {
expect(formatter.formatTabbing({ line: 121, column: 23 })).toHaveLength(1);
expect(formatter.formatTabbing({ line: 1, column: 123 })).toHaveLength(3);
expect(formatter.formatTabbing({ line: 14, column: 23 })).toHaveLength(3);
});
it('creates custom message', () => {
console.log(exampleOne.warnings[0].text);
expect(createCustomMessage(exampleOne.warnings[0].text)).toContain(
URL('https://www.carbondesignsystem.com/guidelines/color/usage')
);
expect(createCustomMessage(exampleTwo.warnings[0].text)).toContain(
URL('https://www.carbondesignsystem.com/guidelines/typography/productive')
);
expect(createCustomMessage(null)).toHaveLength(0);
});
it('formats errors', () => {
expect(formatter.formatError(exampleOne.warnings)).toContain(ERROR('ERROR'));
expect(formatter.formatError(exampleTwo.warnings)).toContain(ERROR('ERROR'));
expect(
formatError([
{
severity: 'warning',
line: 123,
column: 45,
rule: 'insert-rule-here',
text: 'error text',
},
])
).toContain(WARNING('warning'));
});
it('formats message', () => {
const resultsTest = [exampleOne, exampleTwo, { errored: false, warnings: undefined }];
expect(resultsTest.filter(formatter.filterForErrors)).toHaveLength(2);
expect(formatter(resultsTest)).toContain(TITLE('\n!! WARNINGS !!\n\n'));
expect(formatter(resultsTest)).toContain(formatError(exampleOne.warnings));
expect(formatter(resultsTest)).toContain(formatError(exampleTwo.warnings));
expect(formatter([{ errored: false, warnings: undefined }])).toMatch('');
expect(formatter(null)).toHaveLength(0);
});
});