The example described in the doc https://circleci.com/docs/2.0/collect-test-data/#mochajs regarding the mocha-junit-reporter does not work if you have a global working directory which is not ~ (home directory).
This is expected because the defined MOCHA_FILE: junit/test-results.xml
refers to your custom working directory and then not the ~/junit
folder which is in home (but then your logs are forced to be in your working directory).
The simplest solution is to change the code to (remove all the references to ~):
steps:
- checkout
- run: npm install
- run: mkdir junit
- run:
command: mocha test --reporter mocha-junit-reporter
environment:
MOCHA_FILE: junit/test-results.xml
when: always
- store_test_results:
path: junit
- store_artifacts:
path: junit
Another solution if you do want your logs in a specific place is to use full paths in all the instructions.
Things to know which I think should be documented somewhere and where I lost most of the time debugging:
- path in MOCHA_FILE cannot be prefixed with another variable
- more tricky: MOCHA_FILE variable does not resolve the ~ thus it would create a folder named ~ in your working directory
In both cases, store_test_results / artifacts will naturally do nothing because folder is empty: logs are somewhere else!
Hope that the time lost to resolve this basic issue will help someone else! Maybe CircleCI team, you can save us a lot of time by improving this area, thanks a lot!