macaca-reporter
Version:
Reporter for mocha and other frameworks.
32 lines (24 loc) • 1.01 kB
JavaScript
const fs = require('fs');
const path = require('path');
const pkg = require('../package');
const _ = require('./common/helper');
const logger = require('./common/logger');
const {
chalk,
} = _;
module.exports = (data, opts) => {
const options = _.merge({
name: pkg.name,
distDir: process.cwd(),
}, opts);
// Support custom JSON file name by ths config:
// --reporter-options reportJSONFilename=index
const reportJSONFilename = opts.reporterOptions && opts.reporterOptions.reportJSONFilename || 'json-final';
const targetJSON = path.join(options.distDir, 'reports', `${reportJSONFilename}.json`);
fs.writeFileSync(targetJSON, _.powerJSONStringify(data, null, 2), 'utf8');
logger.info(chalk.cyan(`json reporter generated: ${targetJSON}`));
const configJSON = path.join(options.distDir, 'reports', 'config.json');
fs.writeFileSync(configJSON, _.powerJSONStringify(options, null, 2), 'utf8');
logger.info(chalk.cyan(`reporter config generated: ${configJSON}`));
};
;