最近在项目中使用karma,遇到一个坑在这边记录一下。方便日后好找。
Karma 安装
npm install karma --save-dev
npm install karma-jasmine karma-chrome-launcher --save-dev
npm install -g karma-cli
$ karma init 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.
> yes
Do you want to capture a browser 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".
Press Enter to move to the next question.
[这边需要填写require 需加载的文件,否则会报require module is not defined 或者 adapter is not source map ]
> *.js
> test/**/*.js
>
Should any of the files included by the previous patterns be excluded ?
You can use glob patterns, eg. "**/*.swp".
Press Enter to move to the next question.
>
Do you wanna generate a bootstrap file for RequireJS?
This will generate test-main.js/coffee that configures RequireJS and starts the
tests.
> yes
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 "/Users/vojta/Code/karma/karma.conf.js".
在test-mian.js中可以写入requirejs中的config配置项alias shim
引用
karma 官网 需翻墙
http://karma-runner.github.io/0.13/plus/requirejs.html
如果文中有什么表述不准确的地方,欢迎大力指正,感谢阅读,欢迎交流!