Currently we are using Mocha for unit and integration testing.
At some point soon we will be migrating to Jest, but we will make the migration process as smooth as possible.
This is the reason we are using the Jest Expect library instead of Chai.
You’ll find documentation about Meteor testing at the following places:
- Meteor Guide: Testing
- Mocha Getting Started
- Jest Expect API Reference
- Jest Extended Expect API Reference
- Chai BDD Expect API Reference
Vulcan comes pre-configured for unit testing, but for your own project you’ll have to install it.
If you are NOT using a two repo install copy vulcan/packages/meteor-mocha to your project’s packages directory.
In your app’s root directory run these terminal commands:
meteor add meteortesting:mocha
.meteor/versions and make sure the meteortesting packages are at their latest versions,
and if not, update them individually using
meteor update meteortesting:browser-tests etc.:
package.json in your app root and add the following line to the scripts section:
Make sure to replace
~/Dev/Erik-Vulcan with the actual path to you local copy of Vuclan in your two-repo install.
meteor you can define additional environment variables that you may need, such as
Running the tests
To start testing initiate unit-test, for example type in your console:
npm run test-unit
The unit test suite will then run and later re-run when you make code changes. You can terminate it with CTRL-C.
Adding code coverage
Add the following packages in your terminal:
meteor add lmieulet:meteor-coverage meteortesting:mocha
In order to instrument your code, you need to add the babel-plugin-istanbul the .babelrc file in the root of your app:
You must wrap the istanbul plugin with the env setting to disable the file-instrumentation of your project when you are not running the test coverage script. Just keep in mind that if you follow the here under script, babel will use the istanbul package only when BABEL_ENV=COVERAGE.
Now, to run the coverage process, just add these new scripts inside your package.json in the root folder of your app: