Skip to content

Commit 30ff73b

Browse files
authoredNov 15, 2018
fix(browser): report errors to console during singleRun=false (#3209)
Fixes #3131
1 parent 5334d1a commit 30ff73b

File tree

5 files changed

+80
-19
lines changed

5 files changed

+80
-19
lines changed
 

‎lib/browser.js

+11-13
Original file line numberDiff line numberDiff line change
@@ -48,25 +48,23 @@ class Browser {
4848
onKarmaError (error) {
4949
if (this.isNotConnected()) {
5050
this.lastResult.error = true
51-
this.emitter.emit('browser_error', this, error)
52-
this.refreshNoActivityTimeout()
5351
}
52+
this.emitter.emit('browser_error', this, error)
53+
this.refreshNoActivityTimeout()
5454
}
5555

5656
onInfo (info) {
57-
if (this.isNotConnected()) {
58-
if (helper.isDefined(info.dump)) {
59-
this.emitter.emit('browser_log', this, info.dump, 'dump')
60-
}
61-
62-
if (helper.isDefined(info.log)) {
63-
this.emitter.emit('browser_log', this, info.log, info.type)
64-
} else if (!helper.isDefined(info.dump)) {
65-
this.emitter.emit('browser_info', this, info)
66-
}
57+
if (helper.isDefined(info.dump)) {
58+
this.emitter.emit('browser_log', this, info.dump, 'dump')
59+
}
6760

68-
this.refreshNoActivityTimeout()
61+
if (helper.isDefined(info.log)) {
62+
this.emitter.emit('browser_log', this, info.log, info.type)
63+
} else if (!helper.isDefined(info.dump)) {
64+
this.emitter.emit('browser_info', this, info)
6965
}
66+
67+
this.refreshNoActivityTimeout()
7068
}
7169

7270
onStart (info) {

‎test/e2e/browser_console.feature

+36
Original file line numberDiff line numberDiff line change
@@ -172,3 +172,39 @@ Feature: Browser Console Configuration
172172
.
173173
HeadlessChrome
174174
"""
175+
Scenario: Execute logging program with singleRun
176+
Given a configuration with:
177+
"""
178+
files = ['browser-console/log.js', 'browser-console/test.js'];
179+
browsers = ['ChromeHeadlessNoSandbox'];
180+
plugins = [
181+
'karma-jasmine',
182+
'karma-chrome-launcher'
183+
];
184+
singleRun = false;
185+
"""
186+
When I runOut Karma
187+
Then it passes with like:
188+
"""
189+
LOG: 'foo'
190+
"""
191+
Then it passes with like:
192+
"""
193+
DEBUG: 'bar'
194+
"""
195+
Then it passes with like:
196+
"""
197+
INFO: 'baz'
198+
"""
199+
Then it passes with like:
200+
"""
201+
WARN: 'foobar'
202+
"""
203+
Then it passes with like:
204+
"""
205+
ERROR: 'barbaz'
206+
"""
207+
Then it passes with like:
208+
"""
209+
SUCCESS
210+
"""

‎test/e2e/error.feature

+18
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,21 @@ Feature: Error Display
1818
"""
1919
SyntaxError: Unexpected token }
2020
"""
21+
Scenario: Single-run Syntax Error in a test file
22+
Given a configuration with:
23+
"""
24+
files = ['error/test.js', 'error/under-test.js'];
25+
browsers = ['ChromeHeadlessNoSandbox'];
26+
plugins = [
27+
'karma-jasmine',
28+
'karma-chrome-launcher'
29+
];
30+
singleRun = false;
31+
"""
32+
When I monitor Karma
33+
And I stop when the log contains 'SyntaxError'
34+
Then it fails with like:
35+
"""
36+
SyntaxError: Unexpected token }
37+
"""
38+
And I stop a server programmatically

‎test/e2e/step_definitions/core_steps.js

+14-2
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ cucumber.defineSupportCode((a) => {
6464
}
6565

6666
const runOut = command === 'runOut'
67-
if (command === 'run' || command === 'runOut') {
67+
if (command === 'run' || command === 'runOut' || command === 'monitor') {
6868
this.child = spawn('' + runtimePath, ['start', '--log-level', 'warn', configFile])
6969
const done = () => {
7070
cleansingNeeded = true
@@ -96,6 +96,9 @@ cucumber.defineSupportCode((a) => {
9696
}
9797
done()
9898
})
99+
if (command === 'monitor') {
100+
done()
101+
}
99102
}, 1000)
100103
})
101104
} else {
@@ -157,7 +160,7 @@ cucumber.defineSupportCode((a) => {
157160

158161
defineParameterType({
159162
name: 'command',
160-
regexp: /run|runOut|start|init|stop/
163+
regexp: /run|runOut|start|init|stop|monitor/
161164
})
162165

163166
defineParameterType({
@@ -177,6 +180,15 @@ cucumber.defineSupportCode((a) => {
177180
execKarma.apply(this, [command, undefined, proxyPort, proxyPath, callback])
178181
})
179182

183+
When('I stop when the log contains {string}', function (message, callback) {
184+
setInterval(() => {
185+
if (this.lastRun.stdout.includes(message)) {
186+
this.child && this.child.kill()
187+
callback()
188+
}
189+
}, 100)
190+
})
191+
180192
defineParameterType({
181193
name: 'exact',
182194
regexp: /no\sdebug|like/

‎test/unit/browser.spec.js

+1-4
Original file line numberDiff line numberDiff line change
@@ -91,14 +91,11 @@ describe('Browser', () => {
9191
expect(spy).to.have.been.called
9292
})
9393

94-
it('should ignore if browser not executing', () => {
95-
const spy = sinon.spy()
96-
emitter.on('browser_error', spy)
94+
it('should not set lastResult if browser not executing', () => {
9795
browser.state = Browser.STATE_CONNECTED
9896

9997
browser.onKarmaError()
10098
expect(browser.lastResult.error).to.equal(false)
101-
expect(spy).not.to.have.been.called
10299
})
103100
})
104101

0 commit comments

Comments
 (0)
Please sign in to comment.