Skip to content

Commit

Permalink
fix(runner): Merge config.client.args with client.args provided by run
Browse files Browse the repository at this point in the history
Before this change, calling `karma run` would overwrite any value in
config.client.args with the value provided in the `karma run` request,
even if that value was an empty array. This commit does a _.merge to
merge the two values together.

Fixes karma-runner#1746
  • Loading branch information
danielcompton committed Feb 26, 2016
1 parent a751293 commit 23687cc
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
3 changes: 2 additions & 1 deletion lib/middleware/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* It basically triggers a test run and streams stdout back.
*/

var _ = require('lodash')
var path = require('path')
var helper = require('../helper')
var log = require('../logger').create()
Expand Down Expand Up @@ -48,7 +49,7 @@ var createRunnerMiddleware = function (emitter, fileList, capturedBrowsers, repo
})

log.debug('Setting client.args to ', data.args)
config.client.args = data.args
config.client.args = _.merge(config.client.args, data.args)

var fullRefresh = true

Expand Down
24 changes: 23 additions & 1 deletion test/unit/middleware/runner.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ describe('middleware.runner', () => {

nextSpy = sinon.spy()
response = new HttpResponseMock()
config = {client: {}, basePath: '/'}
config = {client: {args: ['clientArg']}, basePath: '/'}

handler = createRunnerMiddleware(
emitter,
Expand Down Expand Up @@ -166,6 +166,28 @@ describe('middleware.runner', () => {
request.emit('end')
})

it('calling run with no client args should not overwrite existing client.args', (done) => {
capturedBrowsers.add(new Browser())
sinon.stub(capturedBrowsers, 'areAllReady', () => true)

emitter.once('run_start', () => {
expect(config.client.args).to.deep.equal(['clientArg'])
done()
})

var RAW_MESSAGE = '{"args": []}'

var request = new HttpRequestMock('/__run__', {
'content-type': 'application/json',
'content-length': RAW_MESSAGE.length
})

handler(request, response, nextSpy)

request.emit('data', RAW_MESSAGE)
request.emit('end')
})

it('should refresh explicit files if specified', (done) => {
capturedBrowsers.add(new Browser())
sinon.stub(capturedBrowsers, 'areAllReady', () => true)
Expand Down

0 comments on commit 23687cc

Please sign in to comment.