Skip to content

Commit

Permalink
feat(config): add restartOnFileChange option
Browse files Browse the repository at this point in the history
When autoWatch=true and restartOnFileChange=true, this will "complete"
the current run immediately then schedule a new one as before. This is
most useful in gulp/grunt/etc. tasks that auto-build/test/reload to reduce
the time-to-feedback when making many changes in quick succession.
  • Loading branch information
Derek Gould committed Sep 24, 2015
1 parent 65080f5 commit 1082f35
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 0 deletions.
3 changes: 3 additions & 0 deletions client/karma.js
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,9 @@ var Karma = function (socket, iframe, opener, navigator, location) {
window.console.clear()
}
})
socket.on('stop', function () {
this.complete()
}.bind(this))

// report browser name, id
socket.on('connect', function () {
Expand Down
8 changes: 8 additions & 0 deletions docs/config/01-configuration-file.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,14 @@ multiple changes into a single run so that the test runner doesn't try to start
tests more than it should. The configuration setting tells Karma how long to wait (in milliseconds) after any changes
have occurred before starting the test process again.

## restartOnFileChange
**Type:** Boolean

**Default:** `false`

**Description:** When Karma is watching the files for changes, it will delay a new run until
the current run is finished. Enabling this setting will cancel the current run and start a new run
immediately when a change is detected.

## basePath
**Type:** String
Expand Down
1 change: 1 addition & 0 deletions lib/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@ var Config = function () {
this.colors = true
this.autoWatch = true
this.autoWatchBatchDelay = 250
this.restartOnFileChange = false
this.usePolling = process.platform === 'darwin' || process.platform === 'linux'
this.reporters = ['progress']
this.singleRun = false
Expand Down
3 changes: 3 additions & 0 deletions lib/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,9 @@ Server.prototype._start = function (config, launcher, preprocess, fileList, webS
if (config.autoWatch) {
self.on('file_list_modified', function () {
self.log.debug('List of files has changed, trying to execute')
if (config.restartOnFileChange) {
socketServer.sockets.emit('stop')
}
executor.schedule()
})
}
Expand Down
6 changes: 6 additions & 0 deletions test/client/karma.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@ describe('Karma', function () {
expect(windowStub).to.have.been.calledWith('about:blank')
})

it('should stop execution', function () {
sinon.spy(k, 'complete')
socket.emit('stop')
expect(k.complete).to.have.been.called
})

it('should not start execution if any error during loading files', function () {
k.error('syntax error', '/some/file.js', 11)
k.loaded()
Expand Down

0 comments on commit 1082f35

Please sign in to comment.