From 2526758233679b133aeeacfa9695a48fc408ec9f Mon Sep 17 00:00:00 2001 From: Reid Burke Date: Fri, 28 Feb 2014 16:38:01 -0800 Subject: [PATCH] Fix #78, collect moduleless QUnit test results. The old implementation required moduleDone in order to collect test results. This change introduces changes that allow results to be sent even without modules by using testStart and testDone APIs. --- lib/hub/view/public/inject.js | 73 +++++++++++++++++++++-------------- 1 file changed, 43 insertions(+), 30 deletions(-) diff --git a/lib/hub/view/public/inject.js b/lib/hub/view/public/inject.js index 3405584b..9859b3ed 100644 --- a/lib/hub/view/public/inject.js +++ b/lib/hub/view/public/inject.js @@ -75,6 +75,7 @@ window.$yetify = function (options) { data = {}, tests = {}, count = 1, + curModuleName = "", curTestName; function complete(results) { @@ -105,7 +106,19 @@ window.$yetify = function (options) { return result.message || ""; } - qunit.log = function (test) { + function formatTests() { + var i, out = {}; + for (i in tests) { + out[tests[i].name] = { + result: tests[i].result, + message: message(tests[i]), + name: tests[i].name + }; + } + return out; + } + + qunit.log(function (test) { tests["test" + count] = { message: test.message, result: (test.result) ? test.result : "fail", @@ -115,46 +128,46 @@ window.$yetify = function (options) { }; count = count + 1; - }; + }); - qunit.moduleStart = function (test) { + qunit.testStart(function (test) { curTestName = test.name; - }; + }); - qunit.moduleDone = function (test) { - var testName = curTestName, - i; + qunit.testDone(function (test) { + var module = formatTests(), + name = curModuleName + curTestName; - data[testName] = { - name: testName, - passed: test.passed, - failed: test.failed, - total: test.total - }; + module.name = name; + module.passed = test.passed; + module.failed = test.failed; + module.total = test.total; - for (i in tests) { - data[testName][tests[i].name] = { - result: tests[i].result, - message: message(tests[i]), - name: tests[i].name - }; - } + data[name] = module; tests = {}; count = 1; - }; + }); - qunit.done = function (tests) { - var results = data; + qunit.moduleStart(function (test) { + curModuleName = test.name + ": "; + }); - results.passed = tests.passed; - results.failed = tests.failed; - results.total = tests.total; - results.duration = tests.runtime; - results.name = document.title; + qunit.moduleDone(function (test) { + curModuleName = ""; + }); - complete(results); - }; + qunit.done(function (tests) { + data = Y.merge(formatTests(), data); + + data.passed = tests.passed; + data.failed = tests.failed; + data.total = tests.total; + data.duration = tests.runtime; + data.name = document.title; + + complete(data); + }); qunit.start(); }