-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Add todo
test modifier
#565
Conversation
By analyzing the blame information on this pull request, we identified @Carnubak and @sohamkamani to be potential reviewers |
@@ -46,6 +46,8 @@ util.inherits(Runner, EventEmitter); | |||
module.exports = Runner; | |||
|
|||
optionChain(chainableMethods, function (opts, title, fn) { | |||
fn = fn || function () {}; |
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.
I think having function noop() {}
at the top of the file and using it here instead of anonymous function inline would be better.
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.
Cool, can do. Was also wondering if ||
is enough, or should I explicitly be checking for typeof fn === 'undefined'
?
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.
Nah, ||
is enough here.
Thanks for this PR, @BarryThePenguin! |
Can you also update the docs? https://github.com/sindresorhus/ava#testskiptitle-body |
This allows omitting test function for all tests, not just |
@sindresorhus Very good point. I guess we came back to the problems discussed in #9, |
Mmm... in this context skip and todo are synonymous with each other. Maybe it's worth exploring? |
Also, noting the api change, this allows for |
That makes sense. I wonder though if we should think about explicitly disallowing that to avoid people abusing it and confusing others. |
I'd be happy to investigate the possibility of having both a Thoughts so far:
Would also require adding |
You know, I would actually prefer to leave |
I've had a go at the |
@@ -27,6 +27,10 @@ TapReporter.prototype.start = function () { | |||
TapReporter.prototype.test = function (test) { | |||
var output; | |||
|
|||
var passed = test.todo ? 'not ok' : 'ok'; | |||
var todoDirective = test.todo ? '# TODO' : ''; | |||
var skipDirective = test.skipped ? '# SKIP' : ''; |
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.
Perhaps do:
var directive = '';
if (test.todo) {
directive = '# TODO';
} else if (test.skipped) {
directive = '# SKIP';
}
Which simplifies the todoDirective || skipDirective || ''
statement below and removes the unnecessary || ''
fall-through.
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.
Ha, great. Will do 💩
I'm not certain I follow the results of all the changes. But I'll just say that I would recommend that |
Yes agreed. Would be good to make @BarryThePenguin changes are looking good generally, nice work. Would be good to clear up some of the logic and state management so it's easier to follow how these special test cases (pun very much intended) are handled. |
Just went through the review. Added Mini and Verbose reporter handling for todo + tests |
I like it, LGTM from me! |
throw new TypeError('Expected a string'); | ||
} | ||
} else if (opts.skipped && typeof fn !== 'function') { | ||
throw new TypeError('Expected a function. Use todo for tests without a function'); |
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.
throw new TypeError('Expected a function. Use `test.todo()` for tests without a function.');
Looks pretty good. The docs needs to be updated and some inline feedback resolved. |
fn = noop; | ||
|
||
if (typeof title !== 'string') { | ||
throw new TypeError('Expected a string'); |
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.
throw new TypeError('`todo` tests require a title');
Updated. Happy to squash/rebase to make the commit history a little more sane 👍 |
LGTM |
👍 |
|
||
if (test.todo) { | ||
directive = '# TODO'; | ||
} else if (test.skipped) { |
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.
This should be test.skip
, from https://github.com/BarryThePenguin/ava/blob/bb3c972cc4df4b3df0139b5d6f738cb18da0e6e7/lib/runner.js#L99.
this.stats.testCount++; | ||
|
||
if (result.result.metadata.skipped) { | ||
if (test.metadata.skipped && !test.metadata.todo) { |
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 still need to increase the todoCount
, as well as initialize it to 0
in the run()
method. Then in https://github.com/sindresorhus/ava/blob/0e1886582833986b896c31859aa61d8da404e996/api.js#L233 you need to compute the total todoCount
. These counts are mocked in the reporter tests.
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.
var passed = test.todo ? 'not ok' : 'ok'; | ||
|
||
if (test.todo) { | ||
directive = '# TODO'; |
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 I'm not mistaken, there's no such directive as # TODO
in TAP spec. For TAP, we could treat todo
tests just like skip
and output them the same way.
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.
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.
In that case, great! :)
This is awesome! Thanks everyone for your work on this. Looking forward to seeing this merged :-) |
Still some things to iron out I think. import test from 'ava';
test.todo('foo');
test.todo('bar'); Gives no output with the default reporter:
And with
I don't think todo tests should be failing. import test from 'ava';
test('foo', t => t.pass());
test.todo('bar'); Outputs it's passing, but no mention of the
|
this.stats.testCount++; | ||
|
||
if (result.result.metadata.skipped) { | ||
if (test.metadata.todo) { | ||
this.stats.todoCount++; |
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 need to initialize todoCount
to 0
in the Runner#run()
method.
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.
Done
@BarryThePenguin would you mind adding a test in |
@sindresorhus sure, I'll see if I can work these out I'm starting to question my reasoning for initially marking todo tests as failed. I've been following the TAP spec and I'm not sure it's quite clear.
This implies that todo tests fail until they are implemented. This PR currently expects todo tests to have no implementation. Does this mean we mark them as failed? Again, I'm not sure how tightly we want AVA coupled with the TAP spec. |
Also, thanks everyone for providing feedback and spending the time to help out. It's been a really enjoyable experience 🐹 |
The TAP description doesn't explicitly say they should fail either, though, just that they shouldn't succeed like a normal test. I think we should rather enable users to fail todo tests in the linting step, not in AVA. Todo tests should be like TODO comments, informative, but not affecting. |
👍 |
Updated. @vdemedes @novemberborn todo is no longer skipped as well. Instead, in test-collection we check for the skipped and todo modifier. @novemberborn I've added the @sindresorhus I'm not quite sure about the exit code being 1, when should the exit code be 1? These are the outputs for the examples you provided above mini reporter
verbose reporter
test + todo example
|
@BarryThePenguin Perfect. Exactly what I was thinking :) LGTM |
Looks fine to me as well, thanks @BarryThePenguin! |
Landed. Thank you for tirelessly working on this one @BarryThePenguin. It turned out really good. |
Thanks @BarryThePenguin! |
This is terrific. I love the level of thought for quality coming from this project. Thanks everyone (especially @BarryThePenguin)! |
Seems too simple...
Fixes #563