phetsims / joist

Joist is the main framework for PhET Interactive Simulations. Joist creates and displays the simulation content, home screen, navigation bar, About dialog, enables switching between tabs, and other framework-related features.
MIT License
8 stars 6 forks source link

Easy post-load checking of namespacing #307

Closed jonathanolson closed 8 years ago

jonathanolson commented 8 years ago

As an alternative to https://github.com/phetsims/tasks/issues/435 (require.js-based) or https://github.com/phetsims/tasks/issues/431 (eslint-based) for checking the namespacing of https://github.com/phetsims/tasks/issues/378.

We had already created a debugging tool for creating these, and I've repurposed it so that if you run in require.js mode with ?ea&checkNamespaces, it will check require.js modules AFTER they all have been loaded, verifying that they exist at their expected namespace locations.

jonathanolson commented 8 years ago

Added to discuss using this as our sole namespace checking method (and enabling by default once we have all common code namespaced). This would mean bailing on https://github.com/phetsims/tasks/issues/435 (require.js-based namespace checks) and https://github.com/phetsims/tasks/issues/431 (eslint-based namespace checks).

pixelzoom commented 8 years ago

How do I test drive this? I tried:

http://localhost/~cmalley/Github/hookes-law/hookes-law_en.html?ea&checkNamespaces

... and I get this assertion failure:

screenshot_94

Is this because joist isn't namespaced yet?

samreid commented 8 years ago

Yes, it asserts that all of the requirejs modules appear in the global namespace with the appropriate name and value. It is failing on the module "checkNamespaces" which has not been namespaced.

samreid commented 8 years ago

You can negate the assert conditions and transform them to if() console.log() if you want to see a full list of offenders.

samreid commented 8 years ago

I asked @jonathanolson over skype:

Brainstorming a change (improvement?) for checkNamespaces.js. How about it first prints out all offending namespace issues in one pass before assert()ing anything?

samreid commented 8 years ago

@jonathanolson responded:

That change sounds fine to me

samreid commented 8 years ago

How about it first prints out all offending namespace issues in one pass before assert()ing anything?

I have done this on my working copy but want to test it further before committing. Tomorrow.

samreid commented 8 years ago

Fixed above. Leaving open and marked for developer-meeting for discussion of how to use this and its limitations (only checks AMD modules loaded without a plugin).

pixelzoom commented 8 years ago

Very odd that checkNamespace by itself does nothing. Why does this features require 2 query parameters? (?ea&checkNamespaces)

How about checkNamespace to get the console output without assertion failure, and add ea to enable related assertions?

samreid commented 8 years ago

Consensus: We will keep the checkNamespace option for now to help developers namespace sims, in the future we will remove ?checkNamespaces and just use ?ea to throw assertion errors if a namespacing issue occurs.

pixelzoom commented 8 years ago

Limitations: • won't confirm namespacing of inner types • there are some non-require things that need to be namespaced in scenery

We can live with these.

pixelzoom commented 8 years ago

In Skype, I proposed that it's time to enable namespace checking. Discussion:

[5/2/16, 12:54:37 PM] Chris Malley: Re turning on checkNamespace... I see lots of recent code (expression-exchange-basics, CCK, making-tens,...) that is not namespaced. Looks like developers have been generally blowing this off. Is that what we decided to do? [5/2/16, 12:56:03 PM] Chris Malley: I understand for old code, but I'm a bit disappointed for recent code. [5/2/16, 12:56:48 PM] Sam Reid: For new code I often work in phases where I tackle cross cutting concerns such as i18n and namespacing as separate step. CCK isn’t i18n’ed yet either. Flipping the switch to require namespaces will encourage me to get to that step much sooner! (and I’m OK with that) [5/2/16, 12:59:23 PM] Chris Malley: How about new sims, like Neuron? 1.0.0 published in Feb, a full 3 months after we decided to namespace. There's 1 source file that's properly namespaced. [5/2/16, 12:59:39 PM] John Blanco: Me too - it'll force me to get these things done (or delegate some of them to Aadish).

pixelzoom commented 8 years ago

Assigned to @jonathanolson to review. Then I believe this can be closed.

pixelzoom commented 8 years ago

@phet-steele FYI, here's the current state of affairs when running test-server. The majority of runnable (sims and demos) are failing with "Assertion failed: not namespaced".

screenshot_20 screenshot_21

pixelzoom commented 8 years ago

I namespaced blast, chains, griddle, graphing-quadratics, ohm-law, resistance-in-a-wire.

jonathanolson commented 8 years ago

I'll plan to tackle build-a-molecule, making-tens, pendulum-lab, wave-on-a-string.

jbphet commented 8 years ago

Neuron, Area Builder, and Arithmetic have been namespaced. The 3 sims that comprise the States of Matter suite have been assigned to @aadish, see https://github.com/phetsims/states-of-matter/issues/114. I'll tackle Balancing Act and Expression Exchange tomorrow.

jessegreenberg commented 8 years ago

I namespaced balloons-and-static-electricity, friction, estimation, and faradays-law.

samreid commented 8 years ago

I namespaced cck in the above commit.

samreid commented 8 years ago

I namespaced bending-light in the above commit.

samreid commented 8 years ago

I namespaced protein-synthesis in the above commit.

samreid commented 8 years ago

I namespaced beaker in the above commit.

samreid commented 8 years ago

I namespaced energy-skate-park-basics in the above commit.

samreid commented 8 years ago

I namespaced fluid-pressure-and-flow in the above commit.

samreid commented 8 years ago

I namespaced seasons in the above commit.

samreid commented 8 years ago

Here's the new list of what's left (17 to go):

image image image

jessegreenberg commented 8 years ago

I am going to work on gravity-and-orbits and john-travoltage next.

aadish commented 8 years ago

namespaced build an atom in above commit

jbphet commented 8 years ago

Balancing Act and Expression Exchange are now namespaced.

aadish commented 8 years ago

States of Matter, Atomic Interactions and States of Matter Basics are namespaced

jessegreenberg commented 8 years ago

john-travoltage and gravity-and-orbits have been namespaced.

phet-steele commented 8 years ago

Hey all, still left:

aadish commented 8 years ago

my bad pushed the commit for build and atom on wrong branch

jbphet commented 8 years ago

Should now be fixed for Balancing Act. I had done the same thing as @aadish, i.e. I committed the changes on a branch instead of on master.

jbphet commented 8 years ago

Marking for developer meeting so that we can discuss and assign individuals to finish the remaining sims.

jbphet commented 8 years ago

I went ahead and did projectile-motion, since I set it up initially and there isn't much to it yet.

pixelzoom commented 8 years ago

I took care of all remaining sims, with one exception. build-a-molecule has its own non-standard namespace, and will need to be converted by @jonathanolson (tracking in https://github.com/phetsims/build-a-molecule/issues/78).

pixelzoom commented 8 years ago

@phet-steele Please kick off an automated test. Verify that the only runnable that fails with "Assertion failed: not namespaced" is build-a-molecule. If verified, close this issue. Otherwise note runnable that still need attention. Thanks.

phet-steele commented 8 years ago

build-a-molecule is all that's left! Congrats! :tada: :cake: :+1: :smile:

pixelzoom commented 8 years ago

Excellent, thanks.