Install and use Karma

1:安装karma

y@y:~$ npm install --global karma

2:安装karma插件

y@y:~$  npm install --global karma-jasmine karma-chrome-launcher

运行Karma:

y@y:~$ .npm-packages/lib/node_modules/karma/bin/karma start
INFO [karma]: Karma v0.12.32 server started at http://localhost:9876/

3:安装karma,命令行插件

y@y:~$ npm install -g karma-cli

测试:

y@y:~$ karma --version
Karma version: 0.12.32
y@y:~$ karma start
INFO [karma]: Karma v0.12.32 server started at http://localhost:9876/

4:配置Karma

y@y:angular-test$ karma init my-karma.conf.js

Which testing framework do you want to use ?
Press tab to list possible options. Enter to move to the next question.
> jasmine

Do you want to use Require.js ?
This will add Require.js plugin.
Press tab to list possible options. Enter to move to the next question.
> no

Do you want to capture any browsers automatically ?
Press tab to list possible options. Enter empty string to move to the next question.
> Chrome
> 

What is the location of your source and test files ?
You can use glob patterns, eg. "js/*.js" or "test/**/*Spec.js".
Enter empty string to move to the next question.
> *.js
WARN [init]: There is no file matching this pattern.

> test/*Spec.js
> 

Should any of the files included by the previous patterns be excluded ?
You can use glob patterns, eg. "**/*.swp".
Enter empty string to move to the next question.
> 

Do you want Karma to watch all the files and run the tests on change ?
Press tab to list possible options.
> yes


Config file generated at "/home/y/my_note/nodejs/angular-test/my-karma.conf.js".

y@y:angular-test$ ll
总用量 28
drwxrwxr-x  6 y y 4096  5月 20 15:46 ./
drwxrwxr-x 10 y y 4096  5月 20 13:48 ../
drwxrwxr-x  3 y y 4096  5月 20 14:49 app/
drwxrwxr-x  7 y y 4096  5月 20 15:03 bower_components/
drwxrwxr-x  2 y y 4096  5月 20 14:03 .idea/
-rw-rw-r--  1 y y 1584  5月 20 15:46 my-karma.conf.js
drwxrwxr-x  2 y y 4096  5月 20 14:50 test/
y@y:angular-test$ 

5:修改项目下面的my-karma.conf.jsp配置文件,将需要的js文件引入:

    // list of files / patterns to load in the browser
    files: [
        'bower_components/angular/angular.min.js',
        'bower_components/angular-mocks/angular-mocks.js',
        'app/js/*.js',
        'test/*Spec.js'
    ],

6:进行运行测试:

@y:angular-test$ karma start my-karma.conf.js 
INFO [karma]: Karma v0.12.32 server started at http://localhost:9876/
INFO [launcher]: Starting browser Chrome
INFO [Chrome 39.0.2171 (Linux)]: Connected on socket cz6gdNTkD5A0FyfLAAAA with id 3944078
Chrome 39.0.2171 (Linux): Executed 1 of 1 SUCCESS (0.021 secs / 0.016 secs)

 

posted @ 2015-05-20 16:01  yshy  阅读(258)  评论(0编辑  收藏  举报