qunit: How should global error handlers resume the test runner in 2.0?

We’re using QUnit and RequireJS. We’ve defined a require.onError handler as follows:

define([], function () {
    require.onError = function (e) {
        if (QUnit && QUnit.config) {
            if (QUnit.config.current) {
                var currentTest = QUnit.config.current;

                currentTest.pushFailure("Died on test #" + (currentTest.assertions.length + 1) + " " +
                    currentTest.stack + ": " + (e.message || e));
            }

            // Restart the tests if they're blocking
            if (QUnit.config.blocking) {
                QUnit.start();
            }
        }
    };
});

This is heavily inspired by how the global error handler used to handle these issues. However, QUnit.start() itself now throws an error (in 2.0.0-rc1), so I need a new way to resume the test runner. What is the best way to do that?

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Comments: 28 (28 by maintainers)

Commits related to this issue

Most upvoted comments

This is not only fair and reasonable, it’s good to have this feature. Thanks for leading this work, @platinumazure.

Okay, it took me a while to come back to this but I think @JamesMGreene has the right idea here.

I’m working on #1099 to make the global error handling logic more directly accessible for other runtimes or plugins. That plus an ability to resume the test runner from the global error handler (possibly behind a config option) should hopefully work for these use cases.

@gibson042 My apologies, I thought I had thanked you earlier. Thanks for taking the time to put together a fiddle proving the concept- really helps.

@platinumazure: Given that your current strategy already dives into QUnit internals, you can create something analogous by spying on assert.async. Note that this is also subject to breakage at any time, but it should be an easy swap for now: https://jsfiddle.net/8kgpzwut/ .

Awesome. If it will help to have some proof-of-concept pull requests as APIs are proposed, I am happy to help.