HOW to run mocha unit-tests on CircleCi and output XML?

Hi guys,

damn! How do I run unit-tests on CircleCi and output an compatible XML file?

I have tried the 2 packages recommended in meteor-guide.

practicalmeteor/mocha is giving me the FLOWROUTER problem, meaning that I can NOT run NEITHER with console NOR with XML output.
=> Spacejam phantomjs no route for the path /local flowrouter
=> also see

dispatch:mocha I can run on console (which is totally useless for CircleCi) and does NOT “find” any other mocha-reporter, meaning that I can NOT output XML-files:

Is there anyone who has a working mocha-unit-test running on CircleCi?
Do you mind posting how you did it?

This is a really quick example of how to get Meteor print an XML file that we can then use on CircleCi to run our unit tests.

Thanks a lot to @mfpinheiro, @pushplaybang and @warehouseman for helping out!!! :slight_smile:

Steps to reproduce this

Create new meteor project

meteor create --full name

Install spacejam globally

npm install -g spacejam


Run tests via http-reporter (works fine)

meteor test --driver-package=practicalmeteor:mocha

Open localhost:3000 to see your tests.

Run tests via console-reporter and FAIL #1

add console-reporter via meteor add practicalmeteor:mocha-console-runner

run tests via spacejam test --driver-package=practicalmeteor:mocha-console-runner --port 1231

this gives the ERROR:

spacejam test --driver-package=practicalmeteor:mocha-console-runner --port 1231
spacejam: spawning meteor
[[[[[ Tests ]]]]]

=> Started proxy.
=> Started MongoDB.
spacejam: meteor mongodb is ready
=> Started your app.

=> App running at: http://localhost:1231/
spacejam: meteor is ready
spacejam: spawning phantomjs
phantomjs: Running tests at http://localhost:1231/local using test-in-console
phantomjs: There is no route for the path: /local
    http://localhost:1231/packages/kadira_flow-router.js?hash=9b5b21b3e949cd3f26a647dfd0ac5f7b7a18757a: 519
spacejam: phantomjs exited with code: 6
spacejam: killing meteor
spacejam: meteor killed with signal: SIGTERM
spacejam: Unhandled error in meteor client side code. Exiting.

FIX FlowRouter bug and fail again with new error FAIL #2

Install FlowRouter bugfix to make it compatible with test-modes

mkdir packages
cd packages
git clone

NOTE: all the Folk does it this:

WOW - we get the next error now, when running spacejam test --driver-package=practicalmeteor:mocha-console-runner --port 1231

W20170327-07:30:04.995(2)? (STDERR) 						throw(ex);
W20170327-07:30:04.996(2)? (STDERR) 						^
W20170327-07:30:04.996(2)? (STDERR)
W20170327-07:30:04.997(2)? (STDERR) Error: Can't find test driver package: practicalmeteor:mocha-console-runner
W20170327-07:30:04.997(2)? (STDERR)     at packages/meteor.js:1031:13
W20170327-07:30:04.998(2)? (STDERR)     at Function.time (/private/var/folders/j3/hmkt_82519vbmq40ccj1c97c0000gn/T/meteor-test-run13bnb8b/.meteor/local/build/programs/server/profile.js:309:28)
W20170327-07:30:04.999(2)? (STDERR)     at /private/var/folders/j3/hmkt_82519vbmq40ccj1c97c0000gn/T/meteor-test-run13bnb8b/.meteor/local/build/programs/server/boot.js:312:13
W20170327-07:30:04.999(2)? (STDERR)     at /private/var/folders/j3/hmkt_82519vbmq40ccj1c97c0000gn/T/meteor-test-run13bnb8b/.meteor/local/build/programs/server/boot.js:353:5
W20170327-07:30:05.000(2)? (STDERR)     at (/private/var/folders/j3/hmkt_82519vbmq40ccj1c97c0000gn/T/meteor-test-run13bnb8b/.meteor/local/build/programs/server/profile.js:510:12)
W20170327-07:30:05.001(2)? (STDERR)     at /private/var/folders/j3/hmkt_82519vbmq40ccj1c97c0000gn/T/meteor-test-run13bnb8b/.meteor/local/build/programs/server/boot.js:351:11
=> Exited with code: 1

The final solution: use a different reporter

meteor remove practicalmeteor:mocha  # avoid version-constrains
meteor add practicalmeteor:mocha-xunit-reporter

Then do a

spacejam test --driver-package=practicalmeteor:mocha-xunit-reporter --load-images=no --ssl-protocol=TLSv1 --xunit-out ./unit-tests.xml

This will generate a xml (hopefully compatible with CircleCi?) and output to console at the same time.

Thanks to Mateus @mfpinheiro