Skip to content
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

Customize reporter by options? #513

Open
jjangga0214 opened this issue Dec 18, 2019 · 9 comments
Open

Customize reporter by options? #513

jjangga0214 opened this issue Dec 18, 2019 · 9 comments

Comments

@jjangga0214
Copy link

Hi,

can we customize reporters by options or configuration?

Like, to say, "dark mode" or "title" on html reporter.

@coreyfarrell
Copy link
Member

I've opened #506 for adding dark mode. The plan is that this would be accomplished through CSS @media (prefers-color-scheme: dark) rather than a report option, so your browser would decide if it wanted to use the dark theme or not. There is no option to control the title of html reporters. I'm unsure from your report how you are using istanbul reports (nyc, jest, other) so I cannot say if it's possible for you to set custom options to reports. NYC only supports setting specific options which apply to reports, I don't think I'd be open to adding an option to NYC for controlling the title of html reports. The issue is that NYC is very complex and I have to try avoiding option overload.

@jjangga0214
Copy link
Author

jjangga0214 commented Dec 18, 2019

@coreyfarrell Good to hear the explanation!
I'm using Jest. Can I configure report-specific options with Jest at all?
(Jest's docs only explain about how to generate coverage(--coverage) and choose reporter(coverageReporters) .)

By the way, what I meant by "title" option was to change "All files"(photo below) or browser's tab title to what I want. (Because I generate multiple coverages in monorepo, and thought It'd be convenient if the title of the html page can be each subproject's name)

Screenshot from 2019-12-18 18-18-14

@coreyfarrell
Copy link
Member

I'm not actually that familiar with jest so I don't know if it has the ability to configure per report options. That said we don't have an option to configure the All files option.

One thought for a monorepo I would generally produce a merged report for the whole repo though I don't know how that would be accomplished using jest. The istanbuljs monorepo uses nyc for it's own coverage. Each module is tested from packages/*, then the posttest of the root package.json runs https://github.com/istanbuljs/istanbuljs/blob/master/monorepo-merge-reports.js before nyc report. This causes the istanbuljs monorepo to generate a single coverage report relative to the monorepo root rather than a separate report relative to each package.

@SimenB
Copy link
Member

SimenB commented Dec 18, 2019

It's currently unsupported, but I'd happily merge a PR to jest adding support for passing options to coverageReporters similar to how you can pass options to reporters today 👍

Regarding monorepos - jest is in a monorepo and it runs all of its test in a single run from root. Since we transpile we also map paths from build/ to src (using https://github.com/facebook/jest/blob/master/scripts/mapCoverage.js), but that may or may not be necessary for you.

@jjangga0214
Copy link
Author

jjangga0214 commented Dec 20, 2019

@coreyfarrell @SimenB
Thanks for the response!

As like @SimenB mentioned, running jest on the repo's root level generates a single merged coverage report. (By the way, mapping from build to src is not required in my personal setting, with ts-jest, but of course thanks for sharing the info)

However, while developing, I usually generate coverage reports only for a few specific packages, not the entire monorepo, to save time. In that situation, I feet it'd be convenient if "title" is configurable, to make it visually very clear which package report I'm reading, as there would be several indepedent report tabs in the web browser.

@jjangga0214
Copy link
Author

@SimenB
By the way, I might have to merge reports in a way like @coreyfarrell mentioned, if I use jest with other test runners. However, jest has nyc built-in, and nyc jest throws an error. Would there be a way to use jest explicitly with nyc?

@SimenB
Copy link
Member

SimenB commented Dec 20, 2019

Nope, that's not supported. You can use nyc on the coverage reports that are output in the coverage directory, though (or custom coverageDirectory if you've set that)

@jjangga0214
Copy link
Author

jjangga0214 commented Dec 20, 2019

@SimenB

You can use nyc on the coverage reports

If existent, may I ask a link to usage docs for it?

# Generate ./jest-coverage, with json, html reporter, for example
npm run test:byjest # this runs `jest --coverage`

# Generate ./foo-coverage, with json and html reporter, for example
npm run test:byfoo 

# Do magic. This generates merged json and html reports.  
# But how?
nyc magic 

@coreyfarrell
Copy link
Member

We don't have docs directly for this specific use case but an example is https://github.com/istanbuljs/istanbuljs/blob/master/monorepo-merge-reports.js. This script is run by the posttest script at the monorepo root. The monorepo-merge-reports.js script spawn nyc merge .nyc_output ../../.nyc_output/istanbul-lib-instrument.json from cwd of packages/istanbul-lib-instrument. Note jest does not actually depend on nyc so you'd need to make sure you installed it on your own and ensure that the nyc you install uses the same version of istanbul-lib-coverage as jest.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants