From 3160e696df8993d7fb33978f9eae8867bfdc905a Mon Sep 17 00:00:00 2001 From: Jim Witschey Date: Mon, 28 Jul 2014 14:06:14 -0400 Subject: [PATCH] fixes non-browser-based tests --- archive/v0.1.19/mithril-tests.js | 50 ++++++++++++++++++++++++++++---- tests/mithril-tests.js | 14 +++++---- tests/test.js | 49 ++++++++++++++++--------------- 3 files changed, 79 insertions(+), 34 deletions(-) diff --git a/archive/v0.1.19/mithril-tests.js b/archive/v0.1.19/mithril-tests.js index 6367c542..401f832e 100644 --- a/archive/v0.1.19/mithril-tests.js +++ b/archive/v0.1.19/mithril-tests.js @@ -674,9 +674,39 @@ if (typeof define == "function" && define.amd) define(function() {return m}) ;;; function test(condition) { - try {if (!condition()) throw new Error} - catch (e) {console.error(e);test.failures.push(condition)} + var duration = 0; + var start = 0; + var result = true; test.total++ + + if (typeof window != "undefined") { + if (typeof performance != "undefined") { + start = performance.now(); + } + try {if (!condition()) throw new Error} + catch (e) {result = false;console.error(e);test.failures.push(condition)} + if (typeof performance != "undefined") { + duration = performance.now() - start; + } + + + test_obj = { + name: "" + test.total, + result: result, + duration: duration + } + if (!result) { + message: "failed: " + condition, + window.global_test_results.tests.push(test_obj) + } + + window.global_test_results.duration += duration; + if (result) { + window.global_test_results.passed++; + } else { + window.global_test_results.failed++; + } + } } test.total = 0 test.failures = [] @@ -2381,7 +2411,17 @@ function testMithril(mock) { } -//mocks -testMithril(mock.window) +//test reporting for saucelabs +if (typeof window != "undefined") { + window.global_test_results = { + tests: [], + duration: 0, + passed: 0, + failed: 0 + }; +} -test.print(console.log) +//mock +testMithril(mock.window); + +test.print(function(value){console.log(value)}); \ No newline at end of file diff --git a/tests/mithril-tests.js b/tests/mithril-tests.js index c92e55ed..7142e5ac 100644 --- a/tests/mithril-tests.js +++ b/tests/mithril-tests.js @@ -1576,12 +1576,14 @@ function testMithril(mock) { } //test reporting for saucelabs -window.global_test_results = { - tests: [], - duration: 0, - passed: 0, - failed: 0 -}; +if (typeof window != "undefined") { + window.global_test_results = { + tests: [], + duration: 0, + passed: 0, + failed: 0 + }; +} //mock testMithril(mock.window); diff --git a/tests/test.js b/tests/test.js index a24f2412..025d8216 100644 --- a/tests/test.js +++ b/tests/test.js @@ -2,32 +2,35 @@ function test(condition) { var duration = 0; var start = 0; var result = true; - if (performance.now) { - start = performance.now(); - } - try {if (!condition()) throw new Error} - catch (e) {result = false;console.error(e);test.failures.push(condition)} - if (performance.now) { - duration = performance.now() - start; - } - test.total++ - test_obj = { - name: "" + test.total, - result: result, - duration: duration - } - if (!result) { - message: "failed: " + condition, - window.global_test_results.tests.push(test_obj) - } + if (typeof window != "undefined") { + if (typeof performance != "undefined") { + start = performance.now(); + } + try {if (!condition()) throw new Error} + catch (e) {result = false;console.error(e);test.failures.push(condition)} + if (typeof performance != "undefined") { + duration = performance.now() - start; + } - window.global_test_results.duration += duration; - if (result) { - window.global_test_results.passed++; - } else { - window.global_test_results.failed++; + + test_obj = { + name: "" + test.total, + result: result, + duration: duration + } + if (!result) { + message: "failed: " + condition, + window.global_test_results.tests.push(test_obj) + } + + window.global_test_results.duration += duration; + if (result) { + window.global_test_results.passed++; + } else { + window.global_test_results.failed++; + } } } test.total = 0