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

Pass options to coverageReporter #4103

Closed
SimenB opened this issue Jul 21, 2017 · 6 comments · Fixed by #9572
Closed

Pass options to coverageReporter #4103

SimenB opened this issue Jul 21, 2017 · 6 comments · Fixed by #9572

Comments

@SimenB
Copy link
Member

SimenB commented Jul 21, 2017

Do you want to request a feature or report a bug?
Feature

What is the current behavior?
Trying to pass options to a coverage reporter (like you can with a normal reporter) fails with

        Failed to write coverage reports:
        ERROR: Error: Invalid report format [text,[object Object]]

The reporter supports options: https://github.com/gotwarlost/istanbul/blob/bc84c315271a5dd4d39bcefc5925cfb61a3d174a/lib/report/text.js#L38-L46

If the current behavior is a bug, please provide the steps to reproduce and either a repl.it demo through https://repl.it/languages/jest or a minimal repository on GitHub that we can yarn install and yarn test.

Config

"jest": {
    "coverageReporters": [
      [
        "text",
        {
          "watermark": {
            "statements": [
              50,
              80
            ],
            "lines": [
              50,
              80
            ],
            "functions": [
              50,
              80
            ],
            "branches": [
              20,
              80
            ]
          }
        }
      ]
    ]
}

Then just run jest --coverage.

What is the expected behavior?
I should be able to pass options to coverage reporters just like normal reporters, as can be seen in its docs: https://facebook.github.io/jest/docs/en/configuration.html#reporters-array-modulename-modulename-options

Please provide your exact Jest configuration and mention your Jest, node, yarn/npm version and operating system.
Jest@20.0.4, node@6.11.1, yarn@0.27.5

@jjshinobi

This comment has been minimized.

@rockshandy
Copy link

Any updates on this? This just bit me I was trying to change the filename of a coverage report through cobertura.

@SimenB
Copy link
Member Author

SimenB commented Jun 13, 2018

No news. PR welcome, though! 🙂

@alexander-elgin
Copy link

I need the feature too. It will allow me to customize text reporter to show not fully covered items only.

@SimenB
Copy link
Member Author

SimenB commented Aug 17, 2018

Jest only calls Istanbul's createReporter and does a reporter.addAll(config.coverageReporters). Istanbul's code is here: https://github.com/istanbuljs/istanbuljs/blob/master/packages/istanbul-api/lib/reporter.js

Seems like we need to pass config to the createReporter call, and it somehow figures out which config is for which reporter later (https://github.com/istanbuljs/istanbuljs/blob/829e658dfa91e3a9533842be9ce940dbe7785c09/packages/istanbul-api/lib/reporter.js#L42-L43).

Jest's logic is here: https://github.com/facebook/jest/blob/08cb885400c538c6f934680adc3d0b51200a0228/packages/jest-cli/src/reporters/coverage_reporter.js#L90-L106

Logic for separating reporter names and config in Jest is in TestScheduler.js, that should probably be extracted (to handle turning Array<string | [string, Object]> into something a bit more usable)

@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 11, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants