Files
coffeescript/documentation/site/test.html
Geoffrey Booth 19231dbcad 2.0.0 (#4701)
* Bump version to 2.0.0; bump dependencies versions

* Make v2 docs the primary docs; jettison the v1 docs’ source: whenever the v1 docs need to be rebuild in the future, that can be done on the `1` branch and copied over; simplify folder tree

* Updated v1 docs that reflect that v2 is out and have updated paths to reflect that the v2 docs are now the primary docs, and the v1 docs only live under /v1/

* Add Google Analytics; track navigation, editing code and running code

* 2.0.0 changelog

* Fix link to root docs

* No more @next; installing local copy should be --save-dev

* Analytics on the browser-based tests page should prove fascinating . . .

* Update annotated source

* Add note to changelog clarifying scope
2017-09-18 08:19:19 -07:00

161 lines
3.7 KiB
HTML
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<title>CoffeeScript Test Suite</title>
<script src="browser-compiler/coffeescript.js"></script>
<script src="https://cdn.jsdelivr.net/underscorejs/1.8.3/underscore-min.js"></script>
<style>
body, pre {
font-family: Consolas, Menlo, Monaco, monospace;
}
body {
margin: 1em;
}
h1 {
font-size: 1.3em;
}
div {
margin: 0.6em;
}
.good {
color: #22b24c
}
.bad {
color: #eb6864
}
.subtle {
font-size: 0.7em;
color: #999999
}
</style>
</head>
<body>
<h1>CoffeeScript Test Suite</h1>
<pre id="stdout"></pre>
<script type="text/coffeescript">
@testingBrowser = yes
@global = window
bold = red = green = reset = ''
stdout = document.getElementById 'stdout'
start = new Date
@currentFile = ''
@passedTests = failedTests = total = done = 0
say = (msg, className) ->
div = document.createElement 'div'
div.className = className if className?
div.appendChild document.createTextNode msg
stdout.appendChild div
msg
asyncTests = []
onFail = (description, fn, err) ->
failures.push
error: err
description: description
source: fn.toString() if fn.toString?
@test = (description, fn) ->
++total
try
result = fn.call(fn)
if result instanceof Promise # An async test.
asyncTests.push result
result.then ->
passedTests++
.catch (err) ->
onFail description, fn, err
else
passedTests++
catch err
onFail description, fn, err
@failures =
push: (failure) -> # Match function called by regular tests
++failedTests
say "#{failure.description}:", 'bad'
say failure.source, 'subtle' if failure.source?
say failure.error, 'bad'
console.error failure.error
@ok = (good, msg = 'Error') ->
throw Error msg unless good
# Polyfill Node asserts fail
@fail = ->
ok no
# Polyfill Node asserts deepEqual with Underscores isEqual
@deepEqual = (a, b) ->
ok _.isEqual(a, b), "Expected #{JSON.stringify a} to deep equal #{JSON.stringify b}"
<%= testHelpers %>
@doesNotThrow = (fn) ->
fn()
ok yes
@throws = (fun, err, msg) ->
try
fun()
catch e
if err
if typeof err is 'function' and e instanceof err # Handle comparing exceptions
ok yes
else if e.toString().indexOf('[stdin]') is 0 # Handle comparing error messages
ok err e
else
eq e, err
else
ok yes
return
ok no
# Run the tests
for test in document.getElementsByClassName 'test'
say '\u2714 ' + test.id
options = {}
options.filename = currentFile = test.id
options.literate = yes if test.type is 'text/x-literate-coffeescript'
CoffeeScript.run test.innerHTML, options
# Finish up
done = ->
yay = passedTests is total and not failedTests
sec = (new Date - start) / 1000
msg = "passed #{passedTests} tests in #{sec.toFixed 2} seconds"
msg = "failed #{total - passedTests} tests and #{msg}" unless yay
say msg, (if yay then 'good' else 'bad')
gtag 'event', 'tests_complete',
event_category: 'tests'
event_label: if yay then 'passed' else 'failed'
value: if yay then passedTests else total - passedTests
gtag 'event', 'tests_report',
event_category: 'tests'
event_label: msg
gtag 'event', 'timing_complete',
name: 'tests_run'
value: sec * 1000
Promise.all(asyncTests).then(done).catch(done)
</script>
<%= tests %>
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-106156830-1"></script>
<script>
window.GA_TRACKING_ID = 'UA-106156830-1';
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments)};
gtag('js', new Date());
gtag('config', GA_TRACKING_ID);
</script>
</body>
</html>