Skip to content
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

start() may happen before init() #358

Closed
rodneyrehm opened this issue Nov 28, 2012 · 4 comments
Closed

start() may happen before init() #358

rodneyrehm opened this issue Nov 28, 2012 · 4 comments
Labels
Type: Bug Something isn't working right.

Comments

@rodneyrehm
Copy link
Contributor

Using Require.js we've run into a funny issue. Apparently QUnit.init (via window.load) is triggered after reqired resource have been loaded. Since QUnit.config.autostart = false; is in play, we call QUnit.start() in the master test-file. (as suggested in this Example).

The quickest solution @jzaefferer and me found is diverting calls to start() unless QUnit is initialized. Achieve with

  1. add QUnit._initialized = true; to QUnit.init();
  2. prepend the following to QUnit.start():
if (!QUnit._initialized) {
    // defer execution until the thing has initialized
    setTimeout(function() {
        QUnit.start(count);
    }, 50);
    return;
}

@jzaefferer also voiced concerns this could break on headless browsers. (I have no clue what that break could be…)

@jzaefferer
Copy link
Member

When running headless without a DOM, QUnit.init never runs. In that case the workaround would break stuff.

Should probably refactor QUnit.init() to initialize the config while QUnit loads, and move the DOM init stuff into QUnit.load, where a bunch of other DOM interaction happens anyway.

@rodneyrehm
Copy link
Contributor Author

ok, you had me confused there. headless - in my simple mind - is a browser that doesn't paint to screen, it still has a dom, though. What you mean - again in my words - is a javascript shell (node, or whatever, something that is not a browser).

Anyway, splitting up default config and DOM init makes sense! This doesn't solve the problem though, as tests could depend on the initialized dom, no?

@jzaefferer
Copy link
Member

If there's no UI (aka headless), results are only available via logging callbacks. Though if the DOM is available, it needs to be update before running the first test. So yeah, for that case, the order needs to get fixed.

@jzaefferer
Copy link
Member

Discussed with Scott in IRC, probably need to do something like this: have QUnit.start() wait for QUnit.load (if there's a dom), if there's none, init immediately. Wrap the DOM access in QUnit.init() to make that also work without DOM.

rodneyrehm added a commit to rodneyrehm/qunit that referenced this issue Dec 17, 2012
@ghost ghost assigned Krinkle Dec 17, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Bug Something isn't working right.
Development

No branches or pull requests

3 participants