Hi_Amos
坚持每天都在进步!!

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:340
    throw err;
          ^
Error: Cannot find module 'zeparser'
    at Function.Module._resolveFilename (module.js:338:15)
    at Function.Module._load (module.js:280:25)
    at Module.require (module.js:364:17)
    at require (module.js:380:17)
    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:1:78)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Module.require (module.js:364:17)

解决方法:

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: 9876,
        colors: true,
        logLevel: config.LOG_INFO,
        autoWatch: true,
        browsers: ['Chrome'],
        captureTimeout: 60000,
        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.1847 (Linux)]: Connected on socket UJ16Fx9X5cKFcMslNw8N with id manual-8888

 配置参考http://blog.fens.me/nodejs-karma-jasmine/

 


posted on 2014-05-06 00:39  Hi_Amos  阅读(1920)  评论(0编辑  收藏  举报