/
standalone-parseErrors.test.js
61 lines (52 loc) · 1.53 KB
/
standalone-parseErrors.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
'use strict';
const blockNoEmpty = require('../rules/block-no-empty');
const configBlockNoEmpty = require('./fixtures/config-block-no-empty');
const path = require('path');
const replaceBackslashes = require('./replaceBackslashes');
const standalone = require('../standalone');
jest.mock('../rules/block-no-empty');
blockNoEmpty.mockImplementation(() => {
return (root, result) => {
result.warn('Some parseError', {
stylelintType: 'parseError',
});
};
});
test('standalone with deprecations', async () => {
const data = await standalone({
code: 'a {}',
config: configBlockNoEmpty,
});
expect(data.output).toContain('Some parseError');
expect(data.results).toHaveLength(1);
expect(data.results[0].parseErrors).toHaveLength(1);
expect(data.results[0].parseErrors[0].text).toBe('Some parseError');
});
test('file with correct syntax reported correctly', async () => {
const data = await standalone({
files: replaceBackslashes(path.join(__dirname, 'fixtures/broken-syntax/correct-syntax.css')),
});
expect(data.results[0]).toMatchObject({
parseErrors: [],
errored: false,
warnings: [],
});
});
test('file with invalid syntax reported correctly', async () => {
const data = await standalone({
files: [replaceBackslashes(path.join(__dirname, 'fixtures/broken-syntax/broken-syntax.css'))],
});
expect(data.results[0]).toMatchObject({
parseErrors: [],
errored: true,
warnings: [
{
column: 1,
line: 1,
rule: 'CssSyntaxError',
severity: 'error',
text: 'Unexpected } (CssSyntaxError)',
},
],
});
});