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.
相关问题
- npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fs
- google-drive can't get push notifications
- How to reimport module with ES6 import
- Why is `node.js` dying when called from inside pyt
- How to verify laravel passport api token in node /
相关文章
- node连接远程oracle报错
- How can make folder with Firebase Cloud Functions
- @angular-cli install fails with deprecated request
- node.js modify file data stream?
- How to resolve hostname to an ip address in node j
- Jenkins Not Outputting Junit Report Info From File
- Transactionally writing files in Node.js
- Log to node console or debug during webpack build
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.It seems like it cannot be done (thanks @dankohn). Here is my solution using Grunt:
Karma: update your karma.conf.js file
autoWatch = false;
singleRun = true;
browsers = ['PhantomJS'];
(to have inline results)Grunt :
npm install grunt-contrib-watch grunt-simple-mocha grunt-karma
Gruntfile.js:
Grunt (optional): setup grunt-watch to start tests on changing the tested files or the specs itself.
run all using
grunt
command.