Skip to content
Yeoman generator for Mocha+Testem
Pull request Compare This branch is 8 commits ahead, 73 commits behind yeoman:master.
Latest commit 69fa103 Sep 24, 2013 @callumlocke Update
Failed to load latest commit information.
lib add testem support Aug 7, 2013
test fix test, bump to 0.1.2 Aug 7, 2013
.editorconfig Update editorconfig Apr 14, 2013
.gitattributes Add dotfiles Nov 24, 2012
.gitignore Rewrite Apr 15, 2013
.jshintrc Rewrite Apr 14, 2013
.travis.yml Add Node 0.10 to travis file Apr 14, 2013 Add readme Nov 24, 2012
package.json v0.1.4 Sep 2, 2013 Update Sep 24, 2013

Mocha+Testem generator Build Status

This is a fork of generator-mocha, modifed to work with Testem. (See differences.)

Works well with generator-webapp.

Getting Started

npm install -g generator-mocha-testem
yo mocha-testem

What this does:

  • creates test directory (similar to generator-mocha's, but modified to work through the Testem server)
  • creates testem.json
  • adds some lines to your .gitignore

Now run testem, and it should launch some browsers and run your tests.

How to use with generator-webapp

  • mkdir myproject && cd myproject
  • yo webapp
  • Delete the test directory: rm -rf test
  • yo mocha-testem

You can now run testem and grunt server at the same time in different terminals, and you'll have a live-reloading webapp and live-reloading test results at the same time.

In your spec runner (test/index.html), add your script tags in this form:

  • application scripts: <script src="../app/scripts/foo.js"></script>
  • test scripts: <script src="specs/foo-test.js"></script>

Optional: add the grunt-testem plugin

Follow these instructions to use Testem in CI mode during your build process. It launches each browser in turn, runs your tests, and closes them afterwards, then proceeds to the next step (e.g. build) only if everything was green.

  • Remove grunt-mocha: npm uninstall -D grunt-mocha
  • Add grunt-testem: npm install -D grunt-testem
  • In your Gruntfile...
    • remove the entire config entry for mocha, and remove the test target of connect
    • find grunt.registerTask('test'..., remove the connect:test subtask, and change 'mocha' to 'testem'
    • add this config entry:
        testem: {
            main: {
                src: [ 'testem.json' ],
                dest: 'tests.tap'

Now try running grunt test (or just grunt).

You can configure which browsers it launches by editing the launch_in_ci section in testem.json.


(Not yet tested.)

When running grunt server in a webapp project, CoffeeScripts are compiled to .tmp. So if you want to unit-test a *.coffee file, the script tag in your test/index.html will need to look like this: <script src="../.tmp/scripts/foo.js"></script>.

(I haven't yet looked into using CoffeeScript for test files yet. More steps will be needed. Suggestions/PRs welcome.)


See the contributing docs


BSD license

Something went wrong with that request. Please try again.