Skip to content

Commit

Permalink
Merge pull request #62 from alanning/patch-1
Browse files Browse the repository at this point in the history
Fix Issue #59 - junit reports not writing in nodejs
  • Loading branch information
putermancer committed Jul 2, 2014
2 parents 8fa5faa + 7816b5a commit 6d8144f
Showing 1 changed file with 46 additions and 15 deletions.
61 changes: 46 additions & 15 deletions src/jasmine.junit_reporter.js
Expand Up @@ -159,17 +159,18 @@
},

writeFile: function(path, filename, text) {
var errors = [];

function getQualifiedFilename(separator) {
if (path && path.substr(-1) !== separator && filename.substr(0) !== separator) {
path += separator;
if (separator && path && path.substr(-1) !== separator && filename.substr(0) !== separator) {
return path + separator + filename;
}
return path + filename;
}

// Rhino
try {
// turn filename into a qualified path
function rhinoWrite (path, filename, text) {
if (path) {
// turn filename into a qualified path
filename = getQualifiedFilename(java.lang.System.getProperty("file.separator"));
// create parent dir and ancestors if necessary
var file = java.io.File(filename);
Expand All @@ -182,26 +183,56 @@
var out = new java.io.BufferedWriter(new java.io.FileWriter(filename));
out.write(text);
out.close();
return;
} catch (e) {}
// PhantomJS, via a method injected by phantomjs-testrunner.js
try {
}

function phantomWrite (path, filename, text) {
// turn filename into a qualified path
filename = getQualifiedFilename(window.fs_path_separator);

// PhantomJS, via a method injected by phantomjs-testrunner.js
__phantom_writeFile(filename, text);
return;
} catch (f) {}
// Node.js
try {
}

function nodeWrite (path, filename, text) {
var fs = require("fs");
var nodejs_path = require("path");
var fd = fs.openSync(nodejs_path.join(path, filename), "w");
var filepath = nodejs_path.join(path, filename)
var fd = fs.openSync(filepath, "w");
fs.writeSync(fd, text, 0);
fs.closeSync(fd);
}


// Attempt writing with each possible environment.
// Track errors in case no write succeeds
try {
rhinoWrite(path, filename, text);
return;
} catch (g) {}
} catch (e) {
errors.push(' Rhino attempt: ' + e.message);
}

try {
phantomWrite(path, filename, text);
return;
} catch (f) {
errors.push(' PhantomJs attempt: ' + f.message);
}

try {
nodeWrite(path, filename, text);
return;
} catch (g) {
errors.push(' NodeJS attempt: ' + g.message);
}

// If made it here, no write succeeded. Let user know.
this.log("Warning: writing junit report failed for '" + path + "', '" +
filename + "'. Reasons:\n" +
errors.join("\n"));
},


getFullName: function(suite, isFilename) {
var fullName;
if (this.useDotNotation) {
Expand Down

0 comments on commit 6d8144f

Please sign in to comment.