Skip to content
This repository has been archived by the owner on Feb 26, 2022. It is now read-only.

Commit

Permalink
Merge pull request #624 from gregglind/coverage
Browse files Browse the repository at this point in the history
Bug 789401 - CoverObject, work in progress r=@Gozala
  • Loading branch information
Gozala committed Jan 7, 2013
2 parents 532a51a + fa2458d commit 2b94404
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion lib/sdk/test/harness.js
Expand Up @@ -185,6 +185,7 @@ function showResults() {
}

function cleanup() {
let coverObject = {};
try {
for (let name in loader.modules)
memory.track(loader.modules[name],
Expand All @@ -211,6 +212,11 @@ function cleanup() {
"be indicative of aberrant behavior.");
}

// read the code coverage object, if it exists, from CoverJS-moz
if (typeof loader.globals.global == "object") {
coverObject = loader.globals.global['__$coverObject'];
}

consoleListener.errorsLogged = 0;
loader = null;

Expand All @@ -222,6 +228,21 @@ function cleanup() {
};

setTimeout(showResults, 1);

// dump the coverobject
if (Object.keys(coverObject).length){
const self = require('self');
const {pathFor} = require("sdk/system");
let file = require('file');
const {env} = require('sdk/system/environment');
console.log("CWD:", env.PWD);
let out = file.join(env.PWD,'coverstats-'+self.id+'.json');
console.log('coverstats:', out);
let outfh = file.open(out,'w');
outfh.write(JSON.stringify(coverObject,null,2));
outfh.flush();
outfh.close();
}
}

function nextIteration(tests) {
Expand Down Expand Up @@ -416,7 +437,8 @@ var runTests = exports.runTests = function runTests(options) {
testConsole = new TestRunnerConsole(new PlainTextConsole(print), options);

loader = Loader(module, {
console: testConsole
console: testConsole,
global: {} // useful for storing things like coverage testing.
});

nextIteration();
Expand Down

0 comments on commit 2b94404

Please sign in to comment.