Skip to content

Async: Implement new assert.async mechanism#653

Merged
JamesMGreene merged 2 commits into
qunitjs:masterfrom
JamesMGreene:async-done
Sep 11, 2014
Merged

Async: Implement new assert.async mechanism#653
JamesMGreene merged 2 commits into
qunitjs:masterfrom
JamesMGreene:async-done

Conversation

@JamesMGreene

Copy link
Copy Markdown
Member

Fixes #534.

Typical Usage Example:

QUnit.test( "x", function( assert ) {
  assert.expect( 1 );
  var done = assert.async();
  setTimeout(function() {
    assert.ok( true );
    done();
  }, 250);
});

This PR should now be merged before #634 (which I will then rebase).

@JamesMGreene

Copy link
Copy Markdown
Member Author

For QUnit v2.x, I think we should change QUnit.start/QUnit.stop to be straight-forward block/unblock without a semaphore (or rename them altogether to avoid confusion with the v1.x behavior) but they still need access to the semaphore for backward compatibility right now.

Comment thread src/core.js Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use pushFailure instead, if there's no current test it's the best option here

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, just a holdover from the existing code.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

@leobalter

Copy link
Copy Markdown
Member

I'm missing also the deprecation messages on asyncTest and QUnit.config.semaphore.

@leobalter

Copy link
Copy Markdown
Member

I also vote for deprecating QUnit.stop() and keeping QUnit.start() to only handle the global config.autostart. Tests' semaphores should be handled only by assert.async, that shouldn't care about global semaphore.

For 2.0.0, I would like to make all tests assert.async() by default, making them to fill expected assertions or calling assert.done, as previously mentioned by @jzaefferer.

@JamesMGreene

Copy link
Copy Markdown
Member Author

To make tests async by default, we would need to either:

  • provide the initially created done function somewhere, e.g. as an additional argument passed to the function callback
QUnit.test( "x", function( assert, done ) {
  /* ... */
  done();
});
  • or as a contextual property (e.g. this.done();), which may have conflicts when migrating from v1.x to v2.x.

@leobalter

Copy link
Copy Markdown
Member

also as assert.done();, no?

anyway, let's bring this 2.0.0 discussion to another issue so here we can focus on the changes on this PR.

@JamesMGreene

Copy link
Copy Markdown
Member Author

also as assert.done();, no?

assert.done is not planned.

@JamesMGreene

Copy link
Copy Markdown
Member Author

I'm missing also the deprecation messages on asyncTest and QUnit.config.semaphore.

Added deprecation warnings for QUnit.start, QUnit.stop, QUnit.asyncTest, and QUnit.config.semaphore.

@jzaefferer

Copy link
Copy Markdown
Member

For 2.0.0, I would like to make all tests assert.async() by default, making them to fill expected assertions or calling assert.done, as previously mentioned by @jzaefferer.

That's not really what I suggested (I hope). With the two approaches we're going for now, I don't think we really need something else.

The third approach would be to make assert.expect() trigger an async test, then running the specified of assertions ending the test. That wouldn't work for expect(0), which we currently support. There's probably more reasons why this isn't great, at least in the context of our existing APIs.

@jzaefferer

Copy link
Copy Markdown
Member

Please ignore style issues with lines that are too long until #654 is addressed, which will help fix these. That kind of issue is just distracting from the important parts here.

@gibson042

Copy link
Copy Markdown
Member

Other than that, \o/ \o/ \o/

This is great.

@JamesMGreene

Copy link
Copy Markdown
Member Author

Thanks, @gibson042!

@jzaefferer @leobalter @Krinkle: Did you guys want to review this PR further? I'm not sure I have anyone's stamp of approval yet.

Comment thread test/async.js Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing space

@leobalter

Copy link
Copy Markdown
Member

LGTM, so I reported only few style issues I saw

@JamesMGreene

Copy link
Copy Markdown
Member Author

@leobalter: All fixed, and a few more.

@JamesMGreene

Copy link
Copy Markdown
Member Author

So @leobalter and @gibson042 have approved now.

@jzaefferer @Krinkle @scottgonzalez, did any of you want to review this further before it gets merged?

Forewarning: The Promise PR (#634) will be ready for rebasing for further review and/or merging immediately after this one is merged, so you should also go review that one (which contains this PR as well) before I have to pester you. 😜

Comment thread reporter/html.js

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be fine, but since this property was never in the public API, it's not really necessary. I also see no reason why something outside QUnit should ever fiddle with this, except as workarounds.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed, per implementation of #653 (comment)

Comment thread test/autostart.js

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Calling start() again here doesn't cause any failure. It should, and it does in master.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added a test for it locally and it does cause a failure for me, so...?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added many tests for the various start/stop error scenarios mentioned in #653 (comment)

@jzaefferer

Copy link
Copy Markdown
Member

Overall looking very promising. No game-breaker, just some details that we need to iron out. No need to discuss setTimeout support here, I'll open a separate ticket for that.

@JamesMGreene

Copy link
Copy Markdown
Member Author

The new commit implemented all of the error scenario rules for QUnit.start/QUnit.stop per my comment #653 (comment), which I am still currently assuming are what @jzaefferer was implying in his comment #653 (comment).

@Krinkle Krinkle changed the title Async: Implement new assert.async mechanism Async: Implement new assert.async mechanism Sep 9, 2014
Comment thread src/core.js Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's QUni?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

QUnicorns?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whoops. Fixed. :)

@leobalter

Copy link
Copy Markdown
Member

LGTM

Enforce test-bound start/stop calls

Fixes #534
Closes #653
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

Implement async/done callback system

4 participants