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): allow updating total specs count #3264

Merged
merged 3 commits into from Feb 13, 2019

Conversation

matz3
Copy link
Contributor

@matz3 matz3 commented Feb 13, 2019

This change allows providing the total specs count after the tests have
been started.
The count will be updated in case it has been provided already.
This can be uselful for some adapters where the total specs count can
not be determined before starting the first test.

Regarding tests
I wanted to update the tests and/or create a test case but the onInfo tests are not clear to me:

  • 'browser_dump' doesn't seem to be a valid event
  • I'm not sure whether the behavior of the tests is really expected or just works by chance.

So I would be happy to get feedback from you before writing a test case.

describe('onInfo', () => {
beforeEach(() => {
browser = new Browser('fake-id', 'full name', collection, emitter, socket)
})
it('should emit "browser_log"', () => {
const spy = sinon.spy()
emitter.on('browser_log', spy)
browser.state = Browser.STATE_EXECUTING
browser.onInfo({log: 'something', type: 'info'})
expect(spy).to.have.been.calledWith(browser, 'something', 'info')
})
it('should emit "browser_info"', () => {
const spy = sinon.spy()
const infoData = {}
emitter.on('browser_info', spy)
browser.state = Browser.STATE_EXECUTING
browser.onInfo(infoData)
expect(spy).to.have.been.calledWith(browser, infoData)
})
it('should ignore if browser not executing', () => {
const spy = sinon.spy()
emitter.on('browser_dump', spy)
browser.state = Browser.STATE_CONNECTED
browser.onInfo({dump: 'something'})
browser.onInfo({total: 20})
expect(browser.lastResult.total).to.equal(0)
expect(spy).not.to.have.been.called
})
})

This change allows providing the total specs count after the tests have
been started.
The count will be updated in case it has been provided already.
This can be uselful for some adapters where the total specs count can
not be determined before starting the first test.
@johnjbarton
Copy link
Contributor

  • 'browser_dump' doesn't seem to be a valid event

I guess the test is attempting to cover:
https://github.com/karma-runner/karma/blob/master/lib/browser.js#L63

However it tests something "not happening" and many things do not happen when code is changed. Maybe the event was originally browser_dump and was renamed, but the test was not corrected. Please correct it if you can.

lib/browser.js Outdated
@@ -60,6 +60,8 @@ class Browser {

if (helper.isDefined(info.log)) {
this.emitter.emit('browser_log', this, info.log, info.type)
} else if (helper.isDefined(info.total)) {
this.lastResult.total = info.total
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you guard the update to results with state EXECUTING then the tests will pass. You can add a similar test with mock state EXECUTING to verify the change.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In order to fix the test should ignore if browser not executing I would suggest to wrap all those if-clauses with a check for state EXECUTING.
Should this.refreshNoActivityTimeout() be still called then?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should log events in any state, they could be error messages for corner cases. So remove the line in the test that checks the .dump path.

The this.refreshNoActivityTimeout() should always be called, it signals that the browser is still on the line.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense. I've pushed my changes.

@johnjbarton
Copy link
Contributor

Thanks!

@johnjbarton johnjbarton merged commit d5df723 into karma-runner:master Feb 13, 2019
@matz3
Copy link
Contributor Author

matz3 commented Feb 14, 2019

Thanks for the quick handling 👍

@matz3 matz3 deleted the fix-update-total-spec-count branch February 14, 2019 08:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants