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

Allow new assertions while waiting for pending ones #1331

Merged
merged 2 commits into from
Apr 3, 2017

Conversation

novemberborn
Copy link
Member

Whilst not a great way to write tests, users may end up adding more
assertions from inside a promise chain that's passed to the t.throws()
or t.notThrows() assertions. These should be counted for the plan, and
not fail the test as being extraneous.

Fixes #1327.

Whilst not a great way to write tests, users may end up adding more
assertions from inside a promise chain that's passed to the `t.throws()`
or `t.notThrows()` assertions. These should be counted for the plan, and
not fail the test as being extraneous.

Fixes #1327.
Copy link
Contributor

@jamestalmage jamestalmage left a comment

Choose a reason for hiding this comment

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

Looks good once the above below are addressed (I've been away too long. I don't even know how GitHub works anymore).

this.saveFirstError(new Error('Assertion passed, but test has already ended'));
}

this.assertCount++;
}

addPendingAssertion(promise) {
if (this.finishing) {
if (this.finished) {
this.saveFirstError(new Error('Assertion passed, but test has already ended'));
Copy link
Contributor

Choose a reason for hiding this comment

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

I realize this is not from this PR, but a pending assertion technically hasn't passed yet. This message should be different.

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 considered that when I first wrote it, but the nuance seemed superfluous. And since #1330 it's not even shown anymore.

// Retry finishing after potential errors from pending assertions have been consumed.
const consumedErrors = Promise.all(this.pendingAssertions);
// Note that more assertions may be added in the meantime.
this.pendingAssertions = [];
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe add a test to validate the works it happens twice (pending resolve, but more pending have been added, and yet another sync will be added while you wait for those to resolve).

Copy link
Member Author

Choose a reason for hiding this comment

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

Done.


ava(a => {
a.pass();
setTimeout(() => {
Copy link
Member

Choose a reason for hiding this comment

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

I really don't think this should be ok. Many people do the mistake of using setTimeout inside a sync test and it silently passing. If users need to do this they should either use an async function or test.cb().

Copy link
Member Author

Choose a reason for hiding this comment

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

@sindresorhus It's not OK, that's what #1330 is about. This merely verifies that the internal handling doesn't cause a crash, since the error cannot currently be communicated.

Copy link
Member

Choose a reason for hiding this comment

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

Ah, ok.

@sindresorhus sindresorhus merged commit 22f7edd into master Apr 3, 2017
@sindresorhus sindresorhus deleted the allow-assertions-while-pending branch April 3, 2017 13:02
@sindresorhus sindresorhus restored the allow-assertions-while-pending branch April 3, 2017 13:04
@novemberborn novemberborn deleted the allow-assertions-while-pending branch April 3, 2017 13:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants