GithubHelp home page GithubHelp logo

Add `--reporters` argument about runner HOT 15 CLOSED

japa avatar japa commented on June 1, 2024
Add `--reporters` argument

from runner.

Comments (15)

thetutlage avatar thetutlage commented on June 1, 2024

Great proposal. I see two things here.

  • We need the reporters array to be a collection of reporters, where all of the reporters are not enabled by default. Or in other words, they are disabled by default.
  • Next, we can activate one or more reporters with the --reporters flag.
  • Finally, we need at least one default enabled reporter. Otherwise, it becomes tiring to always pass the --reporter flag.

I was looking at Mocha, and they have the spec reporter enabled by default. However, the spec reporter is bundled within mocha, so they always have it available.

Have you looked at Vitest or Jest, how they approach this? I have some ideas in mind, but let's see if there is an established pattern

from runner.

Julien-R44 avatar Julien-R44 commented on June 1, 2024

Yes, so Vitest proposes a bit the same thing as my last suggestion. Except that all the reporters are built-in and directly integrated in it. No additional packages to install :
https://vitest.dev/config/#reporters
image

Jest proposes this :
https://jestjs.io/fr/docs/configuration#reporters-arraymodulename--modulename-options

I am personally not a fan of Jest's tuple syntax, and I find Vitest's approach much more clear and concise.
However, the problem with Vitest's approach is that it is impossible to change reporter options. We could imagine a reporterOptions property, but this would not be typesafe :

configure({
   reporter: 'dot',
   reporterOptions: {
      dotOption: true
   }
})

from runner.

thetutlage avatar thetutlage commented on June 1, 2024

How about making reporters an object with following properties.

reporters: {
  list: [],
  default: 'spec',
},

The default property can be type safe based upon what's in their in the list.

from runner.

Julien-R44 avatar Julien-R44 commented on June 1, 2024

The problem with this solution is that you can't activate several reporters at the same time unless you use the --reporters flag. But I ask again: do we really need to activate several reporters at the same time?

Or maybe we can just make it an array :

reporters: {
  list: [],
  default: ['spec','another'],
},

from runner.

Julien-R44 avatar Julien-R44 commented on June 1, 2024

Actually yes, having multiple reporters can be handy. Let's imagine that the user wants to have a json reporter that saves the result of the tests in a file but doesn't display anything in the console, but also to have the spec reporter. This is a bit of a stretch, but it could make sense

from runner.

thetutlage avatar thetutlage commented on June 1, 2024

Yeah, we can allow the default one to be an array and rename the property to be defaults.

So basically, you have a hardcoded set of defaults in the config. However, you can overwrite them using the --reporters flag

from runner.

Julien-R44 avatar Julien-R44 commented on June 1, 2024

Okay, that sounds nice. The only thing that bothers me a little is that it results in a breaking change. But at this point, I don't think we have much choice if we want to offer an API that's not too ugly

If it sounds okay for you, I'm willing to implement it this weekend

from runner.

Julien-R44 avatar Julien-R44 commented on June 1, 2024

Let me just recap:

  • We forget about the non breaking change attempt on the ReporterContract knowing that we have another breaking change, so not much interest except being error prone.
    This means that the contract of the reporter becomes the following :
type ReporterContract = 
   | { name: string; handler: ReporterHandler } 
   | ReporterHandler
  • Then, as you said, we keep that API for the configure function :
reporters: {
  list: [
     specReporter(),
     anotherReporter()
   ],
  defaults: ['spec','another'],
},

As simple as that !

from runner.

Julien-R44 avatar Julien-R44 commented on June 1, 2024

Actually, no, sorry. It is perfectly possible to make the thing non-breaking.

  • We keep my suggestion about the ReporterContract.
  • And finally, we do the same thing for the reporters configuration property. Basically: if reporters is an array, like in the current API, then we just enable all reporters. If it's an object, then we use the new system.

from runner.

thetutlage avatar thetutlage commented on June 1, 2024

Right now we do not have many 3rd party reporters. So, we can break the ReporterContract and ship them as major server. People won't have to change a line in their config.

For the config reporters property, yes, it can be backwards compatible.

from runner.

Julien-R44 avatar Julien-R44 commented on June 1, 2024

Yeah, I was mostly thinking of people that would potentially write an inline reporter. Or who would have just kept their reporter private. Very unlikely to be the case honestly, but possible.

from runner.

thetutlage avatar thetutlage commented on June 1, 2024

Yeah, but I think 0.1% chance of that. Also, we will mark it as a major release. Its just I do not want others to change their config too after the upgrade.

from runner.

Julien-R44 avatar Julien-R44 commented on June 1, 2024

Okay great. Thanks a lot for the feedback dude. I'll get right on it quickly!

from runner.

stale avatar stale commented on June 1, 2024

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

from runner.

stale avatar stale commented on June 1, 2024

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

from runner.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.