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

Async: Implement new assert.async mechanism #653

Merged
merged 2 commits into from
Sep 11, 2014
Merged

Async: Implement new assert.async mechanism #653

merged 2 commits into from
Sep 11, 2014

Conversation

JamesMGreene
Copy link
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
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.

config.current.semaphore = 1;
config.semaphore = 0;
} else {
QUnit.assert.ok( false, "Test timed out" );
Copy link
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
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
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
Member

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

@leobalter
Copy link
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
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
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
Member Author

also as assert.done();, no?

assert.done is not planned.

@JamesMGreene
Copy link
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
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
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
Member

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

This is great.

@JamesMGreene
Copy link
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.

setTimeout(function() {
currentTest.state = "beforeEach";
done();
}, 50);
Copy link
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
Member

LGTM, so I reported only few style issues I saw

@JamesMGreene
Copy link
Member Author

@leobalter: All fixed, and a few more.

@JamesMGreene
Copy link
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. 😜

@@ -15,6 +15,8 @@ QUnit.init = function() {
config.autorun = false;
config.filter = "";
config.queue = [];

// DEPRECATED: QUnit.config.semaphore will be removed in QUnit 2.0.
Copy link
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
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)

@@ -0,0 +1,6 @@
QUnit.start();
Copy link
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
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
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
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
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 Sep 9, 2014
QUnit.start();
}, config.testTimeout );

// If there isn't a test running, don't allow QUni.stop() to be called
Copy link
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
Member

Choose a reason for hiding this comment

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

QUnicorns?

Copy link
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
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
4 participants