How to test nodejs backend code with Karma (testacular)

Sylvain picture Sylvain · May 21, 2013 · Viewed 40.4k times · Source

How do I setup Karma to run my backend unit tests (written with Mocha)? If I add my backend test script to the files = [], it fails stating that require is undefined.

Answer

Dan Kohn picture Dan Kohn · May 21, 2013

You don't. Karma is only for testing browser-based code. If you have a project with mocha tests on the backend and karma/mocha on the front end, try editing your package.json under scripts to set test to: mocha -R spec && karma run karma.con

Then, if npm test returns true, you'll know it's safe to commit or deploy.