-
Notifications
You must be signed in to change notification settings - Fork 2
/
.editorconfig.test.js
66 lines (53 loc) · 2.31 KB
/
.editorconfig.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
const editorconfig = require('editorconfig');
const path = require('path');
async function readConfigForFile(relativeFilePath) {
const filePath = path.join(__dirname, relativeFilePath);
const fileStyles = await editorconfig.parse(filePath);
expect(fileStyles).toBeTruthy();
// console.log('styles', fileStyles);
return fileStyles;
}
test('.editorconfig exists and can be applied to a file', async () => {
const fileStyles = await readConfigForFile('.yarnrc');
expect(fileStyles.charset).toBe('utf-8');
expect(fileStyles.trim_trailing_whitespace).toBe(true);
expect(fileStyles.insert_final_newline).toBe(true);
expect(fileStyles.quote_type).toBe('double');
expect(fileStyles.indent_style).toBe('space');
expect(fileStyles.indent_size).toBe(2);
expect(fileStyles.tab_width).toBe(2);
expect(fileStyles.max_line_length).toBe(80);
});
test('.editorconfig *.md settings', async () => {
const fileStyles = await readConfigForFile('LICENSE.md');
expect(fileStyles.charset).toBe('utf-8');
expect(fileStyles.trim_trailing_whitespace).toBe(false);
expect(fileStyles.insert_final_newline).toBe(true);
expect(fileStyles.quote_type).toBe('double');
expect(fileStyles.indent_style).toBe('space');
expect(fileStyles.indent_size).toBe(2);
expect(fileStyles.tab_width).toBe(2);
expect(fileStyles.max_line_length).toBe(80);
});
test('.editorconfig makefile settings', async () => {
const fileStyles = await readConfigForFile('makefile');
expect(fileStyles.charset).toBe('utf-8');
expect(fileStyles.trim_trailing_whitespace).toBe(true);
expect(fileStyles.insert_final_newline).toBe(true);
expect(fileStyles.quote_type).toBe('double');
expect(fileStyles.indent_style).toBe('tab');
expect(fileStyles.indent_size).toBe(4);
expect(fileStyles.tab_width).toBe(4);
expect(fileStyles.max_line_length).toBe(80);
});
test('.editorconfig .js settings', async () => {
const fileStyles = await readConfigForFile('.editorconfig.test.js');
expect(fileStyles.charset).toBe('utf-8');
expect(fileStyles.trim_trailing_whitespace).toBe(true);
expect(fileStyles.insert_final_newline).toBe(true);
expect(fileStyles.quote_type).toBe('single');
expect(fileStyles.indent_style).toBe('space');
expect(fileStyles.indent_size).toBe(2);
expect(fileStyles.tab_width).toBe(2);
expect(fileStyles.max_line_length).toBe(80);
});