diff --git a/lib/middleware/runner.js b/lib/middleware/runner.js index 7c0d13dbc..465fe54df 100644 --- a/lib/middleware/runner.js +++ b/lib/middleware/runner.js @@ -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() @@ -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 = _.merge(config, {client: {args: data.args}}) var fullRefresh = true diff --git a/test/unit/middleware/runner.spec.js b/test/unit/middleware/runner.spec.js index 8e7228aba..db8eb87ec 100644 --- a/test/unit/middleware/runner.spec.js +++ b/test/unit/middleware/runner.spec.js @@ -5,6 +5,7 @@ import {Promise} from 'bluebird' import Browser from '../../../lib/browser' import BrowserCollection from '../../../lib/browser_collection' import MultReporter from '../../../lib/reporters/multi' +var _ = require('lodash') var createRunnerMiddleware = require('../../../lib/middleware/runner').create var HttpResponseMock = mocks.http.ServerResponse var HttpRequestMock = mocks.http.ServerRequest @@ -166,6 +167,97 @@ describe('middleware.runner', () => { request.emit('end') }) + it('should not overwrite existing client.args when run passes an empty array for client.args', (done) => { + capturedBrowsers.add(new Browser()) + sinon.stub(capturedBrowsers, 'areAllReady', () => true) + config = _.merge(config, {client: {args: ['clientArg']}}) + + 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 not overwrite existing client.args when run passes no client.args', (done) => { + capturedBrowsers.add(new Browser()) + sinon.stub(capturedBrowsers, 'areAllReady', () => true) + config = _.merge(config, {client: {args: ['clientArg']}}) + + emitter.once('run_start', () => { + expect(config.client.args).to.deep.equal(['clientArg']) + done() + }) + + var RAW_MESSAGE = '{}' + + 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 merge existing client.args with client.args passed by run', (done) => { + capturedBrowsers.add(new Browser()) + sinon.stub(capturedBrowsers, 'areAllReady', () => true) + config = _.merge(config, {client: {args: {arg1: 'cherry', arg2: 'mango'}}}) + + emitter.once('run_start', () => { + expect(config.client.args).to.deep.equal({arg1: 'cherry', arg2: 'fig', arg3: 'chocolate'}) + done() + }) + + var RAW_MESSAGE = '{"args": {"arg2": "fig", "arg3": "chocolate"}}' + + 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 set client args passed by run when there are no existing client.args', (done) => { + capturedBrowsers.add(new Browser()) + sinon.stub(capturedBrowsers, 'areAllReady', () => true) + + emitter.once('run_start', () => { + expect(config.client.args).to.deep.equal({arg2: 'fig', arg3: 'chocolate'}) + done() + }) + + var RAW_MESSAGE = '{"args": {"arg2": "fig", "arg3": "chocolate"}}' + + 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)