-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
80 lines (67 loc) · 1.81 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
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
(function() {
'use strict';
function JasmineMatchers(files) {
/**
* @description
* Add a new array item after the one at the supplied index.
*
* @param {Array} array
* @param {Number} index
* @param {*} item
*/
function insertAfter(array, index, item) {
array.splice(index + 1, 0, item);
}
/**
* @description
* Is this file configuation the the "karma-jasmine" framework's jasmine library?
*
* @param {Object} file
* @return {Boolean}
*/
function isJasmine(file) {
return file.pattern.search(/karma\-jasmine(\/|\\)lib(\/|\\)adapter\.js/) !== -1;
}
/**
* @description
* Get the array index of the "karma-jasmine" framework plugin in the files configuration.
*
* @param {Object[]} files
* @return {Number}
*/
function indexOfJasmine(files) {
for (var i = 0, len = files.length; i < len; i++) {
if (isJasmine(files[i])) {
return i;
}
}
return -1;
}
/**
* @description
* Locate the Jasmine Utils library.
*
* @return {String}
*/
function getLibPath() {
return require.resolve('jasmine-utils');
}
// Init
// ---------------------------------------------------------------------------------------------
var ix = indexOfJasmine(files);
if (ix !== -1) {
insertAfter(files, ix, {
pattern: getLibPath(),
included: true,
served: true,
watched: false
});
} else {
throw new Error('"jasmine" needs to appear before "jasmine-utils" in the "frameworks" array of your Karma configuration.');
}
}
JasmineMatchers.$inject = ['config.files'];
module.exports = {
'framework:jasmine-utils': ['factory', JasmineMatchers]
};
}());