Skip to content

Core: Optimize utilization of global and window variables#813

Closed
leobalter wants to merge 5 commits into
qunitjs:masterfrom
leobalter:node-global
Closed

Core: Optimize utilization of global and window variables#813
leobalter wants to merge 5 commits into
qunitjs:masterfrom
leobalter:node-global

Conversation

@leobalter

Copy link
Copy Markdown
Member

Ref #790

QUnit was found exported to the global object on Node environment.

This PR also removes QUnit.diff and QUnit.init functions on Node, they were always browser functions.

This might look as a breaking change, so we should also discuss if this if good to land only on 2.0 or maybe I could set a stub function for them printing a warning about their usage on non-browser envs, which is not functional.

Comment thread src/export.js Outdated

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

this is the most precise check I've got, we might want to simplify if to just check window.document.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This seems like the wrong approach. We shouldn't alias global to window in the first place.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

It is different now and window is now renamed to global.

@leobalter

Copy link
Copy Markdown
Member Author

I also want to land another commit here in this PR renaming window to global to avoid this kind of confusion.

Comment thread src/diff.js Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I get why we exclude the HTML reporter in node, but how does this make a difference?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

when QUnit is not exposed as a global value anymore, the following QUnit.difff line would fail.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I see. I guess with ES6 modules this problem could go away? If so, let's extend the comment a bit and leave the if as-is.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I've change the if to check this and also extended it to check if window has truth document property (avoiding Node apps with a window variable on the global).

@leobalter leobalter changed the title Build: Remove unintended QUnit global export on Node Core: Optimize utilization of global and window variables Aug 11, 2015
@leobalter

Copy link
Copy Markdown
Member Author

@jzaefferer after a hard rebasing, I've fixed this branch with some more optimizations.

The commits will be squashed using this (new) PR title.

Comment thread src/diff.js Outdated

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This is wrong. It took me a while to understand the purpose. I'll remove this.

@jzaefferer

Copy link
Copy Markdown
Member

A few small issues left to address, overall looking good.

Comment thread src/core/utilities.js Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This block runs on every env and global is set to avoid errors on node.

Can you add a comment for that?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

0bba6d5

updated to 1f91270 after rebase

@leobalter

Copy link
Copy Markdown
Member Author

I rebased this branch with master and now it's crashing on the amd tests, I'll check and fix.

@leobalter

Copy link
Copy Markdown
Member Author

Realized the error was on my machine only with a missing node module.

@jzaefferer

Copy link
Copy Markdown
Member

Looks good to land.

@leobalter leobalter closed this in 16d16ba Aug 16, 2015
@leobalter

Copy link
Copy Markdown
Member Author

thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants