Skip to content

Commit

Permalink
Refactor the way test.html runs tests to be similar to how Cakefile r…
Browse files Browse the repository at this point in the history
…uns 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
  • Loading branch information
GeoffreyBooth committed Nov 30, 2016
1 parent cf3a272 commit d99ae0e
Showing 1 changed file with 14 additions and 19 deletions.
33 changes: 14 additions & 19 deletions documentation/test.html
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,9 @@ <h1>CoffeeScript Test Suite</h1>
<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

Expand All @@ -54,13 +51,18 @@ <h1>CoffeeScript Test Suite</h1>
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 = ->
Expand Down Expand Up @@ -94,16 +96,9 @@ <h1>CoffeeScript Test Suite</h1>
# 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
Expand Down

0 comments on commit d99ae0e

Please sign in to comment.