@@ -5,6 +5,7 @@ import {Promise} from 'bluebird'
55import Browser from '../../../lib/browser'
66import BrowserCollection from '../../../lib/browser_collection'
77import MultReporter from '../../../lib/reporters/multi'
8+ var _ = require ( 'lodash' )
89var createRunnerMiddleware = require ( '../../../lib/middleware/runner' ) . create
910var HttpResponseMock = mocks . http . ServerResponse
1011var HttpRequestMock = mocks . http . ServerRequest
@@ -144,26 +145,99 @@ describe('middleware.runner', () => {
144145 handler ( new HttpRequestMock ( '/__run__' ) , response , nextSpy )
145146 } )
146147
147- it ( 'should parse body and set client.args' , ( done ) => {
148- capturedBrowsers . add ( new Browser ( ) )
149- sinon . stub ( capturedBrowsers , 'areAllReady' , ( ) => true )
150-
151- emitter . once ( 'run_start' , ( ) => {
152- expect ( config . client . args ) . to . deep . equal ( [ 'arg1' , 'arg2' ] )
153- done ( )
154- } )
155-
156- var RAW_MESSAGE = '{"args": ["arg1", "arg2"]}'
157-
158- var request = new HttpRequestMock ( '/__run__' , {
159- 'content-type' : 'application/json' ,
160- 'content-length' : RAW_MESSAGE . length
148+ var clientArgsRuns = [
149+ {
150+ desc : 'should parse body and set client.args' ,
151+ expected : [ 'arg1' , 'arg2' ] ,
152+ rawMessage : '{"args": ["arg1", "arg2"]}'
153+ } ,
154+ {
155+ desc : 'should set array client args passed by run when there are no existing client.args' ,
156+ expected : [ 'my_args' ] ,
157+ rawMessage : '{"args": ["my_args"]}'
158+ } ,
159+ {
160+ desc : 'should set object client args passed by run when there are no existing client.args' ,
161+ expected : { arg2 : 'fig' , arg3 : 'chocolate' } ,
162+ rawMessage : '{"args": {"arg2": "fig", "arg3": "chocolate"}}'
163+ } ,
164+ {
165+ desc : 'should overwrite empty array client.args when run passes an array for client.args' ,
166+ expected : [ 'user_arg1' ] ,
167+ rawMessage : '{"args": ["user_arg1"]}' ,
168+ existingConfig : [ ]
169+ } ,
170+ {
171+ desc : 'should overwrite empty array client.args when run passes an object for client.args' ,
172+ expected : { arg2 : 'figs' , arg3 : 'chocolates' } ,
173+ rawMessage : '{"args": {"arg2": "figs", "arg3": "chocolates"}}' ,
174+ existingConfig : [ ]
175+ } ,
176+ {
177+ desc : 'should overwrite empty object client.args when run passes an array for client.args' ,
178+ expected : [ 'user_arg' ] ,
179+ rawMessage : '{"args": ["user_arg"]}' ,
180+ existingConfig : { }
181+ } ,
182+ {
183+ desc : 'should not overwrite existing array client.args when run passes an empty array for client.args' ,
184+ expected : [ 'user_arg' ] ,
185+ rawMessage : '{"args": []}' ,
186+ existingConfig : [ 'user_arg' ]
187+ } ,
188+ {
189+ desc : 'should not overwrite existing array client.args when run passes an empty object for client.args' ,
190+ expected : [ 'user_arg' ] ,
191+ rawMessage : '{"args": {}}' ,
192+ existingConfig : [ 'user_arg' ]
193+ } ,
194+ {
195+ desc : 'should not overwrite existing array client.args when run passes no client.args' ,
196+ expected : [ 'user_arg' ] ,
197+ rawMessage : '{}' ,
198+ existingConfig : [ 'user_arg' ]
199+ } ,
200+ {
201+ desc : 'should merge existing client.args with client.args passed by run' ,
202+ expected : { arg1 : 'cherry' , arg2 : 'fig' , arg3 : 'chocolate' } ,
203+ rawMessage : '{"args": {"arg2": "fig", "arg3": "chocolate"}}' ,
204+ existingConfig : { arg1 : 'cherry' , arg2 : 'mango' }
205+ } ,
206+ {
207+ desc : 'should merge empty client.args with client.args passed by run' ,
208+ expected : { arg2 : 'fig' , arg3 : 'chocolate' } ,
209+ rawMessage : '{"args": {"arg2": "fig", "arg3": "chocolate"}}' ,
210+ existingConfig : { }
211+ }
212+ ]
213+
214+ describe ( '' , function ( ) {
215+ clientArgsRuns . forEach ( function ( run ) {
216+ it ( run . desc , ( done ) => {
217+ capturedBrowsers . add ( new Browser ( ) )
218+ sinon . stub ( capturedBrowsers , 'areAllReady' , ( ) => true )
219+ if ( run . existingConfig ) {
220+ config = _ . merge ( config , { client : { args : run . existingConfig } } )
221+ }
222+
223+ emitter . once ( 'run_start' , ( ) => {
224+ expect ( config . client . args ) . to . deep . equal ( run . expected )
225+ done ( )
226+ } )
227+
228+ var RAW_MESSAGE = run . rawMessage
229+
230+ var request = new HttpRequestMock ( '/__run__' , {
231+ 'content-type' : 'application/json' ,
232+ 'content-length' : RAW_MESSAGE . length
233+ } )
234+
235+ handler ( request , response , nextSpy )
236+
237+ request . emit ( 'data' , RAW_MESSAGE )
238+ request . emit ( 'end' )
239+ } )
161240 } )
162-
163- handler ( request , response , nextSpy )
164-
165- request . emit ( 'data' , RAW_MESSAGE )
166- request . emit ( 'end' )
167241 } )
168242
169243 it ( 'should refresh explicit files if specified' , ( done ) => {
0 commit comments