-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Breaking: t.end
requires test.async
, and t.plan
will not auto end tests. Fixes #244.
#253
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
Breaking: t.end
requires test.async
, and t.plan
will not auto end tests. Fixes #244.
#253
Conversation
Overall, I like it. There are a few places where it creates some weirdness. All revolve around our async assertions ( test('this does not work', t => {
var promise = Promise.reject(new Error('foo'));
// this assertion actually happens asynchronously
t.throws(promise);
// we do not return a promise, so AVA assumes this is a synchronous function
}); There are a number of easy ways around this this. The issue will be preventing user confusion. (Ordered from best to worst workaround IMHO) test('use async/await', async t => {
var promise = Promise.reject(new Error('foo'));
await t.throws(promise);
}); test('return the assertion promise', t => {
var promise = Promise.reject(new Error('foo'));
// t.throws returns a promise, so return it from our test function.
return t.throws(promise);
}); test.async('legacy async with a plan', t => {
t.plan(1);
var promise = Promise.reject(new Error('foo'));
// test is auto-ended once this resolves and we reach our plan count.
t.throws(promise);
}); I like this last one the least. As previously stated, I think allowing |
d6024be
to
28b1641
Compare
#1 is how I already use it and how it was intended. We should just document it better. |
I think we have a resolution in #244, unless there's anything else that's still undecided? Could you rebase this PR? |
0fd3ff8
to
458c36c
Compare
t.end
requires test.async
, and t.plan
will not auto end tests. Fixes #244.
f75fe47
to
e684a24
Compare
This is ready for review. // @sindresorhus @vdemedes I have updated the docs to reflect the new behavior, with a few language tweaks along the way. |
readme.md
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The previous Observable example was so trivial that I don't feel it adequately explained the advantage AVA offered.
I think this:
- Is a simple enough usage of observable that you don't necessarily need to be familiar with them to understand what is happening.
- Shows a novel use of
t.plan()
in coordination with the Observable filter. It's a little closer to a test someone might actually right.
@BarryThePenguin
What I know about Observables I learned in the last 20 minutes, so feel free to tell me where I missed the mark.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could change map with .do(() => t.pass());
. Otherwise, looks good.
RxJS has some docs on marble testing. But I'm not sure how they would fit with AvA
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good call! Thanks!
4400d0e
to
77ebd84
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not just this here instead?
if (!this.metadata.async) {
throw new Error('t.end is not supported in this context. To use t.end as a callback, you must explicitly declare the test asynchronous via `test.async(testName, fn)` ');
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You mean just have t.end
throw when executed?
Because we want to fail fast, and if passed as a callback:
fs.readFile(path, t.end);
We are waiting for the function to actually be called instead of throwing ASAP.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does it matter? It shouldn't be used with test()
anyways. So I don't see how it makes a difference.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If they don't return a promise - we assume sync. We might mark the test done before the callback returns.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, never mind. Got it now. Sorry about the noise.
Looks good to me, except for a few inline comments :) @vdemedes ? |
✅from me. |
Today is a major holiday in the US, so I won't be wrapping this up untill tomorrow. |
@jamestalmage No worries at all. Enjoy Thanksgiving :D |
AVA will no longer automatically end tests when you reach the plan limit. Users must explicitly call t.end(). It is now an error to return an async object (promise/observable) from a legacy `test.async` test. Reference: avajs#244 (comment)
77ebd84
to
982a451
Compare
Ahhh, Windows! @sindresorhus - I'll start looking into it here, but can you just retrigger the build? I was watching that one, and it was running REALLY slow. I think something was wrong on that VM. |
Done |
OK, CI passed. Are we good here? I think all concerns are addressed. |
…n-async Breaking: `t.end` requires `test.async`, and `t.plan` will not auto end tests. Fixes #244.
See #244