jquery/qunit — pull request #193 by gburgett (2012-01-27 03:17:33+00:00)
Title: AsyncTest timer addon

Hi,

I was working with a library that required a significant amount of asynchronous tests, and was having a few problems. One was the test runner was not restarting when I had multiple callbacks in one test. Another was I had trouble figuring out QUnit's default test timeout functionality. A third was I had some assertion bleedover if a test timed out and another test was running, then the previous test's callback performed an assert.

I wrote this addon to solve my problems, and it does quite well. Please forgive me if my problems are already solved by the QUnit library and I'm simply not configuring it correctly. I thought I would contribute it for people working on complex asynchronous tests.

I did make an attempt to rewrite this to override QUnit's test start and assertion methods to accomplish the same thing, but my problem was I needed to override the Test object's run function and Test is not exposed.

The idea was that my test object would extend the testEnvironment object, and the 'remaining' property would be set by the 'expected' parameter of QUnit.test. The testEnvironment would also have a backreference to the test. Then I would also override the assertions and add the overrides to the testEnvironment object so they operate in that context. The overridden assertions would check if the testEnvironment was finished, and if not they would set the 'QUnit.config.current' to the backreferenced Test (which they would get from 'this.test'), so that the assert messages would not bleed over into another test. They would also call '_continue' with 'this' as the context, decrementing the 'remaining' parameter and calling 'start()' once 'remaining <= 0'. This, along with the timeout (which would be set at 'Test.prototype.run'), would execute the async tests as quickly as possible.

If you guys think this is a good idea I can continue to pursue it, and see if I can't make it work.

Signed-off-by: gburgett