11// Karma config
22// https://karma-runner.github.io/0.12/config/configuration-file.html
3- 'use strict' ;
4-
3+ "use strict" ;
54
65module . exports = function ( karma ) {
76 var config = {
8- frameworks : [ ' mocha' , ' chai' , ' host-environment' ] ,
9- reporters : [ ' verbose' ] ,
7+ frameworks : [ " mocha" , " chai" , " host-environment" ] ,
8+ reporters : [ " verbose" ] ,
109
1110 files : [
1211 // Polyfills for older browsers
13- ' test/polyfills/promise.js' ,
14- ' test/polyfills/typedarray.js' ,
12+ " test/polyfills/promise.js" ,
13+ " test/polyfills/typedarray.js" ,
1514
1615 // Json Schema $Ref Parser
17- ' dist/ref-parser.min.js' ,
18- { pattern : ' dist/*.map' , included : false , served : true } ,
16+ " dist/ref-parser.min.js" ,
17+ { pattern : " dist/*.map" , included : false , served : true } ,
1918
2019 // Test Fixtures
21- ' test/fixtures/**/*.js' ,
20+ " test/fixtures/**/*.js" ,
2221
2322 // Test Specs
24- ' test/specs/**/*.parsed.js' ,
25- ' test/specs/**/*.dereferenced.js' ,
26- ' test/specs/**/*.bundled.js' ,
27- ' test/specs/**/*.spec.js' ,
28- { pattern : ' test/specs/**' , included : false , served : true }
23+ " test/specs/**/*.parsed.js" ,
24+ " test/specs/**/*.dereferenced.js" ,
25+ " test/specs/**/*.bundled.js" ,
26+ " test/specs/**/*.spec.js" ,
27+ { pattern : " test/specs/**" , included : false , served : true }
2928 ]
3029 } ;
3130
32- exitIfDisabled ( ) ;
3331 configureCodeCoverage ( config ) ;
34- configureLocalBrowsers ( config ) ;
35- configureSauceLabs ( config ) ;
32+ configureBrowsers ( config ) ;
3633
37- console . log ( ' Karma Config:\n' , JSON . stringify ( config , null , 2 ) ) ;
34+ console . log ( " Karma Config:\n" , JSON . stringify ( config , null , 2 ) ) ;
3835 karma . set ( config ) ;
3936} ;
4037
41- /**
42- * If this is a CI job, and Karma is not enabled, then exit.
43- * (useful for CI jobs that are only testing Node.js, not web browsers)
44- */
45- function exitIfDisabled ( ) {
46- var CI = process . env . CI === 'true' ;
47- var KARMA = process . env . KARMA === 'true' ;
48-
49- if ( CI && ! KARMA ) {
50- console . warn ( 'Karma is not enabled' ) ;
51- process . exit ( ) ;
52- }
53- }
54-
5538/**
5639 * Configures the code-coverage reporter
5740 */
5841function configureCodeCoverage ( config ) {
59- if ( process . argv . indexOf ( '--coverage' ) === - 1 ) {
60- console . warn ( 'Code-coverage is not enabled' ) ;
61- return ;
62- }
63- else if ( process . env . SAUCE === 'true' ) {
64- // Code coverage causes sporadic failures on SauceLabs
65- // https://github.com/karma-runner/karma-sauce-launcher/issues/95#issuecomment-255020888
66- console . warn ( 'Code-coverage is disabled for SauceLabs' ) ;
42+ if ( process . argv . indexOf ( "--coverage" ) === - 1 ) {
43+ console . warn ( "Code-coverage is not enabled" ) ;
6744 return ;
6845 }
6946
70- config . reporters . push ( ' coverage' ) ;
47+ config . reporters . push ( " coverage" ) ;
7148 config . coverageReporter = {
7249 reporters : [
73- { type : ' text-summary' } ,
74- { type : ' lcov' }
50+ { type : " text-summary" } ,
51+ { type : " lcov" }
7552 ]
7653 } ;
7754
7855 config . files = config . files . map ( function ( file ) {
79- if ( typeof file === ' string' ) {
80- file = file . replace ( / ^ d i s t \/ ( .* ) \. m i n \. j s $ / , ' dist/$1.coverage.js' ) ;
56+ if ( typeof file === " string" ) {
57+ file = file . replace ( / ^ d i s t \/ ( .* ) \. m i n \. j s $ / , " dist/$1.coverage.js" ) ;
8158 }
8259 return file ;
8360 } ) ;
@@ -86,19 +63,32 @@ function configureCodeCoverage (config) {
8663/**
8764 * Configures the browsers for the current platform
8865 */
89- function configureLocalBrowsers ( config ) {
90- var isMac = / ^ d a r w i n / . test ( process . platform ) ;
91- var isWindows = / ^ w i n / . test ( process . platform ) ;
92- var isLinux = ! isMac && ! isWindows ;
93-
94- if ( isMac ) {
95- config . browsers = [ 'Firefox' , 'Chrome' , 'Safari' ] ;
66+ function configureBrowsers ( config ) {
67+ let isWindows = / ^ w i n / . test ( process . platform ) || process . env . WINDOWS === "true" ;
68+ let isMac = / ^ d a r w i n / . test ( process . platform ) ;
69+ let isLinux = ! isMac && ! isWindows ;
70+ let isCI = process . env . CI === "true" ;
71+
72+ if ( isCI ) {
73+ if ( isWindows ) {
74+ // IE and Edge aren't available in CI, so use SauceLabs
75+ configureSauceLabs ( config ) ;
76+ }
77+ else if ( isMac ) {
78+ config . browsers = [ "FirefoxHeadless" , "ChromeHeadless" , "Safari" ] ;
79+ }
80+ else if ( isLinux ) {
81+ config . browsers = [ "FirefoxHeadless" , "ChromeHeadless" ] ;
82+ }
83+ }
84+ else if ( isMac ) {
85+ config . browsers = [ "Firefox" , "Chrome" , "Safari" ] ;
9686 }
9787 else if ( isLinux ) {
98- config . browsers = [ ' Firefox' , 'ChromeHeadless' ] ;
88+ config . browsers = [ " Firefox" , "Chrome" ] ;
9989 }
10090 else if ( isWindows ) {
101- config . browsers = [ ' Firefox' , ' Chrome' , 'IE' , ' Edge' ] ;
91+ config . browsers = [ " Firefox" , " Chrome" , "IE" , " Edge" ] ;
10292 }
10393}
10494
@@ -107,79 +97,52 @@ function configureLocalBrowsers (config) {
10797 * https://github.com/karma-runner/karma-sauce-launcher
10898 */
10999function configureSauceLabs ( config ) {
110- var SAUCE = process . env . SAUCE === 'true' ;
111- var username = process . env . SAUCE_USERNAME ;
112- var accessKey = process . env . SAUCE_ACCESS_KEY ;
100+ let username = process . env . SAUCE_USERNAME ;
101+ let accessKey = process . env . SAUCE_ACCESS_KEY ;
113102
114- if ( ! SAUCE || ! username || ! accessKey ) {
115- console . warn ( 'SauceLabs is not enabled' ) ;
116- return ;
103+ if ( ! username || ! accessKey ) {
104+ throw new Error ( `SAUCE_USERNAME and/or SAUCE_ACCESS_KEY is not set` ) ;
117105 }
118106
119- var project = require ( './package.json' ) ;
120- var testName = project . name + ' v' + project . version ;
121- var build = testName + ' Build #' + process . env . TRAVIS_JOB_NUMBER + ' @ ' + new Date ( ) ;
107+ let project = require ( "./package.json" ) ;
122108
123109 config . sauceLabs = {
124- build : build ,
125- testName : testName ,
110+ build : ` ${ project . name } v ${ project . version } Build # ${ process . env . TRAVIS_JOB_NUMBER } ` ,
111+ testName : ` ${ project . name } v ${ project . version } ` ,
126112 tags : [ project . name ] ,
127113 } ;
128114
129115 config . customLaunchers = {
130- SauceLabs_IE_11 : {
131- base : 'SauceLabs' ,
132- platform : 'Windows 10' ,
133- browserName : 'internet explorer'
134- } ,
135- SauceLabs_IE_Edge : {
136- base : 'SauceLabs' ,
137- platform : 'Windows 10' ,
138- browserName : 'microsoftedge'
139- } ,
140-
141- // TODO FIXME TODO FIXME TODO FIXME TODO FIXME TODO FIXME TODO FIXME TODO
142- // ======================================================================
143- // I've temporarily commented-out Safari on Mac because SauceLabs seems to
144- // be having problems with their Mac VMs right now.
145- // https://travis-ci.org/APIDevTools/json-schema-ref-parser/jobs/440110398#L1169-L1194
146- // ======================================================================
147- // SauceLabs_Safari_Latest: {
148- // base: 'SauceLabs',
149- // platform: 'macOS 10.13',
150- // browserName: 'safari'
151- // },
152-
153- SauceLabs_Chrome_Latest : {
154- base : 'SauceLabs' ,
155- platform : 'Windows 10' ,
156- browserName : 'chrome'
116+ IE_11 : {
117+ base : "SauceLabs" ,
118+ platform : "Windows 7" ,
119+ browserName : "internet explorer"
157120 } ,
158- SauceLabs_Firefox_Latest : {
159- base : ' SauceLabs' ,
160- platform : ' Windows 10' ,
161- browserName : 'firefox'
121+ Edge : {
122+ base : " SauceLabs" ,
123+ platform : " Windows 10" ,
124+ browserName : "microsoftedge"
162125 } ,
163126 } ;
164127
165- config . reporters . push ( ' saucelabs' ) ;
128+ config . reporters . push ( " saucelabs" ) ;
166129 config . browsers = Object . keys ( config . customLaunchers ) ;
167- config . concurrency = 1 ;
130+ // config.concurrency = 1;
168131 config . captureTimeout = 60000 ;
169132 config . browserDisconnectTolerance = 5 ,
170133 config . browserDisconnectTimeout = 60000 ;
171134 config . browserNoActivityTimeout = 60000 ;
172- // config.logLevel = ' debug' ;
135+ // config.logLevel = " debug" ;
173136
174137 // The following tests tend to fail on SauceLabs,
175138 // probably due to zero-byte files and special characters in the paths.
176139 // So, exclude these tests when running on SauceLabs.
177140 config . exclude = [
178- ' test/specs/__*/**' ,
179- ' test/specs/blank/**/*.spec.js' ,
180- ' test/specs/circular*/**/*.spec.js' ,
181- ' test/specs/empty/**/*.spec.js' ,
182- ' test/specs/invalid/**/*.spec.js' ,
183- ' test/specs/parsers/**/*.spec.js' ,
141+ " test/specs/__*/**" ,
142+ " test/specs/blank/**/*.spec.js" ,
143+ " test/specs/circular*/**/*.spec.js" ,
144+ " test/specs/empty/**/*.spec.js" ,
145+ " test/specs/invalid/**/*.spec.js" ,
146+ " test/specs/parsers/**/*.spec.js"
184147 ] ;
185148}
0 commit comments