-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Print out warning in verbose & mini reporter when .only() tests are used #1177
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
Conversation
Are you sure you got this part correct? I don't see the sense in it. |
You mean you think the implementation is wrong? Or do you not think there is any value in showing the remaining count? What is happening in the case of the screenshots is that there are two test files being run, test.js and test2.js. There is one .only() test in test.js, and none in test2.js. So now you are at least notified of all the tests in test2.js that has not been run because of the .only() tests. If there was at least one .only in test2.js also. It would just report "all other tests have been skipped". |
I get it now. The first quote is the current message (result of your previous PR). I did not understand this, at first. BTW, why do you put quotes around the |
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.
Shallow review, according to my unfamiliarity with the code.
if (runStatus.hasExclusive === true) { | ||
var remainingTests = runStatus.testCount - (runStatus.passCount + runStatus.failCount); | ||
if (remainingTests > 0) { | ||
status += '\n\n ' + colors.information('The .only() modifier is used in some tests. At least', remainingTests, 'tests were not run.'); |
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.
Use native JavaScript template string instead of some library's API, I think.
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.
Meh, it still needs to be wrapped with colors.information()
, so this combination seems fine to me.
Previously we were targeting Node.js 0.10, which meant that we couldn't use template strings. Now we can, but it's no big deal if new code follows the pattern already used in the file.
if (remainingTests > 0) { | ||
status += '\n\n ' + colors.information('The .only() modifier is used in some tests. At least', remainingTests, 'tests were not run.'); | ||
} else { | ||
status += '\n\n ' + colors.information('The .only() modifier is used in some tests. All other tests have been 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.
DRY first sentence.
if (runStatus.hasExclusive === true) { | ||
var remainingTests = runStatus.testCount - (runStatus.passCount + runStatus.failCount); | ||
if (remainingTests > 0) { | ||
output += '\n\n\n ' + colors.information('The .only() modifier is used in some tests. At least', remainingTests, 'tests were not run.'); |
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 have some shared strings here. Shared with the mini reporter.
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.
And template 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.
You have some shared strings here. Shared with the mini reporter.
I find that to be the kind of repetition that is too bothersome to dry up.
if (remainingTests > 0) { | ||
output += '\n\n\n ' + colors.information('The .only() modifier is used in some tests. At least', remainingTests, 'tests were not run.'); | ||
} else { | ||
output += '\n\n\n ' + colors.information('The .only() modifier is used in some tests. All other tests have been 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.
Shared string.
Thanks for the review! 👍 I am not familiar with template strings, but I think the implementation I have done with regards to string formatting is in-line / same styles as what was already in place in the reporters. I personally don´t think there is a problem with having the same output strings repeated across the two different reporters. They are two separate pieces that in theory could output different things. It also makes it easy to read what the reporter outputs without having to check some global configuration property. But I am up for making changes if more people think its a better solution :) @mightyiam Could you provide an example of how my two lines of output would look using template strings? |
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 is great!
Please check in with @jarlehansen regarding the remainingCount
computation (see inline comment).
if (runStatus.hasExclusive === true) { | ||
var remainingTests = runStatus.testCount - (runStatus.passCount + runStatus.failCount); | ||
if (remainingTests > 0) { | ||
status += '\n\n ' + colors.information('The .only() modifier is used in some tests. At least', remainingTests, 'tests were not run.'); |
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.
Meh, it still needs to be wrapped with colors.information()
, so this combination seems fine to me.
Previously we were targeting Node.js 0.10, which meant that we couldn't use template strings. Now we can, but it's no big deal if new code follows the pattern already used in the file.
if (runStatus.hasExclusive === true) { | ||
var remainingTests = runStatus.testCount - (runStatus.passCount + runStatus.failCount); | ||
if (remainingTests > 0) { | ||
output += '\n\n\n ' + colors.information('The .only() modifier is used in some tests. At least', remainingTests, 'tests were not run.'); |
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 have some shared strings here. Shared with the mini reporter.
I find that to be the kind of repetition that is too bothersome to dry up.
} | ||
|
||
if (runStatus.hasExclusive === true) { | ||
var remainingTests = runStatus.testCount - (runStatus.passCount + runStatus.failCount); |
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 computed in lib/run-status.js
, which @jarlehansen is working on in #1179. Note that as I commented there (#1179 (comment)) you need to include other test states in this count, see the highlighted lines in https://github.com/avajs/ava/blob/033d4dcdcbdadbf665c740ff450c2a775a8373dc/lib/run-status.js#L41:L45.
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.
Will sync up with @jarlehansen regarding this and update PR.
15f477f
to
63fc44a
Compare
@novemberborn updated PR with the changes to remainingCount in run-status.js and added a test for it like you suggested to @jarlehansen in his PR. Had a quick chat with him and he would get on later today to take a look. So you guys can review my suggestion and see what you think :) |
Thanks @ThomasBem, this improves on what I created in my pull request. When this is merged I will update #1179 |
@ThomasBem @jarlehansen thanks for your collaboration 💯 I found one edge case. Tests in the file with I think we should count all tests in |
Yeah, I knew about that behaviour and I tried explaining it in my original PR text. But guess I did not get that through properly, or at least i should have mentioned it more specific :)
Thats the reason its split into two. Because when .only is present it did not count all the other tests. Did not feel comfortable with changing some of the deeper behaviour of how tests where added and removed from collections. But if you think its a good idea to change the behaviour to count all the tests even if there is .only tests present. Then i guess we can simplify the logic you linked to in test-collection.js similar to what was done run-status.js regarding exclusive? |
Fair enough. But yes, let's change it. We should keep the counting consistent, regardless of whether |
@novemberborn I got some results that confused me a bit when trying to fix some failing tests after implementing what I think would be a solution for test-collection.js. Then I read this in the description of one of the api.js tests that was failing, Line 22 in ce42fcb
Is this correct? That it will still run tests that are NOT tagged with .only() if they are in a file that has at least one .only() test? I am still reading up on the code and trying to see if its just me that´s missing something obvious and thats why things are acting seemingly a bit weird. But figured I would at least ask for a clarification regarding this one thing :) |
Think I figured out what i was doing wrong on my own :) Was just doing things way too complicated... But this wording is still somewhat confusing to me. Because it does not run any other tests than the .only() as far as i can tell? |
63fc44a
to
23ffce3
Compare
@novemberborn PR updated with requested changes. It now properly counts all tests, exclusive or not. Also made some changes to the reporters output to be more in line with #1179 that @jarlehansen is working on. Now it only reports on .only() / exclusive if there are tests that have not been run. Any thoughts on the output text?
A bit clumsy with the "test(s)", but i couldn't think of anything better to cover 1 or multiple tests remaining. |
"1 tests were not run" is fine with me. |
That's not how I read it. It's meant to say that if there are two test files, and only one contains exclusive tests, then none of the tests from the other file are run. |
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.
Awesome, so very nearly there 👍
} | ||
|
||
if (runStatus.hasExclusive === true && runStatus.remainingCount > 0) { | ||
status += '\n\n ' + colors.information('The .only() modifier is used in some tests.', runStatus.remainingCount, 'test(s) were not run.'); |
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.
Use plur()
, so "1 test was" and "2 tests were".
23ffce3
to
a2b5608
Compare
PR updated again :) |
Great work @ThomasBem, keep it up 👍 |
Thanks for the support! 👍 |
} | ||
|
||
if (runStatus.hasExclusive === true && runStatus.remainingCount > 0) { | ||
status += '\n\n ' + colors.information('The .only() modifier is used in some tests.', runStatus.remainingCount, plur('test', runStatus.remainingCount), plur('was', 'were', runStatus.remainingCount), 'not run.'); |
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.
@ThomasBem this is very petty, but I just noticed there's a period at the end of the message here (and in the verbose reporter). None of the other messages seem to end in a period. If you've got the time could you do a PR to remove them? 😄
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.
@novemberborn Sure, I can fix that :)
This PR fixes #1135. If all test files have at least one .only test in them, it will print out the following message at the end of the report for both mini and verbose.
If there are test files without .only in them, it will print out the following.
remainingTests will then be the number of tests in the test files that don´t have any .only tests.
It currently looks like this:
Feedback appreciated :)