Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(runner): Merge config.client.args with client.args provided by run #1934

Merged
merged 1 commit into from
Jun 23, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions 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 @@ -47,8 +48,16 @@ var createRunnerMiddleware = function (emitter, fileList, capturedBrowsers, repo
})
})

log.debug('Setting client.args to ', data.args)
config.client.args = data.args
if (_.isEmpty(data.args)) {
log.debug('Ignoring empty client.args from run command')
} else if ((_.isArray(data.args) && _.isArray(config.client.args)) ||
(_.isPlainObject(data.args) && _.isPlainObject(config.client.args))) {
log.debug('Merging client.args with ', data.args)
config.client.args = _.merge(config.client.args, data.args)
} else {
log.warn('Replacing client.args with ', data.args, ' as their types do not match.')
config.client.args = data.args
}

var fullRefresh = true

Expand Down
112 changes: 93 additions & 19 deletions test/unit/middleware/runner.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -144,26 +145,99 @@ describe('middleware.runner', () => {
handler(new HttpRequestMock('/__run__'), response, nextSpy)
})

it('should parse body and set client.args', (done) => {
capturedBrowsers.add(new Browser())
sinon.stub(capturedBrowsers, 'areAllReady', () => true)

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

var RAW_MESSAGE = '{"args": ["arg1", "arg2"]}'

var request = new HttpRequestMock('/__run__', {
'content-type': 'application/json',
'content-length': RAW_MESSAGE.length
var clientArgsRuns = [
{
desc: 'should parse body and set client.args',
expected: ['arg1', 'arg2'],
rawMessage: '{"args": ["arg1", "arg2"]}'
},
{
desc: 'should set array client args passed by run when there are no existing client.args',
expected: ['my_args'],
rawMessage: '{"args": ["my_args"]}'
},
{
desc: 'should set object client args passed by run when there are no existing client.args',
expected: {arg2: 'fig', arg3: 'chocolate'},
rawMessage: '{"args": {"arg2": "fig", "arg3": "chocolate"}}'
},
{
desc: 'should overwrite empty array client.args when run passes an array for client.args',
expected: ['user_arg1'],
rawMessage: '{"args": ["user_arg1"]}',
existingConfig: []
},
{
desc: 'should overwrite empty array client.args when run passes an object for client.args',
expected: {arg2: 'figs', arg3: 'chocolates'},
rawMessage: '{"args": {"arg2": "figs", "arg3": "chocolates"}}',
existingConfig: []
},
{
desc: 'should overwrite empty object client.args when run passes an array for client.args',
expected: ['user_arg'],
rawMessage: '{"args": ["user_arg"]}',
existingConfig: {}
},
{
desc: 'should not overwrite existing array client.args when run passes an empty array for client.args',
expected: ['user_arg'],
rawMessage: '{"args": []}',
existingConfig: ['user_arg']
},
{
desc: 'should not overwrite existing array client.args when run passes an empty object for client.args',
expected: ['user_arg'],
rawMessage: '{"args": {}}',
existingConfig: ['user_arg']
},
{
desc: 'should not overwrite existing array client.args when run passes no client.args',
expected: ['user_arg'],
rawMessage: '{}',
existingConfig: ['user_arg']
},
{
desc: 'should merge existing client.args with client.args passed by run',
expected: {arg1: 'cherry', arg2: 'fig', arg3: 'chocolate'},
rawMessage: '{"args": {"arg2": "fig", "arg3": "chocolate"}}',
existingConfig: {arg1: 'cherry', arg2: 'mango'}
},
{
desc: 'should merge empty client.args with client.args passed by run',
expected: {arg2: 'fig', arg3: 'chocolate'},
rawMessage: '{"args": {"arg2": "fig", "arg3": "chocolate"}}',
existingConfig: {}
}
]

describe('', function () {
clientArgsRuns.forEach(function (run) {
it(run.desc, (done) => {
capturedBrowsers.add(new Browser())
sinon.stub(capturedBrowsers, 'areAllReady', () => true)
if (run.existingConfig) {
config = _.merge(config, {client: {args: run.existingConfig}})
}

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

var RAW_MESSAGE = run.rawMessage

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')
})
})

handler(request, response, nextSpy)

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

it('should refresh explicit files if specified', (done) => {
Expand Down