Skip to content

'console' is undefined with Qunit in IE 9 #212

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

Closed
carhartl opened this issue Jan 2, 2019 · 2 comments · Fixed by #241
Closed

'console' is undefined with Qunit in IE 9 #212

carhartl opened this issue Jan 2, 2019 · 2 comments · Fixed by #241

Comments

@carhartl
Copy link

carhartl commented Jan 2, 2019

Expected Behavior

QUnit test suite with 1 simple test passes successfully.

Actual Behavior

QUnit test suite with 1 simple test fails with global failure due to error `'console' is undefined (see screenshot).

Steps to Reproduce the Problem

  1. single test suite index.html
<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>Test Suite</title>
		<link href="node_modules/qunitjs/qunit/qunit.css" rel="stylesheet">
		<script src="node_modules/qunitjs/qunit/qunit.js"></script>
		<script>
			QUnit.test('simple value', function (assert) {
				assert.expect(1);
				assert.strictEqual(true, true, 'testing...');
			});
		</script>
	</head>
	<body>
		<div id="qunit"></div>
		<div id="qunit-fixture"></div>
	</body>
</html>
  1. browserstack config:
{
    "test_framework" : "qunit",
    "test_path": [
        "index.html"
    ],
    "exit_with_fail": true,
    "browsers": [
        "ie_9"
    ]
}
  1. Execute node_modules/.bin/browserstack-runner

Platform details

  1. browserstack-runner version: 0.9.0
  2. node version: v11.6.0
  3. os type and version: OSX Mojave 10.14.2

Details

See screenshot:

screenshot 2019-01-02 at 19 22 54

The error points to:

var browserstack_console = console || window.console || {};

If I remember IE pecularities correctly this might be because you cannot do var x = foo || ... when foo has never been set up before, i.e. is very much indeed undefined. A test like typeof foo == 'undefined' might work better/be needed. This could be IE 6-8 knowledge though.

PS: also, the runner will just hang until it times out...

Launching 1 worker(s) for 1 run(s).
[Windows 7, Internet Explorer 9.0] Launching
[Windows 7, Internet Explorer 9.0] Received ack
[Windows 7, Internet Explorer 9.0] Launched
[Windows 7, Internet Explorer 9.0] Awaiting ack
@carhartl
Copy link
Author

carhartl commented Jan 2, 2019

https://stackoverflow.com/a/14714140

Secondly, I learned that console is only available in IE 9 if developer tools are open.

@carhartl
Copy link
Author

carhartl commented Jan 2, 2019

Using https://github.com/paulmillr/console-polyfill I can workaround this problem...

Krinkle added a commit to Krinkle/browserstack-runner that referenced this issue Apr 11, 2021
Follows-up 826d2c7.

Before that commit, the reason global "console" was globbered is that the
`var console` part of the inner `var console = {}` assignment was hosted by
the JavaScript engine. Thus the variable always existed in the local scope as
type "undefined", and so the conditional check never saw the real console, and
always created a custom one. Thus it always deleted the original console reference,
as well as any other it contained.

In commit 826d2c7, this was incorrectly fixed by assigning the unchecked
expression referring to `console`, thus no longer having a fallback to `{}` in older
browsers, because an unchecked reference like that throws an Uncaught ReferenceError.

As a result, browserstack-runner was unable to run in IE 9 or older.

Fixes browserstack#161.
Fixes browserstack#164.
Fixes browserstack#212.
Krinkle added a commit to qunitjs/browserstack-runner that referenced this issue Apr 11, 2021
Follows-up 826d2c7.

Before that commit, the reason global "console" was globbered is that the
`var console` part of the inner `var console = {}` assignment was hosted by
the JavaScript engine. Thus the variable always existed in the local scope as
type "undefined", and so the conditional check never saw the real console, and
always created a custom one. Thus it always deleted the original console reference,
as well as any other it contained.

In commit 826d2c7, this was incorrectly fixed by assigning the unchecked
expression referring to `console`, thus no longer having a fallback to `{}` in older
browsers, because an unchecked reference like that throws an Uncaught ReferenceError.

As a result, browserstack-runner was unable to run in IE 9 or older.

Fixes browserstack#161.
Fixes browserstack#164.
Fixes browserstack#212.
Ref browserstack#241.
francisf pushed a commit that referenced this issue Apr 21, 2021
Follows-up 826d2c7.

Before that commit, the reason global "console" was globbered is that the
`var console` part of the inner `var console = {}` assignment was hosted by
the JavaScript engine. Thus the variable always existed in the local scope as
type "undefined", and so the conditional check never saw the real console, and
always created a custom one. Thus it always deleted the original console reference,
as well as any other it contained.

In commit 826d2c7, this was incorrectly fixed by assigning the unchecked
expression referring to `console`, thus no longer having a fallback to `{}` in older
browsers, because an unchecked reference like that throws an Uncaught ReferenceError.

As a result, browserstack-runner was unable to run in IE 9 or older.

Fixes #161.
Fixes #164.
Fixes #212.
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 a pull request may close this issue.

1 participant