wellwelwel / poku

🐷 Poku makes testing easy for Node.js, Bun, Deno, and you at the same time.
https://poku.io
MIT License
632 stars 14 forks source link

Make output report customizable #629

Open mrazauskas opened 2 months ago

mrazauskas commented 2 months ago

In TSTyche repo I have 98 test files. If I run them locally in VS Code terminal, the output rendered by first test files cannot be reached any more. If there are any errors or failures, because the output is outside of scroll back buffer of the terminal.

The only way to see the output of a failing test, is to rerun a particular file.

Perhaps in a multi file run it would be better to emit only errors and file names. (Instead of printing out the whole test tree). Like this:

  ✔ tests/config-install.test.js › 9020.904792ms
  ✔ tests/config-target.test.js › 14780.683209ms
  ✔ tests/config-typescriptPath.test.js › 2426.265125ms
  ✔ tests/config-update.test.js › 2459.254291ms
  ✔ tests/feature-store.test.js › 16204.369208ms
  ✔ tests/feature-typescript-versions.test.js › 39605.810250ms
  ✔ tests/feature-watch.test.js › 70000.974792ms
  ✔ tests/validation-store.test.js › 5521.964250ms
  ✔ tests/validation-target.test.js › 5053.783042ms
  ✔ tests/validation-update.test.js › 231.104250ms
  ✔ tests/validation-watch.test.js › 197.263041ms

If a test file is passing, it isn’t important to see its structure. Keeping focus on errors and failures is most important.

(I would love to have dot reporter, of course. But that’s another story.)

wellwelwel commented 2 months ago

Hm, to do this, all we need to do is remove it:

https://github.com/wellwelwel/poku/blob/7c852a5bf15b1fd28be1e5102ca965da877da6f3/src/services/format.ts#L100-L109

mrazauskas commented 2 months ago

To clarify more, output for a single file looks right. Very useful to see all the details. I try to point out that it becomes overwhelming in multi file runs.

wellwelwel commented 2 months ago

To clarify more, output for a single file looks right. Very useful to see all the details. I try to point out that it becomes overwhelming in multi file runs.

Do you think we could impose a limit to decide whether or not to display the successes?

mrazauskas commented 2 months ago

Hard to say how verbose a single file can be. So probably keep it verbose for a single file run and make it silent for a multi file run (this is how TSTyche works, by the way). Optionally, --verbose option could be added to enable / disable verbosity.

What you think?

wellwelwel commented 2 months ago

I don't know if a --verbose option would be confusing in relation to --debug.

I think it would be more interesting:

Personally, I think option B is more attractive.

mrazauskas commented 2 months ago

This is your project and you see the context better. All I would like to see is less output in case a test file is all passing.

wellwelwel commented 2 months ago

A --reporter option would be great. @mrazauskas, I've adapted the issue title 🙋🏻‍♂️

mrazauskas commented 2 months ago

A --reporter option would be great. @mrazauskas, I've adapted the issue title 🙋🏻‍♂️

By the way, that would be good solution. --reporter dot is all what I need ;D

mrazauskas commented 2 months ago

Just an idea, the --reporter option could allow adjusting verbosity of the reporter. For instance, --quiet can be replaced with --reporter=quiet.

I was running tests today and thinking that information like “Running tests in parallel” or “Fail fast is enabled” are useful for debugging. Something like --log=debug, --log=info, --log=error, --log=quiet could make sense.

wellwelwel commented 2 months ago

--quiet can be replaced with --reporter=quiet

About --quiet, I like the idea of having it as a direct flag due to familiar commands in CLI apps. The idea is that --quiet overrides any debug or reporter options.

For example:

{
  "test": "poku --reporter=dot"
}
npm run test -- --quiet

In addiction, I wondered how other test runners deal with multiple reporters, I intend to have this functionality in a way that makes it easy to implement new reporters 🙋🏻‍♂️

mrazauskas commented 2 months ago

I wondered how other test runners deal with multiple reporters

Jest loops through the list of reporters. A reporter must be an object with a set of callbacks like onRunComplete() (all are optional). There are several callbacks and they are call with various data during the test run. The object passed to onRunComplete() includes data of the whole test run.

In node:test custom reporters are based on a stream of events. That’s lovely pattern!

Inspired by that, I adopted an event emitter for TSTyche. Not only reporters are handle through events, but also the exit code or failFast logic (it handles a cancelation token passed to the runner).

wellwelwel commented 2 months ago

Reporters' Ideas:

The names may not be exactly that.

[!IMPORTANT]

Both --debug and --quiet aren't reporters and should be complementary to all reporters.


Assert

Based on Deno's output, filter and highlight different lines when there is more than one line (regardless of whether it's a string, objects, etc.).

mrazauskas commented 2 months ago

The default reporter could be named poku. This came to my mind as a joke, but why not? ;D