forked from xdissent/karma-chai
-
Notifications
You must be signed in to change notification settings - Fork 43
/
index.js
48 lines (40 loc) · 1.32 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
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);
/* Sinon */
var sinonPath = path.dirname(require.resolve('sinon/package.json')) + '/pkg/sinon.js';
if (!isDuplicate(sinonPath)) {
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]};