karma启动时出现了很多问题:
1.安装karma前提条件
安装karma首先要安装nodejs,npm然后才可以安装karma.nodejs,npm的安装过程可以参考文章:Angularjs学习---angularjs环境搭建,ubuntu 12.04下安装nodejs、npm和karma
2.安装karma步骤
karma官方指导教程:http://karma-runner.github.io/0.12/intro/installation.html
1).首先执行下面命令:
npm install -g karma
2).安装karma-cli
$ npm install -g karma-cli
3)安装插件:
# Install plugins that your project needs:
$ npm install karma-jasmine karma-chrome-launcher --save-dev
3.karma启动设置和报错处理
启动karma:
karma start
报如下错误:
amosli@amosli-pc:~/develop/angular-phonecat$ karma start module.js:
throw err;
^
Error: Cannot find module 'zeparser'
at Function.Module._resolveFilename (module.js::)
at Function.Module._load (module.js::)
at Module.require (module.js::)
at require (module.js::)
at Object.<anonymous> (/home/amosli/develop/angular-phonecat/node_modules/karma/node_modules/socket.io/node_modules/socket.io-client/node_modules/active-x-obfuscator/index.js::)
at Module._compile (module.js::)
at Object.Module._extensions..js (module.js::)
at Module.load (module.js::)
at Function.Module._load (module.js::)
at Module.require (module.js::)
解决方法:
sudo npm install zeparser
原因是没有安装zeparser,安装一下就好了.
然后重新配置一下karma,配置步骤如下:
这里karma init 后会生成karam.conf.js
我们这里需要修改:files和exclude变量
module.exports = function (config) {
config.set({
basePath: '',
frameworks: ['jasmine'],
files: ['*.js'],
exclude: ['karma.conf.js'],
reporters: ['progress'],
port: ,
colors: true,
logLevel: config.LOG_INFO,
autoWatch: true,
browsers: ['Chrome'],
captureTimeout: ,
singleRun: false
});
};
然后最好是将karma.conf.js移到/usr/local/lib/node_modules/karma/,这样启动时会直接在根目录查找karam.conf.js文件了.
再输入karma start
amosli@amosli-pc:~$ karma start
INFO [karma]: Karma v0.12.14 server started at http://localhost:9876/
INFO [Chrome 34.0. (Linux)]: Connected on socket UJ16Fx9X5cKFcMslNw8N with id manual-