From 1965f61da277ed30df5c8410e73f9b02a99c59f2 Mon Sep 17 00:00:00 2001 From: Eric Rowell Date: Mon, 30 Sep 2013 07:52:13 -0700 Subject: [PATCH] added assertion counter to Mocha --- test/runner.js | 47 +++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 45 insertions(+), 2 deletions(-) diff --git a/test/runner.js b/test/runner.js index 345e4ab8..5009d64a 100644 --- a/test/runner.js +++ b/test/runner.js @@ -1,6 +1,47 @@ mocha.ui('tdd'); var assert = chai.assert, - kineticContainer = document.getElementById('kinetic-container'); + kineticContainer = document.getElementById('kinetic-container'), + origAssertEqual = assert.equal, + origAssert = assert, + origNotEqual = assert.notEqual, + assertionCount = 0, + assertions = document.createElement('em'); + +function init() { + // assert extenders so that we can count assertions + assert = function() { + origAssert.apply(this, arguments); + assertions.innerHTML = ++assertionCount; + }; + assert.equal = function() { + origAssertEqual.apply(this, arguments); + assertions.innerHTML = ++assertionCount; + }; + assert.notEqual = function() { + origNotEqual.apply(this, arguments); + assertions.innerHTML = ++assertionCount; + }; + + window.onload = function() { + var mochaStats = document.getElementById('mocha-stats'); + + if (mochaStats) { + var li = document.createElement('li'); + var anchor = document.createElement('a'); + + anchor.href = '#'; + anchor.innerHTML = 'assertions:'; + assertions.innerHTML = 0; + + li.appendChild(anchor); + li.appendChild(assertions); + mochaStats.appendChild(li); + } + } +} + + + Kinetic.enableTrace = true; // make sure pixel ratio is 1 or else the tests will fail on devices with retina display @@ -46,4 +87,6 @@ beforeEach(function(){ Kinetic.inDblClickWindow = false; Kinetic.DD.isDragging = false; Kinetic.DD.node = undefined; -}); \ No newline at end of file +}); + +init(); \ No newline at end of file