Debian Codegraph @

test/other/test-config.js

raw
1 var path = require('path'),
2 configuration = require('../../lib/config'),
3 oldCwd = process.cwd(),
4 newCwd = path.resolve(__dirname, 'config-data'),
5 config;
6
7 module.exports = {
8 "when no explicit config is present": {
9 setUp: function (cb) {
10 config = configuration.loadObject(null);
11 cb();
12 },
13 "verbose option should be set": function (test) {
14 test.equal(false, config.verbose);
15 test.done();
16 },
17 "default instrumentation options should be correct": function (test) {
18 var iOpts = config.instrumentation;
19 test.equal(process.cwd(), iOpts.root());
20 test.equal(true, iOpts.defaultExcludes());
21 test.equal(false, iOpts.embedSource());
22 test.equal('__coverage__', iOpts.variable());
23 test.equal(true, iOpts.compact());
24 test.equal(false, iOpts.preserveComments());
25 test.equal(false, iOpts.completeCopy());
26 test.equal(false, iOpts.saveBaseline());
27 test.equal(false, iOpts.includeAllSources());
28 test.equal('./coverage/coverage-baseline.json', iOpts.baselineFile());
29 test.deepEqual(['**/node_modules/**'], iOpts.excludes());
30 test.deepEqual(['**/node_modules/**', '**/test/**', '**/tests/**'], iOpts.excludes(true));
31 test.done();
32 },
33 "default reporting options should be correct": function (test) {
34 var rOpts = config.reporting;
35 test.equal('summary', rOpts.print());
36 test.deepEqual( ['lcov'], rOpts.reports());
37 test.equal('./coverage', rOpts.dir());
38 test.equal('lcov.info', rOpts.reportConfig().lcovonly.file);
39 test.done();
40 },
41 "default hook options should be correct": function (test) {
42 var hOpts = config.hooks;
43 test.equal(false, hOpts.hookRunInContext());
44 test.equal(null, hOpts.postRequireHook());
45 test.done();
46 }
47 },
48 "when overrides passed in": {
49 "as initial object": {
50 "should use overrides": function (test) {
51 config = configuration.loadObject({ instrumentation: { compact: false, 'save-baseline': true }});
52 test.equal(false, config.instrumentation.compact());
53 test.equal(true, config.instrumentation.saveBaseline());
54 test.done();
55 }
56 },
57 "as override object": {
58 "should use overrides": function (test) {
59 config = configuration.loadObject({},
60 { verbose: true, instrumentation: { compact: false, 'save-baseline': true }}
61 );
62 test.equal(true, config.verbose);
63 test.equal(false, config.instrumentation.compact());
64 test.equal(true, config.instrumentation.saveBaseline());
65 test.done();
66 }
67 },
68 "at both levels": {
69 "should use override object values": function (test) {
70 config = configuration.loadObject(
71 { verbose: true, instrumentation: { compact: false, 'save-baseline': true } },
72 { verbose: false, instrumentation: { compact: true, 'save-baseline': false } }
73 );
74 test.equal(false, config.verbose);
75 test.equal(true, config.instrumentation.compact());
76 test.equal(false, config.instrumentation.saveBaseline());
77 test.done();
78 }
79 },
80 "deeper in the tree": {
81 "should use overrides": function (test) {
82 config = configuration.loadObject({
83 reporting: {
84 'report-config': {
85 'lcovonly': {
86 file: 'foo.info'
87 }
88 }
89 }
90 });
91 test.equal('foo.info', config.reporting.reportConfig().lcovonly.file);
92 test.equal('clover.xml', config.reporting.reportConfig().clover.file);
93 test.equal(null, config.reporting.reportConfig().text.file);
94 test.done();
95 }
96 }
97 },
98 "excludes array changes based on default excludes": {
99 "should honor default excludes setting - when set" : function (test) {
100 config = configuration.loadObject({
101 instrumentation: {
102 "excludes": [ '**/vendor/**' ]
103 }
104 });
105 var iOpts = config.instrumentation;
106 test.deepEqual(['**/node_modules/**', '**/vendor/**'], iOpts.excludes());
107 test.deepEqual(['**/node_modules/**', '**/test/**', '**/tests/**', '**/vendor/**'], iOpts.excludes(true));
108 test.done();
109 },
110 "should honor default excludes setting - when not set" : function (test) {
111 config = configuration.loadObject({
112 instrumentation: {
113 "default-excludes": null,
114 "excludes": [ '**/vendor/**' ]
115 }
116 });
117 var iOpts = config.instrumentation;
118 test.deepEqual(['**/vendor/**'], iOpts.excludes());
119 test.deepEqual(['**/vendor/**'], iOpts.excludes(true));
120 test.done();
121 },
122 "should return nothing when defaults off and no excludes" : function (test) {
123 config = configuration.loadObject({
124 instrumentation: {
125 "default-excludes": null
126 }
127 });
128 var iOpts = config.instrumentation;
129 test.deepEqual([], iOpts.excludes());
130 test.deepEqual([], iOpts.excludes(true));
131 test.done();
132 }
133 },
134 "when loading files": {
135 "should fail on bad config file": function (test) {
136 try {
137 config = configuration.loadFile('/a/non/existent/path.js');
138 test.fail();
139 } catch (ex) {
140 test.ok(1);
141 }
142 test.done();
143 },
144 "should use default config when no default file found": function (test) {
145 config = configuration.loadFile();
146 var defaultConfig = configuration.loadObject();
147 test.deepEqual(config, defaultConfig);
148 test.done();
149 },
150 "when files present": {
151 setUp: function (cb) {
152 process.chdir(newCwd);
153 cb();
154 },
155 tearDown: function (cb) {
156 process.chdir(oldCwd);
157 cb();
158 },
159 "should use default YAML config when not explicit": function (test) {
160 config = configuration.loadFile(undefined, { verbose: true });
161 test.equal(false, config.instrumentation.compact());
162 test.deepEqual(['lcov', 'cobertura'], config.reporting.reports());
163 test.done();
164 },
165 "should use explicit file when provided": function (test) {
166 config = configuration.loadFile('cfg.json', { verbose: true });
167 test.equal(true, config.instrumentation.compact());
168 test.deepEqual(['lcov'], config.reporting.reports());
169 test.equal(true, config.instrumentation.saveBaseline());
170 test.equal('yui-istanbul', config.hooks.postRequireHook());
171 test.done();
172 }
173 }
174 },
175 "with custom watermarks": {
176 "should load from sparse config": function (test) {
177 config = configuration.loadObject({ reporting: { watermarks: { statements: [ 10, 90] } } });
178 var w = config.reporting.watermarks();
179 test.deepEqual([ 10, 90 ], w.statements);
180 test.deepEqual([ 50, 80 ], w.branches);
181 test.deepEqual([ 50, 80 ], w.functions);
182 test.deepEqual([ 50, 80 ], w.lines);
183 test.done();
184 },
185 "should not load any junk config": function (test) {
186 config = configuration.loadObject({
187 reporting: {
188 watermarks: {
189 statements: [ 10, 90, 95],
190 branches: [ -10, 70 ],
191 lines: [ 70, 110 ],
192 functions: [ 'a', 10 ]
193 }
194 }
195 });
196 var w = config.reporting.watermarks();
197 test.deepEqual([ 50, 80 ], w.statements);
198 test.deepEqual([ 50, 80 ], w.branches);
199 test.deepEqual([ 50, 80 ], w.functions);
200 test.deepEqual([ 50, 80 ], w.lines);
201 test.done();
202 },
203 "should not load any junk config (2)": function (test) {
204 config = configuration.loadObject({
205 reporting: {
206 watermarks: {
207 statements: [ 90, 80 ]
208 }
209 }
210 });
211 var w = config.reporting.watermarks();
212 test.deepEqual([ 50, 80 ], w.statements);
213 test.deepEqual([ 50, 80 ], w.branches);
214 test.deepEqual([ 50, 80 ], w.functions);
215 test.deepEqual([ 50, 80 ], w.lines);
216 test.done();
217 }
218 }
219 };