@@ -12,191 +12,221 @@ const files = {
12
12
} ;
13
13
14
14
15
- // Local config
15
+ // Settings
16
16
// =============================================================================
17
- const localConfig = {
18
- // Add browsers via Karma launchers
19
- // https://www.npmjs.com/search?q=karma+launcher
20
- browsers : [
21
- 'ChromeHeadless'
22
- ] ,
23
- files : [
24
- 'node_modules/@babel/polyfill/dist/polyfill.js' ,
25
- files . test ,
26
- // Served only
27
- // NOTE: Access in test files by prepending /base/ to path)
28
- { pattern : files . fixtures , included : false , served : true , watched : true }
29
- ] ,
30
- preprocessors : {
31
- [ files . fixtures ] : [ 'file-fixtures' ] ,
32
- [ files . test ] : [ 'eslint' , 'webpack' , 'sourcemap' ]
33
- } ,
34
- frameworks : [ 'mocha' , 'chai' ] ,
35
- reporters : [ 'mocha' , 'coverage' ] ,
36
- fileFixtures : {
37
- stripPrefix : 'tests/fixtures/'
38
- } ,
39
- webpack : {
40
- mode : 'development' ,
41
- devtool : 'inline-source-map' ,
42
- module : {
43
- rules : [ {
44
- test : / \. j s $ / ,
45
- exclude : [ / n o d e _ m o d u l e s / ] ,
46
- use : [ {
47
- loader : 'babel-loader' ,
48
- options : {
49
- presets : [
50
- [ '@babel/env' , {
51
- targets : {
52
- browsers : [ 'ie >= 9' ]
53
- }
54
- } ]
55
- ] ,
56
- plugins : [
57
- 'transform-custom-element-classes' ,
58
- [ 'istanbul' , {
59
- exclude : [
60
- '**/*.test.js' ,
61
- 'tests/helpers/*'
62
- ]
63
- } ]
17
+ const settings = {
18
+ base : {
19
+ browsers : [
20
+ 'ChromeHeadless'
21
+ ] ,
22
+ files : [
23
+ 'node_modules/@babel/polyfill/dist/polyfill.js' ,
24
+ files . test ,
25
+ // Served only (Access in tests by prepending /base/ to path)
26
+ { pattern : files . fixtures , included : false , served : true , watched : true }
27
+ ] ,
28
+ preprocessors : {
29
+ [ files . fixtures ] : [ 'file-fixtures' ] ,
30
+ [ files . test ] : [ 'eslint' , 'webpack' , 'sourcemap' ]
31
+ } ,
32
+ frameworks : [ 'mocha' , 'chai' ] ,
33
+ reporters : [ 'mocha' ] ,
34
+ fileFixtures : {
35
+ stripPrefix : 'tests/fixtures/'
36
+ } ,
37
+ webpack : {
38
+ mode : 'development' ,
39
+ module : {
40
+ rules : [
41
+ {
42
+ test : / \. j s $ / ,
43
+ exclude : [ / n o d e _ m o d u l e s / ] ,
44
+ use : [
45
+ {
46
+ loader : 'babel-loader' ,
47
+ options : {
48
+ presets : [
49
+ [
50
+ '@babel/env' ,
51
+ {
52
+ targets : {
53
+ browsers : [ 'ie >= 9' ]
54
+ }
55
+ }
56
+ ]
57
+ ] ,
58
+ plugins : [
59
+ 'transform-custom-element-classes'
60
+ ]
61
+ } ,
62
+ }
64
63
]
65
- } ,
66
- } ]
67
- } ]
68
- }
69
- } ,
70
- webpackMiddleware : {
71
- // https://webpack.js.org/configuration/stats/
72
- stats : 'minimal'
73
- } ,
74
- // Code coverage
75
- // https://www.npmjs.com/package/karma-coverage
76
- coverageReporter : {
77
- reporters : [
78
- { type : 'html' } ,
79
- { type : 'lcovonly' } ,
80
- { type : 'text-summary' }
81
- ]
82
- } ,
83
- // Mocha reporter
84
- // https://www.npmjs.com/package/karma-mocha-reporter
85
- mochaReporter : {
86
- output : 'autowatch'
64
+ }
65
+ ]
66
+ }
67
+ } ,
68
+ webpackMiddleware : {
69
+ // https://webpack.js.org/configuration/stats/
70
+ stats : 'minimal'
71
+ } ,
72
+ mochaReporter : {
73
+ // https://www.npmjs.com/package/karma-mocha-reporter
74
+ output : 'autowatch'
75
+ } ,
76
+ autoWatch : false ,
77
+ browserDisconnectTimeout : 1000 * 2 , // default 2000
78
+ browserDisconnectTolerance : 1 , // default 0
79
+ browserNoActivityTimeout : 1000 * 10 , // default 10000
80
+ captureTimeout : 1000 * 60 , // default 60000
81
+ colors : true ,
82
+ concurrency : Infinity ,
83
+ port : 9876 ,
84
+ singleRun : true
87
85
} ,
88
- port : 9876 ,
89
- colors : true ,
90
- autoWatch : false ,
91
- singleRun : true ,
92
- concurrency : Infinity ,
93
- // Avoid DISCONNECTED messages
94
- browserDisconnectTimeout : 1000 * 2 , // default 2000
95
- browserDisconnectTolerance : 1 , // default 0
96
- browserNoActivityTimeout : 1000 * 10 , // default 10000
97
- captureTimeout : 1000 * 60 // default 60000
98
- } ;
86
+ coverage : {
87
+ get reporters ( ) {
88
+ return [ ] . concat ( settings . base . reporters , 'coverage' ) ;
89
+ } ,
90
+ get webpack ( ) {
91
+ const webpackConfig = Object . assign ( { } , settings . base . webpack ) ;
92
+ const babelPluginsConfig = webpackConfig . module . rules [ 0 ] . use [ 0 ] . options . plugins ;
99
93
94
+ babelPluginsConfig . push ( [ 'istanbul' , { exclude : 'tests/*' } ] ) ;
100
95
101
- // Remote config
102
- // =============================================================================
103
- const remoteConfig = Object . assign ( { } , localConfig , {
104
- // SauceLabs browers (see platform configurator below)
105
- // https://wiki.saucelabs.com/display/DOCS/Platform+Configurator#/
106
- customLaunchers : {
107
- sl_chrome : {
108
- base : 'SauceLabs' ,
109
- browserName : 'Chrome' ,
110
- platform : 'Windows 10' ,
111
- version : '48.0'
112
- } ,
113
- // DISABLED DUE TO SAUCELABS ISSUES
114
- // sl_edge: {
115
- // base : 'SauceLabs',
116
- // browserName: 'MicrosoftEdge',
117
- // platform : 'Windows 10',
118
- // version : '14.14393'
119
- // },
120
- sl_firefox : {
121
- base : 'SauceLabs' ,
122
- browserName : 'Firefox' ,
123
- platform : 'Windows 10' ,
124
- version : '30'
96
+ return webpackConfig ;
125
97
} ,
126
- // DISABLED DUE TO SAUCELABS ISSUES
127
- // sl_ie_11: {
128
- // base : 'SauceLabs',
129
- // browserName: 'Internet Explorer',
130
- // platform : 'Windows 10',
131
- // version : '11.0'
132
- // },
133
- sl_ie_10 : {
134
- base : 'SauceLabs' ,
135
- browserName : 'Internet Explorer' ,
136
- platform : 'Windows 8' ,
137
- version : '10.0'
138
- } ,
139
- sl_ie_9 : {
140
- base : 'SauceLabs' ,
141
- browserName : 'Internet Explorer' ,
142
- platform : 'Windows 7' ,
143
- version : '9.0'
98
+ // Code coverage
99
+ // https://www.npmjs.com/package/karma-coverage
100
+ coverageReporter : {
101
+ reporters : [
102
+ { type : 'html' } ,
103
+ { type : 'lcovonly' } ,
104
+ { type : 'text-summary' }
105
+ ]
144
106
}
145
- // DISABLED DUE TO SAUCELABS ISSUES
146
- // sl_safari: {
147
- // base : 'SauceLabs',
148
- // browserName: 'Safari',
149
- // platform : 'OS X 10.10',
150
- // version : '8.0'
151
- // }
152
107
} ,
153
- // Set browsers to customLaunchers
154
- get browsers ( ) {
155
- return Object . keys ( this . customLaunchers ) ;
108
+ local : {
109
+ get webpack ( ) {
110
+ const webpackConfig = Object . assign ( { } , settings . base . webpack ) ;
111
+
112
+ webpackConfig . devtool = 'inline-source-map' ;
113
+
114
+ return webpackConfig ;
115
+ } ,
156
116
} ,
157
- // SauceLab settings
158
- sauceLabs : {
159
- username : saucelabs . username || process . env . SAUCE_USERNAME ,
160
- accessKey : saucelabs . accessKey || process . env . SAUCE_ACCESS_KEY ,
161
- testName : `${ pkg . name } (karma)` ,
162
- recordScreenshots : false ,
163
- recordVideo : false
117
+ remote : {
118
+ // Use custom hostname to prevent Safari disconnects
119
+ // https://support.saucelabs.com/hc/en-us/articles/115010079868-Issues-with-Safari-and-Karma-Test-Runner
120
+ hostname : 'TRAVIS' in process . env ? 'travis.dev' : 'localhost' ,
121
+ get reporters ( ) {
122
+ return [ ] . concat ( settings . base . reporters , 'saucelabs' ) ;
123
+ } ,
124
+ sauceLabs : {
125
+ username : saucelabs . username || process . env . SAUCE_USERNAME ,
126
+ accessKey : saucelabs . accessKey || process . env . SAUCE_ACCESS_KEY ,
127
+ testName : `${ pkg . name } (karma)` ,
128
+ recordScreenshots : false ,
129
+ recordVideo : false
130
+ }
164
131
}
165
- } ) ;
132
+ } ;
133
+
134
+
135
+ // Functions
136
+ // =============================================================================
137
+ function message ( text , level = 'log' ) {
138
+ // Credit: Thomas Brierley
139
+ // https://stackoverflow.com/a/51506718/4903063
140
+ const wrap = ( s , w = 60 ) => {
141
+ s = s . replace ( new RegExp ( `(?![^\\n]{1,${ w } }$)([^\\n]{1,${ w } })\\s` , 'g' ) , '$1\n' ) ;
142
+ s = s . replace ( / \n \s / g, '\n' ) ;
143
+
144
+ return s ;
145
+ } ;
146
+
147
+ // eslint-disable-next-line
148
+ console [ level ] ( [
149
+ '============================================================\n' ,
150
+ `${ wrap ( text ) } \n` ,
151
+ '============================================================\n'
152
+ ] . join ( '' ) ) ;
153
+ }
166
154
167
155
168
156
// Export
169
157
// =============================================================================
170
158
module . exports = function ( config ) {
171
- const isRemote = Boolean ( process . argv . indexOf ( '--remote' ) > - 1 ) ;
172
- const testConfig = isRemote ? remoteConfig : localConfig ;
173
-
174
- if ( isRemote ) {
175
- // Disabled source maps to prevent SauceLabs timeouts
176
- // https://github.com/karma-runner/karma-sauce-launcher/issues/95
177
- testConfig . webpack . devtool = '' ;
178
- testConfig . webpack . module . rules [ 0 ] . use [ 0 ] . options . sourceMap = false ;
179
-
180
- // Add SauceLabs reporter
181
- testConfig . reporters . push ( 'saucelabs' ) ;
182
-
183
- // Remove text-summary reporter
184
- testConfig . coverageReporter . reporters = testConfig . coverageReporter . reporters . filter ( obj => obj . type !== 'text-summary' ) ;
185
-
186
- // Travis-specific settings
187
- if ( 'TRAVIS' in process . env ) {
188
- // Use custom hostname to prevent Safari disconnects
189
- // https://support.saucelabs.com/hc/en-us/articles/115010079868-Issues-with-Safari-and-Karma-Test-Runner
190
- testConfig . hostname = 'travis.dev' ;
191
- }
159
+ const isRemoteCoverage = Boolean ( process . argv . indexOf ( '--remotecoverage' ) > - 1 ) ;
160
+ const isRemoteTest = Boolean ( process . argv . indexOf ( '--remotetest' ) > - 1 ) ;
161
+ const testConfig = Object . assign ( { } , settings . base ) ;
162
+
163
+ // Remote test
164
+ if ( isRemoteTest ) {
165
+ message ( 'KARMA: Browser Tests' ) ;
166
+
167
+ Object . assign ( testConfig , settings . remote , {
168
+ // SauceLabs browers
169
+ // https://wiki.saucelabs.com/display/DOCS/Platform+Configurator#/
170
+ customLaunchers : {
171
+ sl_chrome : {
172
+ base : 'SauceLabs' ,
173
+ browserName : 'Chrome' ,
174
+ platform : 'Windows 10' ,
175
+ version : '48.0'
176
+ } ,
177
+ sl_edge : {
178
+ base : 'SauceLabs' ,
179
+ browserName : 'MicrosoftEdge' ,
180
+ platform : 'Windows 10' ,
181
+ version : '14.14393'
182
+ } ,
183
+ sl_firefox : {
184
+ base : 'SauceLabs' ,
185
+ browserName : 'Firefox' ,
186
+ platform : 'Windows 10' ,
187
+ version : '30'
188
+ } ,
189
+ sl_ie_11 : {
190
+ base : 'SauceLabs' ,
191
+ browserName : 'Internet Explorer' ,
192
+ platform : 'Windows 10' ,
193
+ version : '11.0'
194
+ } ,
195
+ sl_ie_10 : {
196
+ base : 'SauceLabs' ,
197
+ browserName : 'Internet Explorer' ,
198
+ platform : 'Windows 8' ,
199
+ version : '10.0'
200
+ } ,
201
+ sl_ie_9 : {
202
+ base : 'SauceLabs' ,
203
+ browserName : 'Internet Explorer' ,
204
+ platform : 'Windows 7' ,
205
+ version : '9.0'
206
+ } ,
207
+ sl_safari : {
208
+ base : 'SauceLabs' ,
209
+ browserName : 'Safari' ,
210
+ platform : 'OS X 10.10' ,
211
+ version : '8.0'
212
+ }
213
+ } ,
214
+ get browsers ( ) {
215
+ return Object . keys ( this . customLaunchers ) ;
216
+ }
217
+ } ) ;
218
+ }
219
+ // Remove coverage
220
+ else if ( isRemoteCoverage ) {
221
+ message ( 'KARMA: Code Coverage' ) ;
222
+
223
+ Object . assign ( testConfig , settings . remote , settings . coverage ) ;
192
224
}
225
+ // Local
193
226
else {
194
- // eslint-disable-next-line
195
- console . log ( [
196
- '============================================================\n' ,
197
- `KARMA: localhost:${ testConfig . port } /debug.html\n` ,
198
- '============================================================\n'
199
- ] . join ( '' ) ) ;
227
+ message ( `KARMA: localhost:${ testConfig . port } /debug.html` ) ;
228
+
229
+ Object . assign ( testConfig , settings . local , settings . coverage ) ;
200
230
}
201
231
202
232
// Logging: LOG_DISABLE, LOG_ERROR, LOG_WARN, LOG_INFO, LOG_DEBUG
0 commit comments