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(browser): report errors to console during singleRun=false #3209

Merged
merged 1 commit into from
Nov 15, 2018
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
24 changes: 11 additions & 13 deletions lib/browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,25 +48,23 @@ class Browser {
onKarmaError (error) {
if (this.isNotConnected()) {
this.lastResult.error = true
this.emitter.emit('browser_error', this, error)
this.refreshNoActivityTimeout()
}
this.emitter.emit('browser_error', this, error)
this.refreshNoActivityTimeout()
}

onInfo (info) {
if (this.isNotConnected()) {
if (helper.isDefined(info.dump)) {
this.emitter.emit('browser_log', this, info.dump, 'dump')
}

if (helper.isDefined(info.log)) {
this.emitter.emit('browser_log', this, info.log, info.type)
} else if (!helper.isDefined(info.dump)) {
this.emitter.emit('browser_info', this, info)
}
if (helper.isDefined(info.dump)) {
this.emitter.emit('browser_log', this, info.dump, 'dump')
}

this.refreshNoActivityTimeout()
if (helper.isDefined(info.log)) {
this.emitter.emit('browser_log', this, info.log, info.type)
} else if (!helper.isDefined(info.dump)) {
this.emitter.emit('browser_info', this, info)
}

this.refreshNoActivityTimeout()
}

onStart (info) {
Expand Down
36 changes: 36 additions & 0 deletions test/e2e/browser_console.feature
Original file line number Diff line number Diff line change
Expand Up @@ -172,3 +172,39 @@ Feature: Browser Console Configuration
.
HeadlessChrome
"""
Scenario: Execute logging program with singleRun
Given a configuration with:
"""
files = ['browser-console/log.js', 'browser-console/test.js'];
browsers = ['ChromeHeadlessNoSandbox'];
plugins = [
'karma-jasmine',
'karma-chrome-launcher'
];
singleRun = false;
"""
When I runOut Karma
Then it passes with like:
"""
LOG: 'foo'
"""
Then it passes with like:
"""
DEBUG: 'bar'
"""
Then it passes with like:
"""
INFO: 'baz'
"""
Then it passes with like:
"""
WARN: 'foobar'
"""
Then it passes with like:
"""
ERROR: 'barbaz'
"""
Then it passes with like:
"""
SUCCESS
"""
18 changes: 18 additions & 0 deletions test/e2e/error.feature
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,21 @@ Feature: Error Display
"""
SyntaxError: Unexpected token }
"""
Scenario: Single-run Syntax Error in a test file
Given a configuration with:
"""
files = ['error/test.js', 'error/under-test.js'];
browsers = ['ChromeHeadlessNoSandbox'];
plugins = [
'karma-jasmine',
'karma-chrome-launcher'
];
singleRun = false;
"""
When I monitor Karma
And I stop when the log contains 'SyntaxError'
Then it fails with like:
"""
SyntaxError: Unexpected token }
"""
And I stop a server programmatically
16 changes: 14 additions & 2 deletions test/e2e/step_definitions/core_steps.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ cucumber.defineSupportCode((a) => {
}

const runOut = command === 'runOut'
if (command === 'run' || command === 'runOut') {
if (command === 'run' || command === 'runOut' || command === 'monitor') {
this.child = spawn('' + runtimePath, ['start', '--log-level', 'warn', configFile])
const done = () => {
cleansingNeeded = true
Expand Down Expand Up @@ -96,6 +96,9 @@ cucumber.defineSupportCode((a) => {
}
done()
})
if (command === 'monitor') {
done()
}
}, 1000)
})
} else {
Expand Down Expand Up @@ -157,7 +160,7 @@ cucumber.defineSupportCode((a) => {

defineParameterType({
name: 'command',
regexp: /run|runOut|start|init|stop/
regexp: /run|runOut|start|init|stop|monitor/
})

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

When('I stop when the log contains {string}', function (message, callback) {
setInterval(() => {
if (this.lastRun.stdout.includes(message)) {
this.child && this.child.kill()
callback()
}
}, 100)
})

defineParameterType({
name: 'exact',
regexp: /no\sdebug|like/
Expand Down
5 changes: 1 addition & 4 deletions test/unit/browser.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,14 +91,11 @@ describe('Browser', () => {
expect(spy).to.have.been.called
})

it('should ignore if browser not executing', () => {
const spy = sinon.spy()
emitter.on('browser_error', spy)
it('should not set lastResult if browser not executing', () => {
browser.state = Browser.STATE_CONNECTED

browser.onKarmaError()
expect(browser.lastResult.error).to.equal(false)
expect(spy).not.to.have.been.called
})
})

Expand Down