Refactor the way test.html runs tests to be similar to how Cakefile runs them; most importantly, tests fail when the test function throws an exception, not when ok does (which happens intentionally a few times in the classes tests); this also produces a more accurate count of tests run

This commit is contained in:
Geoffrey Booth
2016-11-30 00:34:07 -08:00
parent cf3a27259a
commit d99ae0e7ef

View File

@@ -37,12 +37,9 @@
<pre id="stdout"></pre>
<script type="text/coffeescript">
@global = window
@testingBrowser = yes
@global = window
stdout = document.getElementById 'stdout'
desc = ''
fnStr = ''
start = new Date
success = total = done = failed = 0
@@ -54,13 +51,18 @@ say = (msg, className) ->
msg
@test = (description, fn) ->
desc = description
fnStr = fn.toString() if fn.toString?
fn()
++total
try
fn.call(fn)
++success
catch exception
say "#{description}:", 'bad'
say fn.toString(), 'subtle' if fn.toString?
say exception, 'bad'
console.error exception
@ok = (good, msg = 'Error') ->
++total
if good then ++success else throw Error msg
throw Error msg unless good
# Polyfill Node assert's fail
@fail = ->
@@ -94,16 +96,9 @@ say = (msg, className) ->
# Run the tests
for test in document.getElementsByClassName 'test'
say '\u2714 ' + test.id
try
options = {}
options.literate = yes if test.type is 'text/x-literate-coffeescript'
CoffeeScript.run test.innerHTML, options
catch exception
# debugger
say "#{desc}:", 'bad'
say fnStr, 'subtle'
say exception, 'bad'
console.error exception
options = {}
options.literate = yes if test.type is 'text/x-literate-coffeescript'
CoffeeScript.run test.innerHTML, options
# Finish up
yay = success is total and not failed