Skip to content

Commit

Permalink
Move browser entry to test
Browse files Browse the repository at this point in the history
  • Loading branch information
dy committed May 15, 2018
1 parent be3326d commit d18b56a
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions test/browser.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
var PENDING = '#FCD62A'
var FAILING = '#F28E82'
var PASSING = '#8ECA6C'

var originalLog = console.log
var container = document.body.appendChild(document.createElement('pre'))

var failed = 0
var passed = 0

document.body.style.backgroundColor = PENDING

var pendingLines = []
var pendingRaf = null

console.log = function (line) {
if (typeof line !== 'string') {
line = line + ''
}
if (line.indexOf('ok') === 0) {
passed += 1
} else if (line.indexOf('not ok') === 0) {
failed += 1
}
pendingLines.push(line)
originalLog.apply(console, arguments)

if (!pendingRaf) {
pendingRaf = window.requestAnimationFrame(updateDOM)
}
}

function updateDOM () {
var s = document.body.style
if (failed > 0) {
if (s.backgroundColor !== FAILING) {
s.backgroundColor = FAILING
}
} else if (passed > 0 && failed === 0) {
if (s.backgroundColor !== PASSING) {
s.backgroundColor = PASSING
}
}
container.appendChild(document.createTextNode(pendingLines.join('\n') + '\n'))
pendingLines.length = 0
pendingRaf = null
}

require('./index')

0 comments on commit d18b56a

Please sign in to comment.