Why buster?
- Works for node and browser
- Built-in server for browser tests (no fixture HTML boilerplate)
- Built-in sinon.js
- Super flexible
Why not buster?
- 0.x
- Development is kind of slow
(yet stable enough)
- AMD is tricky
- Super flexible
Getting started
npm install buster
Run tests
./node_modules/.bin/buster-server
Point browser to localhost:1111
./node_modules/.bin/buster-test
Or install globally, but that's a bad idea
require('buster-node')
node myTests.js
npm install grunt-busternpm install -g grunt-clibrew install phantomjs
grunt buster
Debugging
- console.log()
- Browser: Chrome Dev Tools, Firebug, whatever
- node.js: WebStorm/PhpStorm/IntelliJ, node-inspector
Demo time!
Let's build a test result viewer
- Worth mentioning:
-
browserify: client side require()
-
grunt-contrib-watch - autorun tasks
-
nodemon - autorestart server
- Disclaimer: do a better job for production!
11 minsinit(el)
- should render status div
- should render results div
- when status is clicked:
- display results
- hide results
- onchange of textarea should loadResults()
should render results div
when status is clicked, display results
when status is clicked, hide resultss
Test doubles
Use for: isolation, forcing a code path, avoiding external calls, forcing errors
- sinon.spy: wraps around a method and records calls
- sinon.stub: replaces a method
- sinon.mock: replaces methods, built-in expectations
onchange of textarea should loadResults()
loadResults()
- should change status to loading
- should XHR
- should onReceived() after XHR
23 minsshould XHR, then onReceived
should XHR, then onReceived (error)
should XHR, then onReceived (async)
should XHR, then onReceived (promise)
onResultsReceived()
- when OK, should change status and add results
- when failed, should change status and add results
- when http error, should retry
30 minsServer side: /results
- should serve combined results.html
- should 404 when no browser results
- should 404 when no node results
35 minsshould serve combined results.html
should 404 when no browser results
should 404 when no node results