-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Print tests that were pending when a timeout occurs #1886
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
Print tests that were pending when a timeout occurs #1886
Conversation
8672685
to
4d825c7
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.
Great start @vancouverwill!
What the Tap and Mini reporters are for?
You can ignore the TAP reporter for this.
The mini reporter is very much like the verbose reporter, so much so that I've been intending to merge them. Perhaps for now just focus on the verbose reporter.
Would you like extra tests in test/reporters/verbose.js, what format should these be in?
Yes please! Reporter tests live in test/reporters
. We record their output and compare it against a snapshot. You should add this scenario in https://github.com/avajs/ava/blob/master/test/reporters/verbose.js and configure the timeout option in https://github.com/avajs/ava/blob/master/test/helper/report.js. Then run tests using npx tap --no-cov 'test/reporters/*.js'
.
Use UPDATE_REPORTER_LOG=1 npx tap --no-cov 'test/reporters/*.js'
to update the reporter snapshots.
Let me know if you have any other questions 👍
lib/reporters/verbose.js
Outdated
@@ -70,6 +70,8 @@ class VerboseReporter { | |||
this.failures = []; | |||
this.filesWithMissingAvaImports = new Set(); | |||
this.knownFailures = []; | |||
this.runningTestFiles = {}; |
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 a Map
.
lib/reporters/verbose.js
Outdated
addTestRunning(evt) { | ||
this.runningTestsCount++; | ||
if (this.runningTestFiles[evt.testFile] === undefined) { | ||
this.runningTestFiles[evt.testFile] = {}; |
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 a Set
.
lib/reporters/verbose.js
Outdated
/** | ||
* Generates the summary string of tests that are still running | ||
* @returns 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.
To be honest we don't really bother with these comments 😄
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.
Could you remove this comment?
lib/reporters/verbose.js
Outdated
break; | ||
case 'timeout': | ||
this.lineWriter.writeLine(colors.error(`${figures.cross} Exited because no new tests completed within the last ${evt.period}ms of inactivity`)); | ||
this.lineWriter.writeLine(colors.error(`${figures.cross} Exited because no new tests completed within the last ${evt.period}ms of inactivity\n${this.runningTestSummary()}`)); |
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.
timeout
applies to the set of test files that are currently running. However unless --fail-fast
is set, AVA will continue to run remaining test files. This means multiple timeouts may occur.
We should include the timed out files when the event is emitted:
Line 77 in 55e4021
runStatus.emitStateChange({type: 'timeout', period: timeout}); |
Then if you pass the evt
to runningTestSummary()
we could print the files appropriate for each particular timeout.
test/integration/assorted.js
Outdated
t.notMatch(stdout, /.*long-running.js:fast.*/, 'the fast test should not still be shown as running'); | ||
t.match(stdout, /.*long-running.js:slow.*/); | ||
t.match(stdout, /.*long-running.js:slow two.*/); | ||
t.match(stdout, /.*long-running.js:slow three.*/); |
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 timeout test ought not to be here. I think I left it in on purpose since it was reasonably small, but obviously that's no longer the case 😄 Let's remove these additions and write a reporter test instead.
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.
Could you remove the new assertions in this test, and undo the changes in long-running.js
?
1fd483e
to
cf002dc
Compare
hi @novemberborn thanks for the pointers so far 😄 I used the Within Within Apologies because I have put a lot of in Many thanks, Will 😄 |
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 wondered if you had any pointers as to why the timeout is not getting triggered? 😕
OK I figured it out. Took me a little while, too! In short… it's because the tests mock the Date
object. Timeout detection relies on the date actually changing, which it doesn't…
We mock the Date
to ensure the logs are the same wherever and whenever the tests are run. I'll push a commit which restores it for the timeout tests.
I've left some other comments, too. Please run npx xo --fix
to fix linting issues.
In https://github.com/avajs/ava/blob/846920a40c10427c187bdffa51737e907733efbc/api.js#L72:L77 you should record the workers that are being exited because of this timeout, and then pass their file paths in the timeout
event object.
Then in the reporter, you should pass those file paths to runningTestSummary()
and only print the pending tests from the workers that were exited.
This is needed since AVA will continue running more test files, which themselves could time out, and we don't want the same tests to be printed multiple times.
Thanks for your hard work on this @vancouverwill!
test/helper/report.js
Outdated
@@ -139,5 +139,7 @@ exports.regular = reporter => run('regular', reporter); | |||
exports.failFast = reporter => run('failFast', reporter); | |||
exports.failFast2 = reporter => run('failFast2', reporter); | |||
exports.only = reporter => run('only', reporter); | |||
exports.timeoutInSingleFile = reporter => run('timeoutinsinglefile', reporter); | |||
exports.timeoutInMultiFiles = reporter => run('timeoutinmultifiles', 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.
Let's camelCase the type values, like with failFast
.
Let's use timeoutInMultipleFiles
rather than "multi files".
test/helper/report.js
Outdated
@@ -97,7 +97,7 @@ const run = (type, reporter) => { | |||
babelConfig: {testOptions: {}}, | |||
resolveTestsFrom: projectDir, | |||
projectDir, | |||
timeout: undefined, | |||
timeout: type.substring(0,7) === 'timeout' ? "1000ms" : 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.
Use type.startsWith('timeout')
.
lib/reporters/verbose.js
Outdated
/** | ||
* Generates the summary string of tests that are still running | ||
* @returns 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.
Could you remove this comment?
test/integration/assorted.js
Outdated
t.notMatch(stdout, /.*long-running.js:fast.*/, 'the fast test should not still be shown as running'); | ||
t.match(stdout, /.*long-running.js:slow.*/); | ||
t.match(stdout, /.*long-running.js:slow two.*/); | ||
t.match(stdout, /.*long-running.js:slow three.*/); |
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.
Could you remove the new assertions in this test, and undo the changes in long-running.js
?
lib/reporters/verbose.js
Outdated
let smy = ` ${this.runningTestsCount} tests still running`; | ||
this.runningTestFiles.forEach((tests, file) => { | ||
for(let test of this.runningTestFiles.get(file)) { | ||
smy += `\n${figures.circleDotted} ${file}:${test}`; |
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 this.prefixTitle(file, title)
instead.
lib/reporters/verbose.js
Outdated
} | ||
let smy = ` ${this.runningTestsCount} tests still running`; | ||
this.runningTestFiles.forEach((tests, file) => { | ||
for(let test of this.runningTestFiles.get(file)) { |
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.
Change test
to title
.
lib/reporters/verbose.js
Outdated
if (this.runningTestsCount === 0) { | ||
return 'NO TESTS 🍓'; | ||
} | ||
let smy = ` ${this.runningTestsCount} tests still running`; |
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 don't need to add the space. However let's put a \n
in front and put a colon after running
.
@vancouverwill could you allow edits from maintainers on this PR so I can push my fix? |
Hey @novemberborn thanks for those comments, will look into them. With regard to access it looks like it already is set to that as far as I can see 😄 |
Yes. My "push to the PR branch" script got confused about the slash in the branch name. I've pushed my fix now, let me know if you have any further questions! |
4030f32
to
85bfc10
Compare
…ting test summary to include list of running tests with their files
85bfc10
to
45a97c2
Compare
hey @novemberborn I made the changes you suggested and the different files timeout separately with their own respective error messages. Wasn't sure what you guys prefer to do for commit messages, whether you like to squash them or keep the major ones around for histories sake, they are in there for now but happy to squash them if you prefer. Thanks Will |
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.
Wasn't sure what you guys prefer to do for commit messages, whether you like to squash them or keep the major ones around for histories sake, they are in there for now but happy to squash them if you prefer.
This is a pretty focused PR, so we'll do a squash and merge.
I've left some inline comments but I figured we've been doing a back and forth dance for a while now, and I feel a bit bad about that. I'm going to push some changes that address my comments. Let me know what you think and then we can land this.
lib/reporters/verbose.js
Outdated
for (const timedOutFile of evt.timedOutWorkerFiles) { | ||
const currentFile = this.runningTestFiles.get(timedOutFile); | ||
if (currentFile) { | ||
smy += `\n${this.runningTestsCount} tests still running in ${timedOutFile}:`; |
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.
We can actually take currentFile.size
. runningTestsCount
is a global count.
ahh that's awesome. thanks for your patience with the back and forth, I know there has been a fair bit of chat but it is the first time me working on the project so there is bound to more questions than there would normally be. Anyway cheers for the help, I'm definitely happy to get it out. Our team use ava all the time and being able to see which files have timed out will be really useful And good point about ". runningTestsCount is a global count.", I had assumed originally that timeout was a global state and still had that way of thinking I guess. |
@vancouverwill awesome. Was about to merge this and then I realized the PR said this would work on interrupts too, and I don't think we're testing that yet. Will have a look to see what state this PR is actually in, and then merge it with the correct commit message 😉 |
ahh true, I was so focused on timeouts but that was part of the orginal
plan. Should be able to reuse a lot of the same logic for timeouts tho so I
can add the code on here or better yet get this out and we can do another
pr for the interrupts?
…On Mon, Sep 10, 2018 at 9:31 AM Mark Wubben ***@***.***> wrote:
@vancouverwill <https://github.com/vancouverwill> awesome.
Was about to merge this and then I realized the PR said this would work on
interrupts too, and I don't think we're testing that yet. Will have a look
to see what state this PR is actually in, and then merge it with the
correct commit message 😉
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#1886 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AA4ZIyHIM08-DYvCJcutYtajeds0-zVKks5uZiNGgaJpZM4Vu75E>
.
|
Yup that's the plan. Just need to have another look at it. |
Fixes #583
First PR for this project so wanted to get some eyes on it before I spent too much time on it and check I am moving in the right direction 😄
Worked on so far
Still to do
SIGTERM
Unknowns
test/reporters/verbose.js
, what format should these be in?