-
Notifications
You must be signed in to change notification settings - Fork 529
/
config-helpers.js
121 lines (105 loc) · 3.1 KB
/
config-helpers.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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
'use strict';
var equal = require('deep-equal'),
assert = require('assert'),
yaml = require('js-yaml'),
fs = require('fs'),
path = require('path'),
configHelpers = require('../lib/config-helpers');
var emptyConfig = {
options: {},
files: {},
rules: {}
};
var defaultConfig = yaml.safeLoad(fs.readFileSync(path.resolve('lib/config/sass-lint.yml'), 'utf8'));
var ignoreConfig = yaml.safeLoad(fs.readFileSync('tests/yml/.ignore-file.yml', 'utf8'));
var extendableConfigA1 = {
'options': {
'config-file': 'extend/.extend-c.yml'
},
'files': {},
'rules': {
'no-ids': 2
}
};
var extendableConfigA2 = {
'options': {
'config-file': 'extend/.extend-b.yml'
},
'files': {},
'rules': {
'no-ids': 2
}
};
var expectedA1 = {
'options': {
'config-file': 'extend/.extend-c.yml'
},
'files': {},
'rules': {
'no-ids': 2,
'no-important': 2
}
};
var expectedA2 = {
'options': {
'config-file': 'extend/.extend-b.yml'
},
'files': {},
'rules': {
'no-ids': 2,
'no-important': 2,
'no-mergeable-selectors': 2
}
};
describe('config-helpers', function () {
describe('loadDefaults', function () {
it('Should load the current default config', function (done) {
var testConfig = configHelpers.loadDefaults();
assert(equal(defaultConfig, testConfig, {
'strict': true
}));
done();
});
});
describe('loadConfig', function () {
it('Should load a config from a provided path', function (done) {
var testConfig = configHelpers.loadConfig('tests/yml/.ignore-file.yml');
assert(equal(ignoreConfig, testConfig, {
'strict': true
}));
done();
});
it('should return an empty config when an incorrect path is provided', function (done) {
var testConfig = configHelpers.loadConfig('tests/yml/non-existant.yml');
assert(equal(emptyConfig, testConfig, {
'strict': true
}));
done();
});
it('should return an empty config when a blank config is provided', function (done) {
var testConfig = configHelpers.loadConfig('tests/yml/.blank.yml');
assert(equal(emptyConfig, testConfig, {
'strict': true
}));
done();
});
});
describe('checkForConfigExtend', function () {
it('should return the config it was provided when no extend is found', function (done) {
var config = yaml.safeLoad(fs.readFileSync('tests/yml/.ignore-file.yml', 'utf8'));
var testConfig = configHelpers.checkForConfigExtend(config);
assert(equal(config, testConfig));
done();
});
it('should return a merged config when a config specifies an extended config', function (done) {
var testConfig = configHelpers.checkForConfigExtend(extendableConfigA1, 'tests/yml/.extend-a1.yml');
assert(equal(expectedA1, testConfig));
done();
});
it('should return a merged config when a chain of configs are specified', function (done) {
var testConfig = configHelpers.checkForConfigExtend(extendableConfigA2, 'tests/yml/.extend-a2.yml');
assert(equal(expectedA2, testConfig));
done();
});
});
});