Bug 1252995 - Add a method to get lines and name of methods.
This method gets method names and the lines each method spans. It uses getAllOffsets to get the lines.
MozReview-Commit-ID: Df4kP11obq2
* * *
Bug 1252995 - GetMethodNames revision.
Fixed current issues.
* * *
Bug 1252995 - Fixed method names.
--- a/testing/modules/CoverageUtils.jsm
+++ b/testing/modules/CoverageUtils.jsm
@@ -131,16 +131,50 @@ CoverageCollector.prototype._getUncovere
for (let line of tempUncov[scriptName]){
uncoveredLines[scriptName].add(line);
}
}
return uncoveredLines;
}
+CoverageCollector.prototype._getMethodNames = function() {
+ let methodNames = {};
+ this._scripts.forEach(s => {
+ let method = s.displayName;
+ // If the method name is undefined, we return early
+ if (!method){
+ return;
+ }
+
+ let scriptName = s.url;
+ let tempMethodCov = [];
+ let scriptOffsets = s.getAllOffsets();
+
+ if (!methodNames[scriptName]){
+ methodNames[scriptName] = {};
+ }
+
+ /**
+ * Get all lines contained within the method and
+ * push a record of the form:
+ * <method name> : <lines covered>
+ */
+ scriptOffsets.forEach(function (element, index){
+ if (!element){
+ return;
+ }
+ tempMethodCov.push(index);
+ });
+ methodNames[scriptName][method] = tempMethodCov;
+ });
+
+ return methodNames;
+}
+
/**
* Records lines covered since the last time coverage was recorded,
* associating them with the given test name. The result is written
* to a json file in a specified directory.
*/
CoverageCollector.prototype.recordTestCoverage = function (testName) {
dump("Collecting coverage for: " + testName + "\n");
let rawLines = this._getLinesCovered(testName);