forked from kevicency/karma-sinon-chai
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
52 lines (43 loc) · 1.45 KB
/
index.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
var path = require('path');
var pattern = function(file) {
return {pattern: file, included: true, served: true, watched: false};
};
var endsWith = function(substr) {
return function(str) {
return str.indexOf(substr) >= 0 && str.indexOf(substr) === (str.length - substr.length);
};
};
var _isDuplicate = function(files, file) {
var result = false;
for (var i = 0; i < files.length; i++) {
if (files[i]) {
var pattern = files[i].pattern;
result = result || endsWith(path.relative(__dirname, file))(pattern);
}
}
return result;
};
var framework = function(files) {
var isDuplicate = _isDuplicate.bind(this, files);
/* Lolex */
var lolexPath = path.dirname(require.resolve('lolex/package.json')) + '/lolex.js';
/* Sinon */
var sinonPath = path.dirname(require.resolve('sinon/package.json')) + '/pkg/sinon.js';
if (!isDuplicate(sinonPath)) {
files.unshift(pattern(lolexPath));
files.unshift(pattern(sinonPath));
}
/* Chai */
var chaiPath = path.dirname(require.resolve('chai/package.json')) + '/chai.js';
if (!isDuplicate(chaiPath)) {
files.unshift(pattern(chaiPath));
files.push(pattern(path.join(__dirname, 'chai-adapter.js')));
}
/* Sinon-Chai */
var sinonChaiPath = path.resolve(require.resolve('sinon-chai'));
if (!isDuplicate(sinonChaiPath)) {
files.push(pattern(sinonChaiPath))
}
};
framework.$inject = ['config.files'];
module.exports = {'framework:sinon-chai': ['factory', framework]};