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

json reporter output path not working #108

Open
ramzes13 opened this issue Jan 9, 2023 · 1 comment
Open

json reporter output path not working #108

ramzes13 opened this issue Jan 9, 2023 · 1 comment

Comments

@ramzes13
Copy link

ramzes13 commented Jan 9, 2023

Expected behavior

To be generated, the file test-report.json

Actual behavior

All output is redirected to console

Installed packages:

    "mocha": "^10.0.0",
    "mocha-multi-reporters": "^1.5.1",

Steps to reproduce the behavior

npm script:

    "mocha": "TZ=UTC NODE_ENV=mocha ts-mocha \"test/**/*.test.ts\" --exit --recursive --timeout 30000 --reporter mocha-multi-reporters --reporter-options configFile=mocha-multi-reporter-config.json",

mocha-multi-reporter-config.json content:

{
  "reporterEnabled": "spec, json",
  "jsonReporterOptions": {
    "output": "test-report.json"
  }
}
@Danielku15
Copy link

This library is not compatible with the latest Mocha anymore. mocha-multi-reporters uses reportOptions (plural) while Mocha internally uses nowadays reportOption (singular). Any custom options don't make it through to Mocha.

I simply made my own reporter like this:

ci-reporter.js

const BaseReporter = require('mocha/lib/reporters/base');
const SpecReporter = require('mocha/lib/reporters/spec');
const JsonReporter = require('mocha/lib/reporters/json');

module.exports = class MultiReporter extends BaseReporter {
  reporters;

  constructor(runner, options) {
    super(runner, options);
    this.reporters = [
      new SpecReporter(runner, {
        reporterOption: options.reporterOption.specReporterOption,
      }),
      new JsonReporter(runner, {
        reporterOption: options.reporterOption.jsonReporterOption,
      }),
    ];
  }
};

.mocharc.js

const path = require('path');
module.exports = {
  reporter: path.join(__dirname, 'ci-reporter.js'),
  reporterOption: {
    jsonReporterOption: {
      output: path.join(__dirname, `test-results.json`),
    }
  }
}

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

2 participants