Skip to content

Write meteor package tests with mocha and run them in the browser or from the command line with spacejam.

License

Notifications You must be signed in to change notification settings

hubroedu/meteor-mocha

 
 

Repository files navigation

decaffed

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.

App testing with meteor test

  1. Create your mocha tests in files following the *.test[s].* naming convention anywhere in your app folder.

  2. Create your mocha full app tests, in files following the *.app-test[s].* or *.app-spec[s].* naming convention anywhere in your app folder.

  3. Add hubroedu:mocha to your meteor app, along with for example chai:

meteor add hubroedu:mocha
meteor npm i --save-dev chai
  1. 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
  1. 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.

Package testing with meteor test-packages

  1. 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');
});
  1. 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)>

Using Console or XUnit reporters

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

License

mocha - MIT

mike:mocha - MIT

practicalmeteor:mocha - MIT

About

Write meteor package tests with mocha and run them in the browser or from the command line with spacejam.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 66.2%
  • HTML 31.3%
  • CSS 1.8%
  • Shell 0.7%