3

I have a NodeJs application. Currently I am using team city for build and deployment of this application. Now I want to run unit test cases before deployment. I have used Mocha framework with Chai to write test cases. I don't see any runner type for Mocha or Node Js in team city.

I know some plugin is needed to be installed on teamcity server.

does any one know what is the plugin and what steps I need to follow?

Anil
  • 1,669
  • 5
  • 19
  • 44

1 Answers1

7

You don't have to install any specific TeamCity plugin, you have to use test reporter capable of writing TeamCity service messages, e.g. mocha-teamcity-reporter, which is just another npm package.

You'll get you tests consumed by TeamCity after you run mocha --reporter mocha-teamcity-reporter test in your build step, so Command-Line Runner may be used for this purpose.

It is a good practice to extract this command to a separate script in your package.json, e.g:

"test:ci": "mocha --reporter mocha-teamcity-reporter test"

and use npm run test:ci in your build step.

cyberskunk
  • 1,722
  • 20
  • 22
  • 1
    it worked. only point want to add here is that I had to use --exit because Mocha doesn't stop execution automatically after executing all test cases. I was reading on internet and found that it's issue with Mocha 4. – Anil Jan 18 '18 at 17:25