New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

jasmine-reporters

Package Overview
Dependencies
Maintainers
1
Versions
31
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

jasmine-reporters - npm Package Compare versions

Comparing version

to
1.0.0

2

package.json

@@ -5,3 +5,3 @@ {

"description": "Reporters for the Jasmine BDD Framework",
"version": "0.4.1",
"version": "1.0.0",
"homepage": "https://github.com/larrymyers/jasmine-reporters",

@@ -8,0 +8,0 @@ "maintainers": "Ben Loveridge <bloveridge@gmail.com>",

@@ -64,3 +64,5 @@ (function() {

if (spec.results().passed()) {
if (spec.results().skipped ) {
resultText = 'Skipped.';
} else if (spec.results().passed()) {
this.passed_specs++;

@@ -67,0 +69,0 @@ resultText = "Passed.";

@@ -39,16 +39,20 @@ (function() {

*
* @param {string} savePath where to save the files
* @param {boolean} consolidate whether to save nested describes within the
* @param {string} [savePath] where to save the files
* @param {boolean} [consolidate] whether to save nested describes within the
* same file as their parent; default: true
* @param {boolean} useDotNotation whether to separate suite names with
* @param {boolean} [useDotNotation] whether to separate suite names with
* dots rather than spaces (ie "Class.init" not
* "Class init"); default: true
* @param {string} filePrefix is the string value that is prepended to the
* xml output file; default: 'TEST-'
* @param {string} [filePrefix] is the string value that is prepended to the
* xml output file; default: 'TEST-'
* @param {boolean} [consolidateAll] whether to save test results from different
* specs all in a single file; filePrefix is then the whole file
* name without extension; default: false
*/
var JUnitXmlReporter = function(savePath, consolidate, useDotNotation, filePrefix) {
var JUnitXmlReporter = function(savePath, consolidate, useDotNotation, filePrefix, consolidateAll) {
this.savePath = savePath || '';
this.consolidate = consolidate === jasmine.undefined ? true : consolidate;
this.consolidateAll = consolidateAll === jasmine.undefined ? false : consolidateAll;
this.useDotNotation = useDotNotation === jasmine.undefined ? true : useDotNotation;
this.filePrefix = filePrefix || 'TEST-';
this.filePrefix = filePrefix || (this.consolidateAll ? 'junitresults' : 'TEST-');
};

@@ -130,16 +134,28 @@ JUnitXmlReporter.started_at = null; // will be updated when test runner start

reportRunnerResults: function(runner) {
var fileName;
if (this.consolidateAll) {
fileName = this.filePrefix + '.xml';
var output = '<?xml version="1.0" encoding="UTF-8" ?>';
output += "\n<testsuites>";
}
var suites = runner.suites();
for (var i = 0; i < suites.length; i++) {
var suite = suites[i];
var fileName = this.filePrefix + this.getFullName(suite, true) + '.xml';
var output = '<?xml version="1.0" encoding="UTF-8" ?>';
fileName = this.consolidateAll ? fileName : this.filePrefix + this.getFullName(suite, true) + '.xml';
if (!this.consolidateAll) {
var output = '<?xml version="1.0" encoding="UTF-8" ?>';
}
// if we are consolidating, only write out top-level suites
if (this.consolidate && suite.parentSuite) {
if ((this.consolidate || this.consolidateAll) && suite.parentSuite) {
continue;
}
else if (this.consolidate) {
output += "\n<testsuites>";
else if (this.consolidate || this.consolidateAll) {
if (!this.consolidateAll) {
output += "\n<testsuites>";
}
output += this.getNestedOutput(suite);
output += "\n</testsuites>";
this.writeFile(this.savePath, fileName, output);
if (!this.consolidateAll) {
output += "\n</testsuites>";
this.writeFile(this.savePath, fileName, output);
}
}

@@ -151,2 +167,6 @@ else {

}
if (this.consolidateAll) {
output += "\n</testsuites>";
this.writeFile(this.savePath, fileName, output);
}
// When all done, make it known on JUnitXmlReporter

@@ -165,5 +185,7 @@ JUnitXmlReporter.finished_at = (new Date()).getTime();

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;
}

@@ -173,6 +195,5 @@ 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"));

@@ -190,22 +211,51 @@ // create parent dir and ancestors if necessary

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);
// write 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) {

@@ -212,0 +262,0 @@ var fullName;

@@ -118,2 +118,3 @@ /* globals jasmine */

writeFile: function(text) {
var errors = [];
var path = this.savePath;

@@ -128,6 +129,5 @@ var filename = this.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"));

@@ -145,20 +145,48 @@ // create parent dir and ancestors if necessary

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);
// write 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.
console.log("Warning: writing junit report failed for '" + path + "', '" +
filename + "'. Reasons:\n" +
errors.join("\n")
);
}

@@ -165,0 +193,0 @@ };

@@ -188,3 +188,3 @@ (function(){

describe("consolidated is true", function(){
describe("consolidated is true and consolidatedAll is false", function(){
beforeEach(function(){

@@ -209,3 +209,3 @@ reporter.reportRunnerResults(runner);

describe("consolidated is false", function(){
describe("consolidated is false and consolidatedAll is false", function(){
beforeEach(function(){

@@ -228,2 +228,20 @@ reporter.consolidate = false;

describe("consolidatedAll is true", function(){
beforeEach(function(){
reporter.consolidateAll = true;
reporter.reportRunnerResults(runner);
});
it("should write one file for all test suites", function(){
expect(reporter.writeFile.callCount).toEqual(1);
});
it("should consolidate suites output", function(){
expect(reporter.getNestedOutput.callCount).toEqual(4);
});
it("should wrap output in <testsuites>", function(){
expect(reporter.writeFile.mostRecentCall.args[2]).toContain("<testsuites>");
});
it("should include xml header in the file", function(){
expect(reporter.writeFile.argsForCall[0][2]).toContain("<?xml");
});
});
describe("dot notation is true", function(){

@@ -230,0 +248,0 @@ beforeEach(function(){

@@ -128,3 +128,3 @@ /* globals jasmine, phantom */

};
}, {resultsObj: key, fs_path_separator: path_separator});
}, {resultsObj: key, fs_path_separator: path_separator.replace("\\", "\\\\")});
}

@@ -131,0 +131,0 @@