lets_code_javascript icon indicating copy to clipboard operation
lets_code_javascript copied to clipboard

Remove the need for a timeout in smoke test for font loading

Open mgrandrath opened this issue 11 years ago • 0 comments

I wired up the font loading events to PhantomJS.

  • The callback onInitialized is called before the page is loaded (especially before the IIFE with the TypeKit boilerplate is executed).
  • It defines callbacks for fontactive and done in the browser's global namespace. The loaded fonts get stored in a local array. When done is called PhantomJS is notified via callPhantom (which is provided by PhantomJS).
  • callPhantom triggers page.onCallback with 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 within onCallback which 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.

mgrandrath avatar Nov 27 '14 20:11 mgrandrath