TestFormat.js revision 9062ea13d64c4cc70df35e5e10a77e55f2029d41
Y.namespace("Test.Format");
/* (intentionally not documented)
* Basic XML escaping method. Replaces quotes, less-than, greater-than,
* apostrophe, and ampersand characters with their corresponding entities.
* @param {String} text The text to encode.
* @return {String} The XML-escaped text.
*/
switch(value){
case "\"": return """;
case "'": return "'";
case "&": return "&";
}
});
}
/**
* Returns test results formatted as a JSON string. Requires JSON utility.
* @param {Object} result The results object created by TestRunner.
* @return {String} A JSON-formatted string of results.
* @namespace Test.Format
* @method JSON
* @static
*/
};
/**
* Returns test results formatted as an XML string.
* @param {Object} result The results object created by TestRunner.
* @return {String} An XML-formatted string of results.
* @namespace Test.Format
* @method XML
* @static
*/
function serializeToXML(results){
var l = Y.Lang,
}
} else {
xml += " passed=\"" + results.passed + "\" failed=\"" + results.failed + "\" ignored=\"" + results.ignored + "\" total=\"" + results.total + "\">";
}
});
}
return xml;
}
};
/**
* Returns test results formatted in JUnit XML format.
* @param {Object} result The results object created by TestRunner.
* @return {String} An XML-formatted string of results.
* @namespace Test.Format
* @method JUnitXML
* @static
*/
function serializeToJUnitXML(results){
var l = Y.Lang,
xml = "";
//equivalent to testcase in JUnit
case "test":
xml += "<failure message=\"" + xmlEscape(results.message) + "\"><![CDATA[" + results.message + "]]></failure>";
}
xml+= "</testcase>";
}
break;
//equivalent to testsuite in JUnit
case "testcase":
xml = "<testsuite name=\"" + xmlEscape(results.name) + "\" tests=\"" + results.total + "\" failures=\"" + results.failed + "\">";
}
});
xml += "</testsuite>";
break;
//no JUnit equivalent, don't output anything
case "testsuite":
}
});
break;
//top-level, equivalent to testsuites in JUnit
case "report":
xml = "<testsuites>";
}
});
xml += "</testsuites>";
//no default
}
return xml;
}
};
/**
* Returns test results formatted in TAP format.
* @param {Object} result The results object created by TestRunner.
* @return {String} A TAP-formatted string of results.
* @namespace Test.Format
* @method TAP
* @static
*/
var currentTestNum = 1;
function serializeToTAP(results){
var l = Y.Lang,
text = "";
case "test":
}
text += "\n";
} else {
}
break;
case "testcase":
text = "#Begin testcase " + results.name + "(" + results.failed + " failed of " + results.total + ")\n";
}
});
break;
case "testsuite":
text = "#Begin testsuite " + results.name + "(" + results.failed + " failed of " + results.total + ")\n";
}
});
break;
case "report":
}
});
//no default
}
return text;
}
};