1 | var path = require('path');
|
2 |
|
3 | var pattern = function(file) {
|
4 | return {pattern: file, included: true, served: true, watched: false};
|
5 | };
|
6 |
|
7 | var endsWith = function(substr) {
|
8 | return function(str) {
|
9 | return str.indexOf(substr) >= 0 && str.indexOf(substr) === (str.length - substr.length);
|
10 | };
|
11 | };
|
12 |
|
13 | var _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 |
|
24 | var framework = function(files) {
|
25 | var isDuplicate = _isDuplicate.bind(this, files);
|
26 |
|
27 |
|
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 |
|
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 |
|
41 | var sinonChaiPath = path.resolve(require.resolve('sinon-chai'));
|
42 | if (!isDuplicate(sinonChaiPath)) {
|
43 | files.push(pattern(sinonChaiPath))
|
44 | }
|
45 | };
|
46 |
|
47 | framework.$inject = ['config.files'];
|
48 | module.exports = {'framework:sinon-chai': ['factory', framework]};
|