app/assets/javascripts/konacha/runner.js in konacha-2.0.0.beta2 vs app/assets/javascripts/konacha/runner.js in konacha-2.0.0.beta3

- old
+ new

@@ -1,45 +1,70 @@ Konacha = { - dots: "", - getResults: function() { - return JSON.stringify(Konacha.results); + getEvents: function() { + return JSON.stringify(Konacha.events); } }; mocha.reporter(function(runner) { + var createTestObject = function(test, status) { + var obj = { + title:test.title, + fullTitle:test.fullTitle(), + duration:test.duration, + parentFullTitle:test.parent.fullTitle(), + status:status + }; + + if (status == "failed") + obj.error = test.err; // Contains message, expected, actual, operator, stack + + return obj; + }; + + var createSuiteObject = function(suite) { + var obj = { + title:suite.title, + fullTitle:suite.fullTitle() + }; + + if (suite.parent) + obj.parentFullTitle = suite.parent.fullTitle(); + + return obj; + }; + Mocha.reporters.Base.call(this, runner); runner.on('start', function() { - Konacha.results = []; + Konacha.events = []; }); + runner.on('suite', function(suite) { + if (suite.fullTitle() && suite.fullTitle().length > 0) + Konacha.events.push({event:'suite', data:createSuiteObject(suite), type:'suite'}); + }); + + runner.on('test', function(test) { + Konacha.events.push({event:'test', data:createTestObject(test), type:'test'}); + }); + runner.on('pass', function(test) { - Konacha.dots += "."; - Konacha.results.push({ - name:test.title, - passed:true - }); + Konacha.events.push({event:'pass', data:createTestObject(test, "passed"), type:'test'}); }); runner.on('fail', function(test) { - Konacha.dots += "F"; - Konacha.results.push({ - name:test.title, - passed:false, - message:test.err.message, - trace:test.err.stack - }); + Konacha.events.push({event:'fail', data:createTestObject(test, "failed"), type:'test'}); }); runner.on('pending', function(test) { - Konacha.dots += "P"; - Konacha.results.push({ - name:test.title, - passed:false, - pending:true - }); + Konacha.events.push({event:'pending', data:createTestObject(test, "pending"), type:'test'}); }); + runner.on('suite end', function(suite) { + if (suite.fullTitle() && suite.fullTitle().length > 0) + Konacha.events.push({event:'suite end', data:createSuiteObject(suite), type:'suite'}); + }); + runner.on('end', function() { - Konacha.done = true; + Konacha.events.push({event:'end', data:{}}); }); });