Forked from cultofcoders:mocha, as it still pulled in coffeescript through external dependencies. This package is stripped of all coffeescript, and has some stying changes over practicalmeteor:mocha.
-
Create your mocha tests in files following the
*.test[s].*
naming convention anywhere in your app folder. -
Create your mocha full app tests, in files following the
*.app-test[s].*
or*.app-spec[s].*
naming convention anywhere in your app folder. -
Add hubroedu:mocha to your meteor app, along with for example chai:
meteor add hubroedu:mocha
meteor npm i --save-dev chai
- Run your mocha tests using
meteor test
:
# This will execute all your `*.test[s].*` files. Changed port to 3200 to allow running your normal app at the same time
meteor test --driver-package=hubroedu:mocha --port 3200
Or, for full app tests:
# This will execute all your *.app-test[s].* and *.app-spec[s].* files.
meteor test --full-app --driver-package=hubroedu:mocha --port 3200
- Goto http://localhost:3200/ (or to your ROOT_URL) in any browser, to view the test results in mocha's html reporter.
See the testing section in meteor's official guide for more info.
- Add hubroedu:mocha and your mocha tests to your package.js Package.onTest section:
Package.onTest(function (api) {
api.use('hubroedu:mocha');
// Add any files with mocha tests.
api.addFiles('my-mocha-tests.js');
});
- Run your mocha package tests using
meteor test-packages
:
meteor test-packages --driver-package hubroedu:mocha <package(s)>
Package testing with spacejam from the command line
Note: Support for meteor 1.3 app and package testing in spacejam is coming soon.
With spacejam, you'll use our practicalmeteor:mocha-console-runner as the driver-package to print the test results to the console.
spacejam test-packages --driver-package=practicalmeteor:mocha-console-runner <package(s)>
To set other reporter you just need to export MOCHA_REPORTER env var.
For ConsoleReporter: MOCHA_REPORTER=console
For XunitReporter: MOCHA_REPORTER=xunit
Those reporter are mean to be use in combination with spacejam, for example
spacejam test --mocha
Spacejam will use the console reporter and you will see the results in your console.
spacejam test --mocha --xunit-out path/to/file.xml
Spacejam in addition to print the tests in your console will also create a file using XUnit format.
For more details about this integration go HERE