This weekend, I hacked Meteor in order to implement test coverage using istanbul, and this is close to work.
The only remaining issue is to stop the server when tinytest job is done. I think somebody will figure it out 10 times faster than me so I share my results and hope to see coverage in a future version of Meteor . This is mandatory to stop the server because Istanbul waits that moment to write coverage files. So I created a package that stops the server after some delay (2 mins is enough to finish all my tests) :
I have added a new argument to meteor cli : meteor test-packages --coverage, which means that the server has to stop when the job is done and to run the project using Istanbul instead of node. The end-user, the developper, will be able to found coverage pages and json in his local folder : .meteor/local/coverage/packages/...
Yeap, here is the tutorial ! And at the end of these instructions I drop a link to let you see the coverage report
Check everything is good.
npm version
–> you must see node version 0.40
If it’s ok, install meteor and istanbul : git clone https://github.com/serut/meteor and npm install -g istanbul
Create a new project and run it using my meteor version
MAC-Leo:WebstormProjects Leo$ meteor create sample-meteor
Created a new Meteor app in 'sample-meteor'.
To run your new app:
cd sample-meteor
meteor
If you are new to Meteor, try some of the learning resources here:
https://www.meteor.com/learn
MAC-Leo:WebstormProjects Leo$ cd sample-meteor
MAC-Leo:sample-meteor Leo$ ../meteor/meteor
babel-compiler: updating npm dependencies -- meteor-babel...
npm-mongo: updating npm dependencies -- mongodb...
logging: updating npm dependencies -- cli-color...
=> Running Meteor from a checkout -- overrides project version (Meteor 1.2.1)
[[[[[ ~/WebstormProjects/sample-meteor ]]]]]
=> Started proxy.
=> Started MongoDB.
[...]
=> Started your app.
=> App running at: http://localhost:3000/
^C^C
Create a package that stops the server
MAC-Leo:sample-meteor Leo$ meteor create --package alpha
alpha: created in packages/alpha
MAC-Leo:sample-meteor Leo$ meteor add alpha
Changes to your project's package version selections:
alpha added, version 0.0.1
MAC-Leo:sample-meteor Leo$ nano packages/alpha/alpha.js
MAC-Leo:sample-meteor Leo$ cat packages/alpha/alpha.js
// Write your package code here!
Meteor.setTimeout(function() {
process.exit(0);
},120000);
MAC-Leo:sample-meteor Leo$ nano packages/alpha/package.js :
api.addFiles('alpha.js`); ---> api.addFiles('alpha.js`, 'server');
MAC-Leo:sample-meteor Leo$ cat packages/alpha/package.js
[...]
Package.onUse(function(api) {
api.versionsFrom('1.2.1');
api.use('ecmascript');
api.addFiles('alpha.js`, 'server');
});
[...]
You see at the end that I stop the Meteor server using Ctrl +c 2 times.
And this what you can found on your /Users/Leo/WebstormProjects/sample-meteor/.meteor/local/coverage/packages directory : http://serut.github.io/meteor/index.html