3
3
// Karma config
4
4
// https://karma-runner.github.io/0.12/config/configuration-file.html
5
5
module . exports = function ( config ) {
6
- var isMac = / ^ d a r w i n / . test ( process . platform ) ,
7
- isWindows = / ^ w i n / . test ( process . platform ) ,
8
- isLinux = ! ( isMac || isWindows ) ;
9
-
10
- config . set ( {
6
+ var baseConfig = {
11
7
frameworks : [ 'mocha' , 'chai' , 'sinon' ] ,
12
- reporters : [ 'mocha' , 'coverage' ] ,
8
+ reporters : [ 'mocha' ] ,
13
9
14
10
files : [
15
11
// ono
@@ -18,31 +14,151 @@ module.exports = function(config) {
18
14
// Unit tests
19
15
'tests/helper.js' ,
20
16
'tests/**/*.spec.js'
21
- ] ,
17
+ ]
18
+ } ;
22
19
23
- browsers : ( function ( ) {
24
- // Test on all browsers that are available for the environment
25
- if ( isMac ) {
26
- return [ 'PhantomJS' , 'Firefox' , 'Chrome' , 'Safari' ] ;
27
- }
28
- else if ( isWindows ) {
29
- return [ 'PhantomJS' , 'Firefox' , 'Chrome' , 'Safari' , 'IE' ] ;
20
+ configureBrowsers ( baseConfig ) ;
21
+ configureSauceLabs ( baseConfig ) ;
22
+ config . set ( baseConfig ) ;
23
+ } ;
24
+
25
+ /**
26
+ * Configures the browsers for the current platform
27
+ */
28
+ function configureBrowsers ( config ) {
29
+ var isMac = / ^ d a r w i n / . test ( process . platform ) ,
30
+ isWindows = / ^ w i n / . test ( process . platform ) ,
31
+ isLinux = ! ( isMac || isWindows ) ;
32
+
33
+ if ( isMac ) {
34
+ config . browsers = [ 'PhantomJS' , 'Firefox' , 'Chrome' , 'Safari' ] ;
35
+ }
36
+ else if ( isLinux ) {
37
+ config . browsers = [ 'PhantomJS' , 'Firefox' ] ;
38
+ }
39
+ else if ( isWindows ) {
40
+ config . browsers = [ 'PhantomJS' , 'Firefox' , 'Chrome' , 'Safari' , 'IE9' , 'IE10' , 'IE' ] ;
41
+
42
+ // NOTE: IE 6, 7, 8 are not supported by Chai
43
+ config . customLaunchers = {
44
+ IE9 : {
45
+ base : 'IE' ,
46
+ 'x-ua-compatible' : 'IE=EmulateIE9'
47
+ } ,
48
+ IE10 : {
49
+ base : 'IE' ,
50
+ 'x-ua-compatible' : 'IE=EmulateIE10'
30
51
}
31
- else if ( isLinux ) {
32
- return [ 'PhantomJS' , 'Firefox' ] ;
52
+ } ;
53
+ }
54
+ }
55
+
56
+ /**
57
+ * Configures Sauce Labs emulated browsers/devices.
58
+ * https://github.com/karma-runner/karma-sauce-launcher
59
+ */
60
+ function configureSauceLabs ( config ) {
61
+ var username = process . env . SAUCE_USERNAME ;
62
+ var accessKey = process . env . SAUCE_ACCESS_KEY ;
63
+ var jobNumber = getJobNumber ( process . env . TRAVIS_JOB_NUMBER ) ;
64
+
65
+ // Only run Sauce Labs if we have the username & access key.
66
+ // And only run it for the first job in a build. No need to run it for every job.
67
+ if ( username && accessKey && jobNumber <= 1 ) {
68
+ var project = require ( './package.json' ) ;
69
+ var testName = project . name + ' v' + project . version ;
70
+ var build = testName + ' @ ' + new Date ( ) ;
71
+
72
+ config . sauceLabs = {
73
+ build : build ,
74
+ testName : testName ,
75
+ tags : [ project . name ] ,
76
+ recordVideo : true ,
77
+ recordScreenshots : true
78
+ } ;
79
+
80
+ config . customLaunchers = {
81
+ 'IE-9' : {
82
+ base : 'SauceLabs' ,
83
+ platform : 'Windows 7' ,
84
+ browserName : 'internet explorer' ,
85
+ version : '9'
86
+ } ,
87
+ 'IE-10' : {
88
+ base : 'SauceLabs' ,
89
+ platform : 'Windows 7' ,
90
+ browserName : 'internet explorer' ,
91
+ version : '10'
92
+ } ,
93
+ 'IE-11' : {
94
+ base : 'SauceLabs' ,
95
+ platform : 'Windows 7' ,
96
+ browserName : 'internet explorer' ,
97
+ version : '11'
98
+ } ,
99
+ 'Chrome-Latest' : {
100
+ base : 'SauceLabs' ,
101
+ platform : 'Windows 7' ,
102
+ browserName : 'chrome'
103
+ } ,
104
+ 'Firefox-Latest' : {
105
+ base : 'SauceLabs' ,
106
+ platform : 'Windows 7' ,
107
+ browserName : 'firefox'
108
+ } ,
109
+ 'Opera-Latest' : {
110
+ base : 'SauceLabs' ,
111
+ platform : 'Windows 7' ,
112
+ browserName : 'opera'
113
+ } ,
114
+ 'Safari-Latest' : {
115
+ base : 'SauceLabs' ,
116
+ platform : 'OS X 10.10' ,
117
+ browserName : 'safari'
118
+ } ,
119
+ 'iOS-6' : {
120
+ base : 'SauceLabs' ,
121
+ platform : 'OS X 10.10' ,
122
+ browserName : 'iphone' ,
123
+ version : '6'
124
+ } ,
125
+ 'iOS-8' : {
126
+ base : 'SauceLabs' ,
127
+ platform : 'OS X 10.10' ,
128
+ browserName : 'iphone' ,
129
+ version : '8'
130
+ } ,
131
+ 'Android-4-4' : {
132
+ base : 'SauceLabs' ,
133
+ platform : 'Linux' ,
134
+ browserName : 'android' ,
135
+ version : '4.4'
136
+ } ,
137
+ 'Android-5' : {
138
+ base : 'SauceLabs' ,
139
+ platform : 'Linux' ,
140
+ browserName : 'android' ,
141
+ version : '5'
33
142
}
34
- } ) ( ) ,
35
-
36
- coverageReporter : {
37
- reporters : [
38
- { type : 'text-summary' } ,
39
- {
40
- type : 'lcov' ,
41
- subdir : function ( browser ) {
42
- return browser . toLowerCase ( ) . split ( / [ / - ] / ) [ 0 ] ;
43
- }
44
- } ,
45
- ]
46
- }
47
- } ) ;
48
- } ;
143
+ } ;
144
+
145
+ config . reporters . push ( 'saucelabs' ) ;
146
+ config . browsers = Object . keys ( config . customLaunchers ) ;
147
+ }
148
+ }
149
+
150
+ /**
151
+ * Returns the Travis CI job number, or 1 if there is no job number.
152
+ *
153
+ * Examples:
154
+ * - "4.1" -> 1
155
+ * - "16.2" -> 2
156
+ * - "16" -> 1
157
+ * - "" -> 1
158
+ * - null -> 1
159
+ */
160
+ function getJobNumber ( number ) {
161
+ var match = / \. ( \d + ) / . exec ( number ) ;
162
+ var job = match ? match [ 1 ] || '1' : '1' ;
163
+ return parseInt ( job ) ;
164
+ }
0 commit comments