lets_code_javascript
lets_code_javascript copied to clipboard
Remove the need for a timeout in smoke test for font loading
I wired up the font loading events to PhantomJS.
- The callback
onInitializedis called before the page is loaded (especially before the IIFE with the TypeKit boilerplate is executed). - It defines callbacks for
fontactiveanddonein the browser's global namespace. The loaded fonts get stored in a local array. Whendoneis called PhantomJS is notified viacallPhantom(which is provided by PhantomJS). -
callPhantomtriggerspage.onCallbackwith the collected fonts array as argument (Note: only serializable data can be exchanged this way). - On the client side, the callbacks that are defined via PhantomJS are assigned to the config object (or a no-op function if they are undefined, which will be the case outside of the smoke test).
Remaining problems
- The test does not feel terribly faster. I don't know if there are any PhantomJS settings or other tweaks that would improve this.
- The call to
phantom.exit()is now withinonCallbackwhich is less than ideal. Either should there be a mechanism for collecting asynchronous test results or each test should go into its own file. The former is probably better for performance (because of spawning less processes) while the latter is generally simpler and makes it easier to organize the tests.