-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
206 lines (169 loc) · 7.3 KB
/
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
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
'use strict';
var assert = require('assert');
var kextjs = require('./index');
var path = require('path');
it('should add coverage to preprocessor dictionary', function(cb) {
var prep = kextjs.preprocessCoverage(['file1', 'file2']);
assert.strictEqual('coverage', prep.file1);
assert.strictEqual('coverage', prep.file2);
cb();
});
it('should default module options', function(cb) {
var options = kextjs.setOptions();
assert(options.beforeSource);
assert(options.beforeSource.length === 0);
assert(options.afterSource);
assert(options.afterSource.length === 0);
assert(options.coverage === false);
assert.strictEqual(9877, options.staticPort);
cb();
});
it('should default karma options', function(cb) {
var options = kextjs.setOptions();
assert.strictEqual(9876, options.karma.port, 'Expects default port');
assert(options.karma.singleRun);
assert('progress', options.karma.reporters.pop());
assert('Chrome', options.karma.browsers.pop());
assert('jasmine', options.karma.frameworks.pop());
assert(options.karma.preprocessors);
cb();
});
it('should not override module options', function(cb) {
var options = kextjs.setOptions({
beforeSource: ['before.js'],
afterSource: ['after.js'],
coverage: true,
staticPort: 1111
});
assert(options.beforeSource);
assert.strictEqual('before.js', options.beforeSource[0]);
assert(options.afterSource);
assert.strictEqual('after.js', options.afterSource[0]);
assert(options.coverage);
assert.strictEqual(1111, options.staticPort);
cb();
});
it('should not override karma options', function(cb) {
var options = kextjs.setOptions({
karma: {
port: 1111,
singleRun: false,
reporters: ['otherreporter'],
browsers: ['otherbrowser'],
frameworks: ['otherframework'],
preprocessors: {
myfile: 'process'
}
}
});
assert.strictEqual(1111, options.karma.port, 'Expects default port');
assert(!options.karma.singleRun, 'Expect single run false');
assert('otherreporter', options.karma.reporters.pop(), 'Expects reporter set');
assert('otherbrowser', options.karma.browsers.pop(), 'Expects browser set');
assert('otherframework', options.karma.frameworks.pop(), 'Expects framework set');
assert.strictEqual('process', options.karma.preprocessors.myfile, 'Expects preprocessor set');
cb();
});
it('should add coverage preprocessors', function(cb) {
var options = kextjs.setOptions({
coverage: true,
karma: {
reporters: ['junit']
}
}, ['file1', 'file2']);
assert.strictEqual('coverage', options.karma.reporters.pop(), 'Expects coverage reporter');
assert.strictEqual('coverage', options.karma.preprocessors.file1, 'Expects file 1 preprocessors set');
assert.strictEqual('coverage', options.karma.preprocessors.file2, 'Expects file 2 preprocessors set');
cb();
});
it('should concat before files, source files, after files and spec files', function(cb) {
var options = kextjs.setOptions({
beforeSource: ['before.js'],
afterSource: ['after.js'],
tests: ['fixture1.js', 'fixture2.js']
}, ['src1.js', 'src2.js']),
bootstrap;
assert.strictEqual('fixture2.js', options.karma.files.pop());
assert.strictEqual('fixture1.js', options.karma.files.pop());
assert.strictEqual('after.js', options.karma.files.pop());
assert.strictEqual('src2.js', options.karma.files.pop());
assert.strictEqual('src1.js', options.karma.files.pop());
bootstrap = options.karma.files.pop().pattern;
assert.equal(bootstrap.indexOf('bootstrap.js') !== -1, true);
assert.strictEqual('before.js', options.karma.files.pop());
cb();
});
it('should filter source files by given expression in filterSources config', function(cb) {
var options = kextjs.setOptions({
beforeSource: ['before.js'],
afterSource: ['after.js'],
tests: ['fixture1.js', 'fixture2.js'],
filterSource: 'U4/src/some'
}, ['U4/src/some/src1.js', 'U4/src/other/src2.js']),
bootstrap;
assert.strictEqual('fixture2.js', options.karma.files.pop());
assert.strictEqual('fixture1.js', options.karma.files.pop());
assert.strictEqual('after.js', options.karma.files.pop());
assert.strictEqual('U4/src/some/src1.js', options.karma.files.pop());
bootstrap = options.karma.files.pop().pattern;
assert.equal(bootstrap.indexOf('bootstrap.js') !== -1, true);
assert.strictEqual('before.js', options.karma.files.pop());
cb();
});
it('should filter source files by given list of expressions in filterSources config', function(cb) {
var options = kextjs.setOptions({
beforeSource: ['before.js'],
afterSource: ['after.js'],
tests: ['fixture1.js', 'fixture2.js'],
filterSource: ['U4/src/some/one', 'U4/src/some/two']
}, ['U4/src/some/one/src1.js', 'U4/src/some/two/src2.js', 'U4/src/some/three/src3.js']),
bootstrap;
assert.strictEqual('fixture2.js', options.karma.files.pop());
assert.strictEqual('fixture1.js', options.karma.files.pop());
assert.strictEqual('after.js', options.karma.files.pop());
assert.strictEqual('U4/src/some/two/src2.js', options.karma.files.pop());
assert.strictEqual('U4/src/some/one/src1.js', options.karma.files.pop());
bootstrap = options.karma.files.pop().pattern;
assert.equal(bootstrap.indexOf('bootstrap.js') !== -1, true);
assert.strictEqual('before.js', options.karma.files.pop());
cb();
});
it('should filter source files to cover by given expression in filterCoverage config', function(cb) {
var options = kextjs.setOptions({
beforeSource: ['before.js'],
afterSource: ['after.js'],
tests: ['fixture1.js', 'fixture2.js'],
filterCoverage: 'U4/src/some',
coverage: true
}, ['U4/src/some/src1.js', 'U4/src/other/src2.js']);
assert.strictEqual(1, Object.keys(options.karma.preprocessors).length);
assert.strictEqual('coverage', options.karma.preprocessors['U4/src/some/src1.js']);
cb();
});
it('should filter source files to cover by given list of expressions in filterCoverage config', function(cb) {
var options = kextjs.setOptions({
beforeSource: ['before.js'],
afterSource: ['after.js'],
tests: ['fixture1.js', 'fixture2.js'],
filterCoverage: ['U4/src/some/one', 'U4/src/some/two'],
coverage: true
}, ['U4/src/some/one/src1.js', 'U4/src/some/two/src2.js', 'U4/src/some/three/src3.js']);
assert.strictEqual(2, Object.keys(options.karma.preprocessors).length);
assert.strictEqual('coverage', options.karma.preprocessors['U4/src/some/one/src1.js']);
assert.strictEqual('coverage', options.karma.preprocessors['U4/src/some/two/src2.js']);
cb();
});
it('should use a custom context file', function(cb){
var options = kextjs.setOptions({
tests: ['fixture1.js', 'fixture2.js'],
}, ['src1.js']);
assert.strictEqual(options.karma.customContextFile, path.join(__dirname, '/context.html'));
cb();
});
it('should use a custom debug file', function(cb){
var options = kextjs.setOptions({
tests: ['fixture1.js', 'fixture2.js'],
}, ['src1.js']);
assert.strictEqual(options.karma.customDebugFile, path.join(__dirname, '/debug.html'));
cb();
});