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

Allow mocha reporter file output #149

Closed
wants to merge 2 commits into from
Closed

Allow mocha reporter file output #149

wants to merge 2 commits into from

Conversation

truevektordev
Copy link

This change allows reporters to output to a file simply by setting the CLI arg --reporterFile. Anything in reporter.output will be written to the file.

added new command line parameter --reporterFile
write contents of reporterInstance.output to file at --reporterFile
@truevektordev
Copy link
Author

Example reporter that "writes" to a file:

var spec = require('./spec');
var Base = require('./base');


function FileReporter(runner) {
    spec.call(this, runner);

    var stats = this.stats;
    this.output = "";

    var _this = this;

    runner.on('end', function() {
        _this.output = "Tests: " + stats.tests + "\n";
        _this.output += "Failures: " + stats.failures + "\n";
        _this.output += "Skipped: " + (stats.tests - stats.failures - stats.passes);
    });
}

FileReporter.prototype.__proto__ = Base.prototype;

exports = module.exports = FileReporter;

@nathanboktae
Copy link
Owner

We already have this feature. --file does exactly what you added, except without tests and a bug (you don't close the file).

@truevektordev
Copy link
Author

You have a point about closing the file and including tests. I'll get some tests added and actually close the file...

The --file feature does not work for things like outputting an xunit file since all output (including console.log - see #133) is sent to the file. This allows the reporter to be the only thing outputting to the file without having to remove console.log from code (which isn't always possible depending on external libraries being used).

If you think a different approach (besides removing console.log statements) would be better, please let me know.

Thanks!

@nathanboktae
Copy link
Owner

If you have to write a custom reporter anyways, then write one that uses process.stdout.write and use the existing --file feature.

@nathanboktae
Copy link
Owner

Not to mention we also have the hooks feature (#99) which you can dump output to a file with (yes we need better documentation on that feature).

@truevektordev
Copy link
Author

Okay, I'll see if I can get hooks to work instead and then probably submit a pull request for README.md to outline the feature a little better.

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

Successfully merging this pull request may close these issues.

2 participants