Avoid directly depending on the global window variable

The current implementation forces tests to be run in the browser, and eliminates the possibility of using node or ruby utilities to run tests.