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