karma requirejs 加载问题小记

来源:互联网 发布:新疆人 知乎 编辑:程序博客网 时间:2024/04/30 04:06

最近在项目中使用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.jsWhich testing framework do you want to use ?Press tab to list possible options. Enter to move to the next question.> jasmineDo 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.> yesDo 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 thetests.> yesDo you want Karma to watch all the files and run the tests on change ?Press tab to list possible options.> yesConfig 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

如果文中有什么表述不准确的地方,欢迎大力指正,感谢阅读,欢迎交流!

0 0