Open codeclown opened 6 years ago
This needs to be addressed, current dynamic console output gets messed up when anything else logs in-between.
Addressing this could also remove the need for requiring logLevel: 'silent'
.
The possible solution I have in mind would be to listen to process.stdout
and process.stderr
manually and also manually print anything they piped through. Could become messy/unreliable, though, but worth a shot.
process.stdout.on('data', ...)
Turns out this isn't that straight-forward because the process in which the reporter runs is different than the process in which the tests run. Therefore, it's not possible to listen to stdout/stderr of the tests in the reporter.
I'll leave this issue open, maybe someone has a solution.
To clarify, the problem is the following.
Instead of always printing more and more lines after the previous output whenever the state of the suite changes (e.g. a test passes -> should now show "1 passed" instead of "0 passed"), this reporter clears N lines in the console and then just prints the lines that changed compared to the last state.
This works perfectly when nothing but this reporter's output is printed to the console, but it breaks whenever something else logs to the console. Example:
Reporter first prints this:
00-01 ./sample-file.js
0 passed 0 failed 0 pending
❯ Sample test (currently running)
Then some random process, or the currently running test, or wdio, etc. prints something:
00-01 ./sample-file.js
0 passed 0 failed 0 pending
❯ Sample test (currently running)
FOOBAR printed from test
Now, the next time the reporter receives an update, it clears N lines based on its internal state, disregarding the outsider FOOBAR-line. In this case the line that changed is line 2, so 3 lines are cleared before printing the changed lines, and this is the broken result:
00-01 ./sample-file.js
0 passed 0 failed 0 pending
1 passed 0 failed 0 pending
❯ Sample test (currently running)
I haven't tested if this reporter overwrites manual console.logs, and if it does, that should be prevented so that it's possible to log stuff from the tests.