-
Notifications
You must be signed in to change notification settings - Fork 70
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
GH-32 - Use iteration to populate dust.helpers #64
Conversation
Could you please explain what is specRunner2.js and how it's different from specRunner? |
I can. It's a bit hard to pick up. The server specRunners are almost identical and the difference is very subtle. The main difference is the in the order of the assignment statements. In specRunner it goes dust->dust.helpers->dust.helpers.tapper, whereas in specRunner2 it goes dust->dust.helpers.tapper->dust.helpers. Both specRunners run the same battery of tests and thus should produce consistent results. However without the fix in dust-helpers.js, specRunner will pass all tests but specRunner2 will not because dust.helpers.tapper gets clobbered inside dust-helpers.js. In summary, specRunner2.js simulates the assignment order @rragan described in the ticket I referenced.
|
Thanks for the explanation. I feel that updating existing spec runner with new order of require statements should be sufficient. We probably do not need a separate spec runner just to test this. The change to dust-helpers.js file looks good to me. |
Yeah, it was admittedly overkill. I cleaned it up. |
Client side spec runner has changed when we switched to grunt build. It is now auto generated. You'll need to do git pull to get latest changes. Your changes to server side spec runner still apply. Take a look at the jasmine task config in gruntfile.js on line 85. You'll need to play with the order of files in config. If you want to see the generated spec runner - change keepRunner option in config to true. Next time you run Also, is adding LAB.src.js absolutely necessary? If so, I would rather add it as a proper node dependency into package.json and reference from node_modules folder instead of checking in into the project. |
I'll take a look at this when I get the chance. LAB.src.js is there for the same reason the previously removed server-side specrunner duplicate - to enforce a specific script-loading order that creates an error. I do agree about using a proper node dependency, but I couldn't find it in the npm repository. That said, I think we can just revert the client-side spec runner like you suggested for the server-side. It is kind of overkill. |
Hi Kate. Per your suggestion, I removed the old client specrunner and the LAB.src.js file. If you have any other suggestions, please let me know. |
} | ||
|
||
//Get unit test specs | ||
dust.helpers.tapper = function(chunk, context, bodies, params) { |
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.
dust.helpers.tapper was moved to testUtils
so it's easier to maintain in across Phantom, Rhino and Node tests.
Instead of adding tapper helper back here you can simply do
//This should be declared global in order to access them in the spec
dust = require('dustjs-linkedin');
require("../../../test/testUtils");
require("../../../lib/dust-helpers");
//Get unit test specs
helpersTests = require('../spec/helpersTests');
This order should test your use case.
Can you also squash the commits? We'll be ready to pull in your change after this update
1. LinkedInAtticGH-32 - populate dust.helpers using iteration 37d3b84 in lib/dust-helpers.js force a failing script loading order by reworking existing specRunners - server - sandwich dust.helpers.tapper assignment between dust and dust.helpers assignment - client - use LABjs to force a specific script-loading order to achieve equivalent effect as the server 2. mv specRunner2.js specRunner.js 28233cf 3. remove client spec runner 6b1b3ba it's now autogenerated from grunt build + enforcing a specific script load order seems like overkill 4. import testUtils bde96fe
…dInAttic#64 'Use iteration to populate dust.helpers'
…dInAttic#64 'Use iteration to populate dust.helpers'
This was resolved with #73. Closing this pull request. Please re-open if you think I've missed anything. |
GH-32 - Instead of overwriting dust.helpers in the module, use iteration to populate the header methods. This should be fine because dustjs <--dependsOn-- dustjs-helpers and dustjs defines a helpers attribute.
This seems like a long standing issue that is not immediately obvious from the documentation. I use custom helpers in my private project and I could have encountered this issue - I didn't only because how I set up my dependencies in require.js (custom helpers were in an AMD depending on full dust.js).
Any time helpers get called between dustjs and dustjs-helpers declarations.
The main roadblock seems to be race conditions, so I wanted to force a specific script loading order. I used LABjs to do this on the client, and it was a code rearrangement on the server.
If user defines helpers with the same names defined in dustjs-helpers, the last declaration will win. I have no idea how to handle that beyond namespaces within dust.helpers, or declaring caveat emptor. That seems clunky and that would probably require more widespread code changes.