question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Pass through "file" option to reporters

See original GitHub issue

Expected Behavior

I can pass through the “file” option to reporters such as Cobertura in order to specify the report filename.

Observed Behavior

I cannot specify the report filename.

The following lines of code in nyc/index pass through only four options to each reporter:

// nyc/index.js
    this.reporter.forEach((_reporter) => {
      reports.create(_reporter, {
        skipEmpty: this.config.skipEmpty,
        skipFull: this.config.skipFull,
        projectRoot: this.cwd,
        maxCols: process.stdout.columns || 100
      }).execute(context)
    })

However, the reporters are configured to expect potentially more options than these. Here is an example from Cobertura:

// cobertura.index
    constructor(opts) {
        super();

        this.cw = null;
        this.xml = null;
        this.projectRoot = opts.projectRoot || process.cwd();
        this.file = opts.file || 'cobertura-coverage.xml';
    }

As you can see, the capability to specify the filename is already present via the option “file.” However, there is no way to pass it through. I would expect it to look something like this:

// nyc/index.js
    this.reporter.forEach((_reporter) => {
      reports.create(_reporter, {
        skipEmpty: this.config.skipEmpty,
        skipFull: this.config.skipFull,
        projectRoot: this.cwd,
        maxCols: process.stdout.columns || 100,
        file: this.config.reportFilename   <-- added line here
      }).execute(context)
    })

Environment Information

  System:
    OS: Windows 10 10.0.18362
    CPU: (8) x64 Intel(R) Core(TM) i7 CPU         880  @ 3.07GHz
    Memory: 7.40 GB / 15.96 GB
  Binaries:
    Node: 12.14.0 - C:\Program Files\nodejs\node.EXE
    npm: 6.13.4 - C:\Program Files\nodejs\npm.CMD
  npmPackages:
    nyc: ^15.0.0 => 15.0.0


Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:2
  • Comments:5

github_iconTop GitHub Comments

1reaction
danvkcommented, Feb 11, 2021

As it turns out, it’s not too hard to replicate what nyc report does in a script of your own and pass through the options you want. Here’s my script to get statement coverage with the html-spa reporter, @miyasudokoro presumably you could do something similar for the cobertura reporter and the file option.

(This is in TypeScript, you’ll have to compile to JS or run with ts-node to use it.)

import libReport from 'istanbul-lib-report';
import reports from 'istanbul-reports';
import NYC from 'nyc';

process.env.NYC_CWD = process.cwd();
const nyc = new NYC(process.argv);

(async () => {
  const {config} = nyc;
  const context = libReport.createContext({
    dir: nyc.reportDirectory(),
    watermarks: config.watermarks,
    coverageMap: await nyc.getCoverageMapFromAllCoverageFiles(),
  });

  (reports.create('html-spa', {
    skipEmpty: config.skipEmpty,
    metricsToShow: ['statements', 'lines', 'branches', 'functions'],
  }) as any).execute(context);
})().catch(e => {
  // eslint-disable-next-line no-console
  console.error(e);
});
0reactions
electrovircommented, Dec 1, 2022

I would love it if the entire configuration (this.config) was passed to the reporter.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Catch2/reporters.md at devel - GitHub
Reporters are a customization point for most of Catch2's output, e.g. formatting and writing out assertions (whether passing or failing), sections, test cases, ......
Read more >
Chef InSpec Reporters - Chef Documentation
Chef InSpec allows you to output your test results to one or more reporters. Configure the reporter(s) using either the --reporter option or...
Read more >
Content Scanning in File Reporter - YouTube
File Reporter provides the ability to scan file content with user-defined or custom pattern matching. Furthermore, it can automatically ...
Read more >
Reporters | Cypress Documentation
Some reporters accept options that customize their behavior. These can be specified in your Cypress configuration or via command line options. Reporter options...
Read more >
Reporter | Testomatio
Setting Report Title. Give a title to your reports by passing it as environment variable to TESTOMATIO_TITLE . TESTOMATIO={ ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found