Last active
July 27, 2016 18:55
-
-
Save kristoferjoseph/9fa00cdd4bfec01bdcaa150f42c5dc95 to your computer and use it in GitHub Desktop.
Tiny test lib and runner.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<title>tiny tests</title> | |
<style> | |
body { | |
font-family: sans-serif; | |
padding: 3rem; | |
} | |
.test-pass { | |
margin-left: 2rem; | |
color: #2ECC40; | |
} | |
.test-fail { | |
margin-left: 2rem; | |
color: #FF4136; | |
} | |
</style> | |
</head> | |
<body> | |
<div id="output"></div> | |
<script src="./test.bundle.js"></script> | |
</body> | |
</html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var assert = require('assert') | |
var display | |
if (typeof window !== 'undefined') { | |
display = document.getElementById('output') | |
} | |
function print(out) { | |
if (display) { | |
display.innerHTML += out | |
} | |
} | |
function fail(msg) { | |
var out = ' ✘ ' + msg | |
console.error(out) | |
print('<h4 class="test-fail">'+out+'</h4>') | |
} | |
function pass(msg) { | |
var out = ' ✔︎ ' + msg | |
console.info(out) | |
print('<h4 class="test-pass">'+out+'</h4>') | |
} | |
function test(label, func) { | |
beforeEach() | |
var f = false | |
label = label || '' | |
console.info(label) | |
print('<h3 class="test-label">'+label+'</h3>') | |
try { | |
msg = func() | |
} | |
catch(e) { | |
f = e.message | |
fail(f) | |
} | |
finally { | |
if (!f) { | |
pass('passed') | |
} | |
} | |
afterEach() | |
} | |
function beforeEach() { | |
} | |
function afterEach() { | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Found myself without internet and wrote this tiny test lib. Was really fun to figure out and works for most modules. Works in node and the browser.