1
1
/* eslint-env node*/
2
2
3
- // Karma configuration
4
-
5
- /*
6
- * Test file globs can be passed with an argument.
7
- *
8
- * Example:
9
- *
10
- * $ npm run test-jasmine -- tests/axes_test.js
11
- *
12
- * will only run the tests in axes_test.js
13
- *
14
- */
15
-
3
+ var path = require ( 'path' ) ;
4
+ var minimist = require ( 'minimist' ) ;
16
5
var constants = require ( '../../tasks/util/constants' ) ;
17
6
18
- var arg = process . argv [ 4 ] ;
19
-
20
7
var isCI = ! ! process . env . CIRCLECI ;
21
- var testFileGlob = arg ? arg : 'tests/*_test.js' ;
22
- var isSingleSuiteRun = ( arg && arg . indexOf ( 'bundle_tests/' ) === - 1 ) ;
23
- var isRequireJSTest = ( arg && arg . indexOf ( 'bundle_tests/requirejs' ) !== - 1 ) ;
24
- var isIE9Test = ( arg && arg . indexOf ( 'bundle_tests/ie9' ) !== - 1 ) ;
8
+ var argv = minimist ( process . argv . slice ( 4 ) , {
9
+ string : [ 'bundleTest' , 'width' , 'height' ] ,
10
+ 'boolean' : [ 'info' , 'watch' , 'verbose' , 'Chrome' , 'Firefox' ] ,
11
+ alias : {
12
+ 'Chrome' : 'chrome' ,
13
+ 'Firefox' : [ 'firefox' , 'FF' ] ,
14
+ 'bundleTest' : [ 'bundletest' , 'bundle_test' ]
15
+ } ,
16
+ 'default' : {
17
+ info : false ,
18
+ watch : false ,
19
+ verbose : false ,
20
+ width : '1035' ,
21
+ height : '617'
22
+ }
23
+ } ) ;
24
+
25
+ if ( argv . info ) {
26
+ console . log ( [
27
+ 'plotly.js karma runner for jasmine tests CLI info' ,
28
+ '' ,
29
+ 'Examples:' ,
30
+ '' ,
31
+ 'Run `axes_test.js`, `bar_test.js` and `scatter_test.js` suites in `autoWatch` / multiple run mode:' ,
32
+ ' $ npm run test-jasmine -- axes bar_test.js scatter --watch' ,
33
+ '' ,
34
+ 'Run all tests with the `noCI` tag on Firefox in a 1500px wide window:' ,
35
+ ' $ npm run test-jasmine -- --tags=noCI --FF --width=1500' ,
36
+ '' ,
37
+ 'Run the `ie9_test.js` bundle test with the verbose reporter:' ,
38
+ ' $ npm run test-jasmine -- --bundleTest=ie9 --verbose' ,
39
+ '' ,
40
+ 'Arguments:' ,
41
+ ' - All non-flagged arguments corresponds to the test suites in `test/jasmine/tests/` to be run.' ,
42
+ ' No need to add the `_test.js` suffix, we expand them correctly here.' ,
43
+ ' - `--bundleTest` set the bundle test suite `test/jasmine/bundle_tests/ to be run.' ,
44
+ ' Note that only one bundle test can be run at a time.' ,
45
+ '' ,
46
+ 'Other options:' ,
47
+ ' - `--info`: show this info message' ,
48
+ ' - `--Chrome` (alias `--chrome`): run test in (our custom) Chrome browser' ,
49
+ ' - `--Firefox` (alias `--FF`, `--firefox`): run test in (our custom) Firefox browser' ,
50
+ ' - `--watch (dflt: `false`)`: run karma in `autoWatch` / multiple run mode' ,
51
+ ' - `--verbose` (dflt: `false`): show test result using verbose reporter' ,
52
+ ' - `--tags`: run only test with given tags (using the `jasmine-spec-tags` framework)' ,
53
+ ' - `--width`(dflt: 1035): set width of the browser window' ,
54
+ ' - `--height` (dflt: 617): set height of the browser window' ,
55
+ '' ,
56
+ 'For info on the karma CLI options run `npm run test-jasmine -- --help`'
57
+ ] . join ( '\n' ) ) ;
58
+ process . exit ( 0 ) ;
59
+ }
60
+
61
+ var SUFFIX = '_test.js' ;
62
+ var basename = function ( s ) { return path . basename ( s , SUFFIX ) ; } ;
63
+ var merge = function ( _ ) {
64
+ var list = [ ] ;
65
+
66
+ ( Array . isArray ( _ ) ? _ : [ _ ] ) . forEach ( function ( p ) {
67
+ list = list . concat ( p . split ( ',' ) ) ;
68
+ } ) ;
69
+
70
+ return list ;
71
+ } ;
72
+ var glob = function ( _ ) {
73
+ return _ . length === 1 ?
74
+ _ [ 0 ] + SUFFIX :
75
+ '{' + _ . join ( ',' ) + '}' + SUFFIX ;
76
+ } ;
77
+
78
+ var isBundleTest = ! ! argv . bundleTest ;
79
+ var isFullSuite = ! isBundleTest && argv . _ . length === 0 ;
80
+ var testFileGlob ;
81
+
82
+ if ( isFullSuite ) {
83
+ testFileGlob = path . join ( 'tests' , '*' + SUFFIX ) ;
84
+ } else if ( isBundleTest ) {
85
+ var _ = merge ( argv . bundleTest ) ;
86
+
87
+ if ( _ . length > 1 ) {
88
+ console . warn ( 'Can only run one bundle test suite at a time, ignoring ' , _ . slice ( 1 ) ) ;
89
+ }
90
+
91
+ testFileGlob = path . join ( 'bundle_tests' , glob ( [ basename ( _ [ 0 ] ) ] ) ) ;
92
+ } else {
93
+ testFileGlob = path . join ( 'tests' , glob ( merge ( argv . _ ) . map ( basename ) ) ) ;
94
+ }
25
95
26
- var pathToMain = '../../lib/index.js' ;
27
- var pathToJQuery = 'assets/jquery-1.8.3.min.js' ;
96
+ var pathToShortcutPath = path . join ( __dirname , '..' , '..' , 'tasks' , 'util' , 'shortcut_paths.js' ) ;
97
+ var pathToMain = path . join ( __dirname , '..' , '..' , 'lib' , 'index.js' ) ;
98
+ var pathToJQuery = path . join ( __dirname , 'assets' , 'jquery-1.8.3.min.js' ) ;
99
+ var pathToIE9mock = path . join ( __dirname , 'assets' , 'ie9_mock.js' ) ;
28
100
29
101
30
102
function func ( config ) {
@@ -71,13 +143,13 @@ func.defaultConfig = {
71
143
preprocessors : { } ,
72
144
73
145
// test results reporter to use
74
- // possible values: 'dots', 'progress'
146
+ // possible values: 'dots', 'progress', 'spec' and 'verbose'
75
147
// available reporters: https://npmjs.org/browse/keyword/karma-reporter
76
148
//
77
149
// See note in CONTRIBUTING.md about more verbose reporting via karma-verbose-reporter:
78
150
// https://www.npmjs.com/package/karma-verbose-reporter ('verbose')
79
151
//
80
- reporters : isSingleSuiteRun ? [ 'progress' ] : [ 'dots' , 'spec' ] ,
152
+ reporters : ( isFullSuite && ! argv . tags ) ? [ 'dots' , 'spec' ] : [ 'progress '] ,
81
153
82
154
// web server port
83
155
port : 9876 ,
@@ -86,38 +158,43 @@ func.defaultConfig = {
86
158
colors : true ,
87
159
88
160
// enable / disable watching file and executing tests whenever any file changes
89
- autoWatch : ! isCI ,
161
+ autoWatch : argv . watch ,
90
162
91
163
// if true, Karma captures browsers, runs the tests and exits
92
- singleRun : isCI ,
164
+ singleRun : ! argv . watch ,
93
165
94
166
// how long will Karma wait for a message from a browser before disconnecting (30 ms)
95
167
browserNoActivityTimeout : 30000 ,
96
168
97
169
// start these browsers
98
170
// available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
99
- browsers : [ 'Chrome_WindowSized' ] ,
171
+ //
172
+ // N.B. this field is filled below
173
+ browsers : [ ] ,
100
174
101
175
// custom browser options
102
176
//
103
177
// window-size values came from observing default size
104
178
//
105
179
// '--ignore-gpu-blacklist' allow to test WebGL on CI (!!!)
106
180
customLaunchers : {
107
- Chrome_WindowSized : {
181
+ _Chrome : {
108
182
base : 'Chrome' ,
109
- flags : [ '--window-size=1035,617' , '--ignore-gpu-blacklist' ]
183
+ flags : [
184
+ '--window-size=' + argv . width + ',' + argv . height ,
185
+ isCI ? '--ignore-gpu-blacklist' : ''
186
+ ]
110
187
} ,
111
- Firefox_WindowSized : {
188
+ _Firefox : {
112
189
base : 'Firefox' ,
113
- flags : [ '--width=1035' , '--height=617' ]
190
+ flags : [ '--width=' + argv . width , '--height=' + argv . height ]
114
191
}
115
192
} ,
116
193
117
194
browserify : {
118
- transform : [ '../../tasks/util/shortcut_paths.js' ] ,
195
+ transform : [ pathToShortcutPath ] ,
119
196
extensions : [ '.js' ] ,
120
- watch : ! isCI ,
197
+ watch : argv . watch ,
121
198
debug : true
122
199
} ,
123
200
@@ -140,10 +217,33 @@ func.defaultConfig = {
140
217
}
141
218
} ;
142
219
143
- // Add lib/index.js to single-suite runs,
144
- // to avoid import conflicts due to plotly.js
145
- // circular dependencies.
146
- if ( isSingleSuiteRun ) {
220
+ if ( isFullSuite ) {
221
+ func . defaultConfig . files . push ( pathToJQuery ) ;
222
+ func . defaultConfig . preprocessors [ testFileGlob ] = [ 'browserify' ] ;
223
+ } else if ( isBundleTest ) {
224
+ switch ( basename ( testFileGlob ) ) {
225
+ case 'requirejs' :
226
+ func . defaultConfig . files = [
227
+ constants . pathToRequireJS ,
228
+ constants . pathToRequireJSFixture
229
+ ] ;
230
+ break ;
231
+ case 'ie9' :
232
+ // load ie9_mock.js before plotly.js+test bundle
233
+ // to catch reference errors that could occur
234
+ // when plotly.js is first loaded.
235
+ func . defaultConfig . files . push ( pathToIE9mock ) ;
236
+ func . defaultConfig . preprocessors [ testFileGlob ] = [ 'browserify' ] ;
237
+ break ;
238
+ default :
239
+ func . defaultConfig . preprocessors [ testFileGlob ] = [ 'browserify' ] ;
240
+ break ;
241
+ }
242
+ } else {
243
+ // Add lib/index.js to non-full-suite runs,
244
+ // to avoid import conflicts due to plotly.js
245
+ // circular dependencies.
246
+
147
247
func . defaultConfig . files . push (
148
248
pathToJQuery ,
149
249
pathToMain
@@ -152,26 +252,19 @@ if(isSingleSuiteRun) {
152
252
func . defaultConfig . preprocessors [ pathToMain ] = [ 'browserify' ] ;
153
253
func . defaultConfig . preprocessors [ testFileGlob ] = [ 'browserify' ] ;
154
254
}
155
- else if ( isRequireJSTest ) {
156
- func . defaultConfig . files = [
157
- constants . pathToRequireJS ,
158
- constants . pathToRequireJSFixture
159
- ] ;
160
- }
161
- else if ( isIE9Test ) {
162
- // load ie9_mock.js before plotly.js+test bundle
163
- // to catch reference errors that could occur
164
- // when plotly.js is first loaded.
165
-
166
- func . defaultConfig . files . push ( './assets/ie9_mock.js' ) ;
167
- func . defaultConfig . preprocessors [ testFileGlob ] = [ 'browserify' ] ;
168
- }
169
- else {
170
- func . defaultConfig . files . push ( pathToJQuery ) ;
171
- func . defaultConfig . preprocessors [ testFileGlob ] = [ 'browserify' ] ;
172
- }
173
255
174
256
// lastly, load test file glob
175
257
func . defaultConfig . files . push ( testFileGlob ) ;
176
258
259
+ // add browsers
260
+ var browsers = func . defaultConfig . browsers ;
261
+ if ( argv . Chrome ) browsers . push ( '_Chrome' ) ;
262
+ if ( argv . Firefox ) browsers . push ( '_Firefox' ) ;
263
+ if ( browsers . length === 0 ) browsers . push ( '_Chrome' ) ;
264
+
265
+ // add verbose reporter if specified
266
+ if ( argv . verbose ) {
267
+ func . defaultConfig . reporters . push ( 'verbose' ) ;
268
+ }
269
+
177
270
module . exports = func ;
0 commit comments