Overview of Testing Badass Backbone Apps

Discussion

Where your test code lives + gets built

brunch compiles all files in the /test directory that end with _test into /test/javascript/test.js

brunch also combines all files inside of /test/vendor (like mocha, sinon etc.) into /test/javascript/test-vendor.js

You can see & configure this in /config.coffee

How your test code gets executed

brunch then copies all *.html files in /test/assets/test/ into /public/test/assets/test/*

So for example, you can hit in your browser:

http://localhost:3333/test-run/all.html

Where all.html is a mocha test harness page that includes test.js and test-vendor.js and some basic code to invoke your tests.

Continuous Integration

You can also execute your tests from the command line using mocha-phantomjs and this way incorporate your tests into Continuous Integration. To use mocha-phantomjs have you need to have brunch running and then from the terminal execute:

mocha-phantomjs http://localhost:3333/test/index.html

Execute only specific tests

Inside your test/*.html file you can control what tests get executed using the mocha grep (-g) option.

/test-run/all.html has no grep option, so it is setup to run all of your tests. You can uncomment and add any string regex to run a single suite or even a single test or a mixture of tests with matching strings.

See /test/grep.html for more info. We recommend creating separate /test-run/*.html files to execute groups of tests and leaving /test-run/all.html to run all your tests for CI and such.

Demo

Open /test-run/all.html to see how all the pieces hang together.