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

Support and test on-demand global mode #1593

Merged
merged 3 commits into from Sep 19, 2016

Conversation

toolness
Copy link
Member

This adds support and unit tests for on-demand global mode, fixing #1570.

In particular, it fixes a bug whereby p5 would actually initialize itself twice: once when on-demand global mode was triggered via an explicit new p5(), and again when the page's load event fired (i.e., "non-on-demand global mode"). This would then cause a bunch of warnings from #1318 to be logged.

Now p5.instance is always written when _isGlobal is set, and it's checked before initializing non-on-demand global mode.

Since there weren't already tests for non-on-demand global mode, I also added some.

@@ -781,7 +781,7 @@ suite('p5.Color', function() {
});
});

suite.only('p5.Color.prototype.toString', function() {
suite('p5.Color.prototype.toString', function() {
Copy link
Member Author

Choose a reason for hiding this comment

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

Looks like this was introduced in #1463. It didn't seem to affect running tests from the command-line, but when run in-browser it'd configure mocha to only run this suite and no others.

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh, I was wrong about this not affecting tests from the command-line. It does affect tests from the command-line! In fact, f024aab broke the tests, but they didn't show up in Travis CI because of this line 😞

@toolness
Copy link
Member Author

Er... I am really confused by the test failure. As far as I can tell from looking at the source, the test that's failing should have started failing as of f024aab...

@toolness
Copy link
Member Author

Hmm, in fact, that test is failing when I run it in my browser on master, but it's not failing when run through the command-line. This is really weird!

@toolness
Copy link
Member Author

Blerg, figured it out--see #1593 (comment).

@lmccart any idea what to do about the failing test introduced in f024aab?

@limzykenneth
Copy link
Member

Was just about to say it was that commit. I think we can just fix this line in the test definition.

@toolness
Copy link
Member Author

Cool, do you think we should just change it to test if the result is an object instead of an array?

@lmccart
Copy link
Member

lmccart commented Sep 18, 2016

oops, yes we can just change that to object. I wonder why it didn't fail when I ran it. sorry about that!

@toolness
Copy link
Member Author

No worries! It didn't fail when you ran it because of the suite.only() debug call that was accidentally left in as part of #1463, I think.

Just committed a fix, so this should be ready for review!

@@ -471,6 +471,7 @@ var p5 = function(sketch, node, sync) {
// assume "global" mode and make everything global (i.e. on the window)
if (!sketch) {
this._isGlobal = true;
p5.instance = this;
Copy link
Member Author

Choose a reason for hiding this comment

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

If we want to be really friendly, we could actually add a check here to see if p5.instance is non-null, and log a friendly warning if so. Hopefully that should never happen, but it could potentially cause some hard-to-catch bugs if it ever does.

@lmccart lmccart merged commit ee2f44a into processing:master Sep 19, 2016
@lmccart
Copy link
Member

lmccart commented Sep 19, 2016

this looks all good, very helpful stuff!!

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

3 participants