segmentio / analytics.js-integration-tester

Helper to quickly test an analytics.js integration.
MIT License
8 stars 11 forks source link

add waitForScripts #37

Closed tsholmes closed 8 years ago

tsholmes commented 8 years ago

This provides a function to fix issues seen in the tests for various integrations caused by a race between scripts that an integration loads and the test framework.

This was tested against the adroll and route integrations, which have been failing spuriously due to this race condition.

It overrides the document.createElement method in order to track all dynamically created script tags. A map (waiting) is kept of all elements who have not yet loaded, which are removed from this map once the load event fires. Once the last removal happens, it will callback everyone waiting for scripts to load.

jgershen commented 8 years ago

CC @hankim813 @f2prateek @wcjohnson11 for code review

wcjohnson11 commented 8 years ago

lgtm