Files would be laid out as follows ... obviously this is a little contrived :)
grunt.js
app/
index.html
js/
foo.js
runner.js
tests/
foo.js
vendor/
chai.js
mocha.js
jquery.js
require.js
| define([ 'js/foo' ], function(Foo) { | |
| suite('Foo', function() { | |
| test('it works', function() { | |
| assert(true, 'ok'); | |
| }); | |
| }); | |
| }); |
| /*global module:false*/ | |
| module.exports = function(grunt) { | |
| // Project configuration. | |
| grunt.initConfig({ | |
| mocha: { | |
| index: ['app/index.html'] | |
| } | |
| }); | |
| // Default task. | |
| grunt.loadNpmTasks('grunt-mocha'); | |
| grunt.registerTask('default', 'lint mocha'); | |
| }; |
| <!doctype html> | |
| <html> | |
| <head> | |
| <meta charset="utf-8"> | |
| <link rel="stylesheet" href="css/mocha.css"> | |
| <script src="vendor/chai.js"></script> | |
| <script> | |
| window.assert = chai.assert; | |
| </script> | |
| <script src="vendor/mocha.js"></script> | |
| <script> | |
| mocha.setup('tdd'); | |
| </script> | |
| <script src="vendor/require.js"></script> | |
| <script> | |
| require.config({ | |
| deps : [ 'js/runner' ], | |
| paths : { | |
| 'jquery' : 'vendor/jquery' | |
| } | |
| }); | |
| </script> | |
| </head> | |
| <body> | |
| <div id="mocha"></div> | |
| <div id="test"></div> | |
| <!-- restore this script tag if you're not using requirejs. | |
| <script>mocha.run();</script> | |
| --> | |
| </body> | |
| </html> |
| require([ | |
| 'tests/foo' | |
| ], function() { | |
| mocha.run(); | |
| }); |
seems it still doesn't work for me like this. dropping a console.log into the mocha runner gives me:
nevermind, I'll keep digging around. thanks for sharing this anyways.