-
Notifications
You must be signed in to change notification settings - Fork 64
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
Don't clobber window.console #199
Conversation
lib/_patch/browserstack.js
Outdated
@@ -38,7 +38,7 @@ | |||
} | |||
|
|||
if (typeof console !== 'object') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As this code is being run inside an IIFE, I fail to see how this conditional will ever be true
? Won't it always be undefined
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@patocallaghan i fail to understand this statement. If console
is always undefined
this conditional will always be true. And I could not find any reference to say that the console object is undefined in an IIFE. Could you also provide a sample ember test which fails. It will help me debug better.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't add that code so 🤷♂️ It appears it was added here c6c51c4 5 years ago 😄 FYI I'm running this on Node 8.9
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have these comments:
- In the browser context
window.console
andconsole
are the same object. So ifconsole
is not an objectwindow.console
wouldn't be either. So this change shouldn't really affect your tests. - If it does, I would suggest this change. All checks be made on an object
browserstack_console = console || window.console
. At the endwindow.console
andconsole
should be made equal tobrowserstack_console
. This would take into account bothconsole
andwindow.console
and then override the methods. It would make for a cleaner flow.
Also any sample ember test cases that fail?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
-
Yep, generally
window.console
andconsole
are the same in Browser-land but for some reason in this context they are not. Is there something on the Browserstack side clobberingconsole
? -
I've updated the logic to do as you say and added a
browserstack_console
variable to clean things up a bit.
Re:tests
You don't specifically need Ember tests to see this. I've added some console
method asserts to browserstack-runner/tests/behaviour/resources/qunit_test1.js
. If you revert my fix you'll see that these functions appear as undefined
in Browserstack. Screenshot below:
It looks like the failing CI is unrelated to my change. Master is also failing with the same error https://travis-ci.org/browserstack/browserstack-runner/builds/360235624
|
@patocallaghan This is helpful 👍. did you try running tests running locally? we are fixing travis failures. will get it merged once its fixed. |
@mohitmun Yes I did, with both |
@patocallaghan When running tests, it tries to retrieve browsers list from API which needs authentication. must be failing because of no credentials. try exporting browserstack credentials into you environment.
Let me know if it works |
Sorry for the silence here. I ran the tests locally with my Browserstack credentials and everything looks fine. No failing tests. |
@mohitmun any update here? |
619b4f5
to
4268931
Compare
@@ -1,4 +1,13 @@ | |||
QUnit.module('Partial Tests', function() { | |||
QUnit.test('console Tests', function(assert) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ray-pankaj I've added these assertions so you can reproduce the problem. Just revert my fixes to see console.info
fail
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In qunit_test1.js the unit tests written should have booleans
in the assertion, for instance typeof console.info === "function"
to make the spec pass, as assert.ok
expects booleans
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @ray-pankaj I've updated per your feedback. For some reason I can't seem to test the full suite locally though. When I run npm run test-behaviour
I get the following error for some of the tests:
Uncaught AssertionError [ERR_ASSERTION]: 'Error: BrowserStackLocal failed to launch within 30 seconds.' == null
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ran tests locally. All pass. Merging now.
4268931
to
0d4b0b3
Compare
0d4b0b3
to
ad0a2e6
Compare
Thanks @ray-pankaj 🙇 Any idea when we'll see a release with the patch? |
Since upgrading a JS framework (Ember 3.x) we use, Browserstack has failed to run our tests correctly, throwing exceptions and causing test failures.
Internally the framework relies on the presence of
window.console.info
andwindow.console.debug
but Browserstack clobberswindow.console
and only re-implementsconsole.log
andconsole.warn
.This change means we will always have all
window.console
methods, butconsole.warn
andconsole.log
are still overridden for the runner's purposes.