🌐 AI搜索 & 代理 主页
Skip to content

Commit 40b7de6

Browse files
Merge pull request #1592 from drgould/feature-restartOnFileChange
feat(config): add restartOnFileChange option
2 parents 60975de + 1082f35 commit 40b7de6

File tree

5 files changed

+21
-0
lines changed

5 files changed

+21
-0
lines changed

client/karma.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,9 @@ var Karma = function (socket, iframe, opener, navigator, location) {
220220
window.console.clear()
221221
}
222222
})
223+
socket.on('stop', function () {
224+
this.complete()
225+
}.bind(this))
223226

224227
// report browser name, id
225228
socket.on('connect', function () {

docs/config/01-configuration-file.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,14 @@ multiple changes into a single run so that the test runner doesn't try to start
6969
tests more than it should. The configuration setting tells Karma how long to wait (in milliseconds) after any changes
7070
have occurred before starting the test process again.
7171

72+
## restartOnFileChange
73+
**Type:** Boolean
74+
75+
**Default:** `false`
76+
77+
**Description:** When Karma is watching the files for changes, it will delay a new run until
78+
the current run is finished. Enabling this setting will cancel the current run and start a new run
79+
immediately when a change is detected.
7280

7381
## basePath
7482
**Type:** String

lib/config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,7 @@ var Config = function () {
236236
this.colors = true
237237
this.autoWatch = true
238238
this.autoWatchBatchDelay = 250
239+
this.restartOnFileChange = false
239240
this.usePolling = process.platform === 'darwin' || process.platform === 'linux'
240241
this.reporters = ['progress']
241242
this.singleRun = false

lib/server.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,9 @@ Server.prototype._start = function (config, launcher, preprocess, fileList, webS
297297
if (config.autoWatch) {
298298
self.on('file_list_modified', function () {
299299
self.log.debug('List of files has changed, trying to execute')
300+
if (config.restartOnFileChange) {
301+
socketServer.sockets.emit('stop')
302+
}
300303
executor.schedule()
301304
})
302305
}

test/client/karma.spec.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,12 @@ describe('Karma', function () {
4949
expect(windowStub).to.have.been.calledWith('about:blank')
5050
})
5151

52+
it('should stop execution', function () {
53+
sinon.spy(k, 'complete')
54+
socket.emit('stop')
55+
expect(k.complete).to.have.been.called
56+
})
57+
5258
it('should not start execution if any error during loading files', function () {
5359
k.error('syntax error', '/some/file.js', 11)
5460
k.loaded()

0 commit comments

Comments
 (0)