UNPKG

1.35 kBJavaScriptView Raw
1var path = require('path');
2
3var pattern = function(file) {
4 return {pattern: file, included: true, served: true, watched: false};
5};
6
7var endsWith = function(substr) {
8 return function(str) {
9 return str.indexOf(substr) >= 0 && str.indexOf(substr) === (str.length - substr.length);
10 };
11};
12
13var _isDuplicate = function(files, file) {
14 var result = false;
15 for (var i = 0; i < files.length; i++) {
16 if (files[i]) {
17 var pattern = files[i].pattern;
18 result = result || endsWith(path.relative(__dirname, file))(pattern);
19 }
20 }
21 return result;
22};
23
24var framework = function(files) {
25 var isDuplicate = _isDuplicate.bind(this, files);
26
27 /* Sinon */
28 var sinonPath = path.dirname(require.resolve('sinon/package.json')) + '/pkg/sinon.js';
29 if (!isDuplicate(sinonPath)) {
30 files.unshift(pattern(sinonPath));
31 }
32
33 /* Chai */
34 var chaiPath = path.dirname(require.resolve('chai/package.json')) + '/chai.js';
35 if (!isDuplicate(chaiPath)) {
36 files.unshift(pattern(chaiPath));
37 files.push(pattern(path.join(__dirname, 'chai-adapter.js')));
38 }
39
40 /* Sinon-Chai */
41 var sinonChaiPath = path.resolve(require.resolve('sinon-chai'));
42 if (!isDuplicate(sinonChaiPath)) {
43 files.push(pattern(sinonChaiPath))
44 }
45};
46
47framework.$inject = ['config.files'];
48module.exports = {'framework:sinon-chai': ['factory', framework]};