1
1
'use strict'
2
2
3
- const yargs = require ( 'yargs' )
4
3
const path = require ( 'path' )
5
4
const mocks = require ( 'mocks' )
6
5
@@ -34,7 +33,7 @@ describe('cli', () => {
34
33
}
35
34
36
35
const processArgs = ( args , opts ) => {
37
- const argv = yargs . parse ( args )
36
+ const argv = m . describeRoot ( ) . parse ( args )
38
37
return e . processArgs ( argv , opts || { } , fsMock , pathMock )
39
38
}
40
39
@@ -63,14 +62,14 @@ describe('cli', () => {
63
62
describe ( 'processArgs' , ( ) => {
64
63
it ( 'should override if multiple options given' , ( ) => {
65
64
// yargs parses --port 123 --port 456 as port = [123, 456] which makes no sense
66
- const options = processArgs ( [ 'some.conf' , '--port' , '12' , '--log-level' , 'info' , '--port' , '34' , '--log-level' , 'debug' ] )
65
+ const options = processArgs ( [ 'start' , ' some.conf', '--port' , '12' , '--log-level' , 'info' , '--port' , '34' , '--log-level' , 'debug' ] )
67
66
68
67
expect ( options . port ) . to . equal ( 34 )
69
68
expect ( options . logLevel ) . to . equal ( 'DEBUG' )
70
69
} )
71
70
72
71
it ( 'should return camelCased options' , ( ) => {
73
- const options = processArgs ( [ 'some.conf' , '--port' , '12' , '--single-run' ] )
72
+ const options = processArgs ( [ 'start' , ' some.conf', '--port' , '12' , '--single-run' ] )
74
73
75
74
expect ( options . configFile ) . to . exist
76
75
expect ( options . port ) . to . equal ( 12 )
@@ -79,105 +78,105 @@ describe('cli', () => {
79
78
80
79
it ( 'should parse options without configFile and set default' , ( ) => {
81
80
setCWD ( '/cwd' )
82
- const options = processArgs ( [ '--auto-watch ' , '--auto-watch-interval' , '10 '] )
81
+ const options = processArgs ( [ 'start ' , '--auto-watch' ] )
83
82
expect ( path . resolve ( options . configFile ) ) . to . equal ( path . resolve ( '/cwd/karma.conf.js' ) )
84
83
expect ( options . autoWatch ) . to . equal ( true )
85
- expect ( options . autoWatchInterval ) . to . equal ( 10 )
86
84
} )
87
85
88
86
it ( 'should set default karma.conf.coffee config file if exists' , ( ) => {
89
87
setCWD ( '/cwd2' )
90
- const options = processArgs ( [ '--port' , '10' ] )
88
+ const options = processArgs ( [ 'start' , ' --port', '10' ] )
91
89
92
90
expect ( path . resolve ( options . configFile ) ) . to . equal ( path . resolve ( '/cwd2/karma.conf.coffee' ) )
93
91
} )
94
92
95
93
it ( 'should set default karma.conf.ts config file if exists' , ( ) => {
96
94
setCWD ( '/cwd3' )
97
- const options = processArgs ( [ '--port' , '10' ] )
95
+ const options = processArgs ( [ 'start' , ' --port', '10' ] )
98
96
99
97
expect ( path . resolve ( options . configFile ) ) . to . equal ( path . resolve ( '/cwd3/karma.conf.ts' ) )
100
98
} )
101
99
102
100
it ( 'should not set default config if neither exists' , ( ) => {
103
101
setCWD ( '/' )
104
- const options = processArgs ( [ ] )
102
+ const options = processArgs ( [ 'start' ] )
105
103
106
104
expect ( options . configFile ) . to . equal ( null )
107
105
} )
108
106
109
107
it ( 'should parse auto-watch, colors, singleRun to boolean' , ( ) => {
110
- let options = processArgs ( [ '--auto-watch' , 'false' , '--colors' , 'false' , '--single-run' , 'false' ] )
108
+ let options = processArgs ( [ 'start' , ' --auto-watch', 'false' , '--colors' , 'false' , '--single-run' , 'false' ] )
111
109
112
110
expect ( options . autoWatch ) . to . equal ( false )
113
111
expect ( options . colors ) . to . equal ( false )
114
112
expect ( options . singleRun ) . to . equal ( false )
115
113
116
- options = processArgs ( [ '--auto-watch' , 'true' , '--colors' , 'true' , '--single-run' , 'true' ] )
114
+ options = processArgs ( [ 'start' , ' --auto-watch', 'true' , '--colors' , 'true' , '--single-run' , 'true' ] )
117
115
118
116
expect ( options . autoWatch ) . to . equal ( true )
119
117
expect ( options . colors ) . to . equal ( true )
120
118
expect ( options . singleRun ) . to . equal ( true )
121
119
} )
122
120
123
121
it ( 'should replace log-level constants' , ( ) => {
124
- let options = processArgs ( [ '--log-level' , 'debug' ] )
122
+ let options = processArgs ( [ 'start' , ' --log-level', 'debug' ] )
125
123
expect ( options . logLevel ) . to . equal ( constant . LOG_DEBUG )
126
124
127
- options = processArgs ( [ '--log-level' , 'error' ] )
125
+ options = processArgs ( [ 'start' , ' --log-level', 'error' ] )
128
126
expect ( options . logLevel ) . to . equal ( constant . LOG_ERROR )
129
127
130
- options = processArgs ( [ '--log-level' , 'warn' ] )
128
+ options = processArgs ( [ 'start' , ' --log-level', 'warn' ] )
131
129
expect ( options . logLevel ) . to . equal ( constant . LOG_WARN )
132
130
133
- options = processArgs ( [ '--log-level' , 'foo' ] )
131
+ options = processArgs ( [ 'start' , ' --log-level', 'foo' ] )
134
132
expect ( mockery . process . exit ) . to . have . been . calledWith ( 1 )
135
133
136
- options = processArgs ( [ '--log-level' ] )
134
+ options = processArgs ( [ 'start' , ' --log-level'] )
137
135
expect ( mockery . process . exit ) . to . have . been . calledWith ( 1 )
138
136
} )
139
137
140
138
it ( 'should parse format-error into a function' , ( ) => {
141
139
// root export
142
- let options = processArgs ( [ '--format-error' , '../../test/unit/fixtures/format-error-root' ] )
140
+ let options = processArgs ( [ 'start' , ' --format-error', '../../test/unit/fixtures/format-error-root' ] )
143
141
const formatErrorRoot = require ( '../../test/unit/fixtures/format-error-root' )
144
142
expect ( options . formatError ) . to . equal ( formatErrorRoot )
145
143
146
144
// property export
147
- options = processArgs ( [ '--format-error' , '../../test/unit/fixtures/format-error-property' ] )
145
+ options = processArgs ( [ 'start' , ' --format-error', '../../test/unit/fixtures/format-error-property' ] )
148
146
const formatErrorProperty = require ( '../../test/unit/fixtures/format-error-property' ) . formatError
149
147
expect ( options . formatError ) . to . equal ( formatErrorProperty )
150
148
} )
151
149
152
150
it ( 'should parse browsers into an array' , ( ) => {
153
- const options = processArgs ( [ '--browsers' , 'Chrome,ChromeCanary,Firefox' ] )
151
+ const options = processArgs ( [ 'start' , ' --browsers', 'Chrome,ChromeCanary,Firefox' ] )
154
152
expect ( options . browsers ) . to . deep . equal ( [ 'Chrome' , 'ChromeCanary' , 'Firefox' ] )
155
153
} )
156
154
157
155
it ( 'should resolve configFile to absolute path' , ( ) => {
158
156
setCWD ( '/cwd' )
159
- const options = processArgs ( [ 'some/config.js' ] )
157
+ const options = processArgs ( [ 'start' , ' some/config.js'] )
160
158
expect ( path . resolve ( options . configFile ) ) . to . equal ( path . resolve ( '/cwd/some/config.js' ) )
161
159
} )
162
160
163
161
it ( 'should parse report-slower-than to a number' , ( ) => {
164
- let options = processArgs ( [ '--report-slower-than' , '2000' ] )
162
+ let options = processArgs ( [ 'start' , ' --report-slower-than', '2000' ] )
165
163
expect ( options . reportSlowerThan ) . to . equal ( 2000 )
166
164
167
- options = processArgs ( [ '--no-report-slower-than' ] )
165
+ options = processArgs ( [ 'start' , ' --no-report-slower-than'] )
168
166
expect ( options . reportSlowerThan ) . to . equal ( 0 )
169
167
} )
170
168
171
169
it ( 'should cast reporters to array' , ( ) => {
172
- let options = processArgs ( [ '--reporters' , 'dots,junit' ] )
170
+ let options = processArgs ( [ 'start' , ' --reporters', 'dots,junit' ] )
173
171
expect ( options . reporters ) . to . deep . equal ( [ 'dots' , 'junit' ] )
174
172
175
- options = processArgs ( [ '--reporters' , 'dots' ] )
173
+ options = processArgs ( [ 'start' , ' --reporters', 'dots' ] )
176
174
expect ( options . reporters ) . to . deep . equal ( [ 'dots' ] )
177
175
} )
178
176
179
177
it ( 'should parse removed/added/changed files to array' , ( ) => {
180
178
const options = processArgs ( [
179
+ 'run' ,
181
180
'--removed-files' , 'r1.js,r2.js' ,
182
181
'--changed-files' , 'ch1.js,ch2.js' ,
183
182
'--added-files' , 'a1.js,a2.js'
@@ -187,18 +186,6 @@ describe('cli', () => {
187
186
expect ( options . addedFiles ) . to . deep . equal ( [ 'a1.js' , 'a2.js' ] )
188
187
expect ( options . changedFiles ) . to . deep . equal ( [ 'ch1.js' , 'ch2.js' ] )
189
188
} )
190
-
191
- it ( 'should error on args with underscores' , ( ) => {
192
- let expectedException
193
- try {
194
- const options = processArgs ( [ '--no_browsers' ] )
195
- expectedException = 'Should have thrown but got ' + options
196
- } catch ( e ) {
197
- expectedException = e
198
- } finally {
199
- expect ( expectedException + '' ) . to . includes ( 'Bad argument: no_browsers did you mean no-browsers' )
200
- }
201
- } )
202
189
} )
203
190
204
191
describe ( 'parseClientArgs' , ( ) => {
0 commit comments