1- 'use strict' ;
2-
31// Karma config
42// https://karma-runner.github.io/0.12/config/configuration-file.html
3+ 'use strict' ;
4+
5+ var baseConfig = {
6+ frameworks : [ 'mocha' ] ,
7+ reporters : [ 'mocha' ] ,
8+ files : [
9+ // Third-Party Libraries
10+ 'tests/bower_components/chai/chai.js' ,
11+ 'tests/bower_components/sinon-js/sinon.js' ,
12+ 'tests/bower_components/useragent-parser/src/useragent-parser.js' ,
13+
14+ // Ono
15+ 'dist/ono.min.js' ,
16+ { pattern : 'dist/*.map' , included : false , served : true } ,
17+
18+ // Test Fixtures
19+ 'tests/fixtures/**/*.js' ,
20+
21+ // Tests
22+ 'tests/specs/**/*.spec.js'
23+ ]
24+ } ;
25+
526module . exports = function ( config ) {
6- var baseConfig = {
7- frameworks : [ 'mocha' ] ,
8- reporters : [ 'mocha' ] ,
9- files : [
10- // Third-Party Libraries
11- 'www/bower_components/chai/chai.js' ,
12- 'www/bower_components/sinon-js/sinon.js' ,
13- 'www/bower_components/useragent-parser/src/useragent-parser.js' ,
14-
15- // Ono
16- 'dist/ono.min.js' ,
17-
18- // Unit Tests
19- 'tests/**/_*.js' ,
20- 'tests/**/*.spec.js'
21- ]
22- } ;
27+ var karma = process . env . KARMA ? process . env . KARMA === 'true' : true ;
28+ var coverage = process . env . KARMA_COVERAGE ? process . env . KARMA_COVERAGE === 'true' : true ;
29+ var sauce = process . env . KARMA_SAUCE ? process . env . KARMA_SAUCE === 'true' : true ;
30+ var sauceUsername = process . env . SAUCE_USERNAME ;
31+ var sauceAccessKey = process . env . SAUCE_ACCESS_KEY ;
2332
24- configureBrowsers ( baseConfig ) ;
25- configureSauceLabs ( baseConfig ) ;
33+ if ( ! karma ) {
34+ // Karma is disabled, so abort immediately
35+ process . exit ( ) ;
36+ return ;
37+ }
38+
39+ if ( coverage ) {
40+ configureCodeCoverage ( baseConfig ) ;
41+ }
42+
43+ if ( sauce && sauceUsername && sauceAccessKey ) {
44+ configureSauceLabs ( baseConfig ) ;
45+ }
46+ else {
47+ configureLocalBrowsers ( baseConfig ) ;
48+ }
49+
50+ console . log ( 'Karma Config:\n' , JSON . stringify ( baseConfig , null , 2 ) ) ;
2651 config . set ( baseConfig ) ;
2752} ;
2853
54+ /**
55+ * Configures the code-coverage reporter
56+ */
57+ function configureCodeCoverage ( config ) {
58+ config . reporters . push ( 'coverage' ) ;
59+ config . files . splice ( config . files . indexOf ( 'dist/ono.min.js' ) , 1 , 'dist/ono.test.js' ) ;
60+ config . coverageReporter = {
61+ reporters : [
62+ { type : 'text-summary' } ,
63+ { type : 'lcov' }
64+ ]
65+ } ;
66+ }
67+
2968/**
3069 * Configures the browsers for the current platform
3170 */
32- function configureBrowsers ( config ) {
71+ function configureLocalBrowsers ( config ) {
3372 var isMac = / ^ d a r w i n / . test ( process . platform ) ,
3473 isWindows = / ^ w i n / . test ( process . platform ) ,
3574 isLinux = ! ( isMac || isWindows ) ;
@@ -42,9 +81,8 @@ function configureBrowsers(config) {
4281 }
4382 else if ( isWindows ) {
4483 config . browsers = [ 'PhantomJS' , 'Firefox' , 'Chrome' , 'Safari' , 'IE9' , 'IE10' , 'IE' ] ;
45-
46- // NOTE: IE 6, 7, 8 are not supported by Chai
4784 config . customLaunchers = {
85+ // NOTE: IE 6, 7, 8 are not supported by Chai
4886 IE9 : {
4987 base : 'IE' ,
5088 'x-ua-compatible' : 'IE=EmulateIE9'
@@ -62,114 +100,83 @@ function configureBrowsers(config) {
62100 * https://github.com/karma-runner/karma-sauce-launcher
63101 */
64102function configureSauceLabs ( config ) {
65- var username = process . env . SAUCE_USERNAME ;
66- var accessKey = process . env . SAUCE_ACCESS_KEY ;
67- var jobNumber = getJobNumber ( process . env . TRAVIS_JOB_NUMBER ) ;
68-
69- // Only run Sauce Labs if we have the username & access key.
70- // And only run it for the first job in a build. No need to run it for every job.
71- if ( username && accessKey && jobNumber <= 1 ) {
72- var project = require ( './package.json' ) ;
73- var testName = project . name + ' v' + project . version ;
74- var build = testName + ' Build #' + process . env . TRAVIS_JOB_NUMBER + ' @ ' + new Date ( ) ;
75-
76- config . sauceLabs = {
77- build : build ,
78- testName : testName ,
79- tags : [ project . name ] ,
80- recordVideo : true ,
81- recordScreenshots : true
82- } ;
103+ var project = require ( './package.json' ) ;
104+ var testName = project . name + ' v' + project . version ;
105+ var build = testName + ' Build #' + process . env . TRAVIS_JOB_NUMBER + ' @ ' + new Date ( ) ;
83106
84- config . customLaunchers = {
85- 'IE-9' : {
86- base : 'SauceLabs' ,
87- platform : 'Windows 7' ,
88- browserName : 'internet explorer' ,
89- version : '9'
90- } ,
91- 'IE-10' : {
92- base : 'SauceLabs' ,
93- platform : 'Windows 7' ,
94- browserName : 'internet explorer' ,
95- version : '10'
96- } ,
97- 'IE-11' : {
98- base : 'SauceLabs' ,
99- platform : 'Windows 7' ,
100- browserName : 'internet explorer' ,
101- version : '11'
102- } ,
103- 'Chrome-Latest' : {
104- base : 'SauceLabs' ,
105- platform : 'Windows 7' ,
106- browserName : 'chrome'
107- } ,
108- 'Firefox-Latest' : {
109- base : 'SauceLabs' ,
110- platform : 'Windows 7' ,
111- browserName : 'firefox'
112- } ,
113- 'Opera-Latest' : {
114- base : 'SauceLabs' ,
115- platform : 'Windows 7' ,
116- browserName : 'opera'
117- } ,
118- 'Safari-Latest' : {
119- base : 'SauceLabs' ,
120- platform : 'OS X 10.10' ,
121- browserName : 'safari'
122- } ,
123- 'iOS-6' : {
124- base : 'SauceLabs' ,
125- platform : 'OS X 10.10' ,
126- browserName : 'iphone' ,
127- version : '6'
128- } ,
129- 'iOS-8' : {
130- base : 'SauceLabs' ,
131- platform : 'OS X 10.10' ,
132- browserName : 'iphone' ,
133- version : '8'
134- } ,
135- 'Android-4-4' : {
136- base : 'SauceLabs' ,
137- platform : 'Linux' ,
138- browserName : 'android' ,
139- version : '4.4'
140- } ,
141- 'Android-5' : {
142- base : 'SauceLabs' ,
143- platform : 'Linux' ,
144- browserName : 'android' ,
145- version : '5'
146- }
147- } ;
148-
149- config . reporters . push ( 'saucelabs' ) ;
150- config . browsers = Object . keys ( config . customLaunchers ) ;
107+ config . sauceLabs = {
108+ build : build ,
109+ testName : testName ,
110+ tags : [ project . name ] ,
111+ recordVideo : true ,
112+ recordScreenshots : true
113+ } ;
151114
152- // Sauce Connect sometimes hangs (https://github.com/karma-runner/karma-sauce-launcher/issues/14)
153- // So terminate the process after a few minutes
154- setTimeout ( function ( ) {
155- console . warn ( '\nWARNING: Sauce Connect appears to have hung. Forcefully terminating.\n' ) ;
156- process . exit ( ) ;
157- } , 1000 * 60 * 8 ) ; // 8 minutes
158- }
159- }
115+ config . customLaunchers = {
116+ 'IE-9' : {
117+ base : 'SauceLabs' ,
118+ platform : 'Windows 7' ,
119+ browserName : 'internet explorer' ,
120+ version : '9'
121+ } ,
122+ 'IE-10' : {
123+ base : 'SauceLabs' ,
124+ platform : 'Windows 7' ,
125+ browserName : 'internet explorer' ,
126+ version : '10'
127+ } ,
128+ 'IE-11' : {
129+ base : 'SauceLabs' ,
130+ platform : 'Windows 7' ,
131+ browserName : 'internet explorer' ,
132+ version : '11'
133+ } ,
134+ 'Chrome-Latest' : {
135+ base : 'SauceLabs' ,
136+ platform : 'Windows 7' ,
137+ browserName : 'chrome'
138+ } ,
139+ 'Firefox-Latest' : {
140+ base : 'SauceLabs' ,
141+ platform : 'Windows 7' ,
142+ browserName : 'firefox'
143+ } ,
144+ 'Opera-Latest' : {
145+ base : 'SauceLabs' ,
146+ platform : 'Windows 7' ,
147+ browserName : 'opera'
148+ } ,
149+ 'Safari-Latest' : {
150+ base : 'SauceLabs' ,
151+ platform : 'OS X 10.10' ,
152+ browserName : 'safari'
153+ } ,
154+ 'iOS-6' : {
155+ base : 'SauceLabs' ,
156+ platform : 'OS X 10.10' ,
157+ browserName : 'iphone' ,
158+ version : '6'
159+ } ,
160+ 'iOS-8' : {
161+ base : 'SauceLabs' ,
162+ platform : 'OS X 10.10' ,
163+ browserName : 'iphone' ,
164+ version : '8'
165+ } ,
166+ 'Android-4-4' : {
167+ base : 'SauceLabs' ,
168+ platform : 'Linux' ,
169+ browserName : 'android' ,
170+ version : '4.4'
171+ } ,
172+ 'Android-5' : {
173+ base : 'SauceLabs' ,
174+ platform : 'Linux' ,
175+ browserName : 'android' ,
176+ version : '5'
177+ }
178+ } ;
160179
161- /**
162- * Returns the Travis CI job number, or 1 if there is no job number.
163- *
164- * Examples:
165- * - "4.1" -> 1
166- * - "16.2" -> 2
167- * - "16" -> 1
168- * - "" -> 1
169- * - null -> 1
170- */
171- function getJobNumber ( number ) {
172- var match = / \. ( \d + ) / . exec ( number ) ;
173- var job = match ? match [ 1 ] || '1' : '1' ;
174- return parseInt ( job ) ;
180+ config . reporters . push ( 'saucelabs' ) ;
181+ config . browsers = Object . keys ( config . customLaunchers ) ;
175182}
0 commit comments