Summary
karma run calls this line lib/middleware/runner.js#L50 which overwrites the state of config.client.args with an empty array. This means that plugins that rely on config.client.args will run when calling karma start, but fail after calling karma run once (even when they are subsequently autorun from the karma start process).
Details
I'm using karma-cljs-test to run my ClojureScript tests. It needs a main function to be provided in config.client.args. I was able to run my tests successfully through the auto runner in karma start but when I called karma run, my tests would fail to run as config.client.args had been overwritten with an empty array. Because config is a mutable object, once I had called karma run once, my tests would fail when being rerun by the karma start autorunner.
Commenting out
config.client.args = data.args
let my tests pass, but this is clearly not a viable solution. One option would be to only set config.client.args if data.args is not an empty array.
This also raises the wider question of why a karma run is setting global mutable state. That behaviour was surprising to me, and I don't think it is intentional.
This behaviour seems to have been introduced in ca4c4d8, and relates to 27b8d67, #283, karma-runner/grunt-karma#79, karma-runner/grunt-karma#79, karma-runner/grunt-karma@b658ec9 and karma-runner/grunt-karma@168f7b7.
Summary
karma runcalls this line lib/middleware/runner.js#L50 which overwrites the state ofconfig.client.argswith an empty array. This means that plugins that rely onconfig.client.argswill run when callingkarma start, but fail after callingkarma runonce (even when they are subsequently autorun from thekarma startprocess).Details
I'm using karma-cljs-test to run my ClojureScript tests. It needs a main function to be provided in
config.client.args. I was able to run my tests successfully through the auto runner inkarma startbut when I calledkarma run, my tests would fail to run asconfig.client.argshad been overwritten with an empty array. Becauseconfigis a mutable object, once I had calledkarma runonce, my tests would fail when being rerun by thekarma startautorunner.Commenting out
let my tests pass, but this is clearly not a viable solution. One option would be to only set
config.client.argsifdata.argsis not an empty array.This also raises the wider question of why a
karma runis setting global mutable state. That behaviour was surprising to me, and I don't think it is intentional.This behaviour seems to have been introduced in ca4c4d8, and relates to 27b8d67, #283, karma-runner/grunt-karma#79, karma-runner/grunt-karma#79, karma-runner/grunt-karma@b658ec9 and karma-runner/grunt-karma@168f7b7.