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

Add error stack to clean function #1

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 14 additions & 15 deletions lib/index.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
/**
* Expose `JSON`.
*/
var util = require('util'),
fs = require('fs')
let fs = require('fs')

var mocha = require('mocha');
var Base = mocha.reporters.Base
let mocha = require('mocha');
let Base = mocha.reporters.Base
, cursor = Base.cursor
, color = Base.color;

Expand All @@ -19,10 +18,10 @@ module.exports = JSONFileReporter;
*/

function JSONFileReporter(runner) {
var self = this;
let self = this;
Base.call(this, runner);

var tests = []
let tests = []
, failures = []
, passes = [];

Expand All @@ -39,28 +38,27 @@ function JSONFileReporter(runner) {
});

runner.on('end', function(){
var obj = {
let obj = {
stats: self.stats
, tests: tests.map(clean)
, failures: failures.map(clean)
, passes: passes.map(clean)
};
var jsonOutput = JSON.stringify(obj, null, 2);
process.stdout.write(jsonOutput);
let jsonOutput = JSON.stringify(obj, null, 2);

try {
util.print("\nGenerating report.json file")
var path = "./";
console.log("\nGenerating report.json file")
let path = "./";
if(process.env.REPORT_PATH){
path = process.env.REPORT_PATH
}
var out = fs.openSync(path+"/report.json", "w");
let out = fs.openSync(path+"/report.json", "w");

fs.writeSync(out, jsonOutput);
fs.close(out);
util.print("\nGenerating report.json file complete in "+path+"\n")
fs.closeSync(out);
console.log("\nGenerating report.json file complete in "+path+"\n")
} catch (error) {
util.print("\nError: Unable to write to file report.json\n");
console.log("\nError: Unable to write to file report.json\n");
}
});
}
Expand All @@ -79,5 +77,6 @@ function clean(test) {
title: test.title
, fullTitle: test.fullTitle()
, duration: test.duration
, err: test.err
}
}