如何修复我的生成器角度项目以便 grunt 测试工作? [英] How do I fix my generator-angular project so that grunt test works?
问题描述
我正在学习本教程:http://www.sitepoint.com/kickstart-your-angularjs-development-with-yeoman-grunt-and-bower/ 作为了解使用 yo generator-angular 创建的文件的一种方式.p>
我有使用 AngularJS 的经验,但正在寻找一种方法来设置最佳实践目录;我不确定如何设置依赖项并让 karma 自己运行,因此使用 yeoman 生成器.
但是,直接开箱即用,无需编辑任何其他内容,当我运行 grunt test 时,我得到以下信息:
运行 "clean:server" (clean) 任务清洁 .tmp...OK运行并发:测试"(并发)任务运行copy:styles"(复制)任务已复制 1 个文件完成,没有错误运行autoprefixer:dist"(自动前缀)任务创建了前缀文件.tmp/styles/main.css".运行connect:test"(连接)任务开始在 127.0..0.1:9001 上连接 Web 服务器.运行业力:单位"(业力)任务警告:没有框架:茉莉花"的提供者!(解决:framework:jasmine)使用 --force 继续.由于警告而中止.
我不明白为什么 jasmine 没有提供程序,也不知道如何解决这个问题.是修复我的 package.json 文件和更新节点的问题吗?
这是配置文件:
//Karma 配置//http://karma-runner.github.io/0.10/config/configuration-file.htmlmodule.exports = 功能(配置){配置.set({//基本路径,将用于解析文件和排除基本路径:'',//要使用的测试框架 (jasmine/mocha/qunit/...)框架:['茉莉花'],//要在浏览器中加载的文件/模式列表文件:['app/bower_components/angular/angular.js','app/bower_components/angular-mocks/angular-mocks.js','app/bower_components/angular-resource/angular-resource.js','应用程序/脚本/*.js','app/scripts/**/*.js','测试/模拟/**/*.js','测试/规范/**/*.js'],//要排除的文件/模式列表排除: [],//网络服务器端口端口:8080,//日志级别//可能的值:LOG_DISABLE ||LOG_ERROR ||日志警告 ||日志信息 ||LOG_DEBUG日志级别:config.LOG_INFO,//启用/禁用监视文件并在任何文件更改时执行测试自动监视:假,//启动这些浏览器,目前可用://- 铬合金//- ChromeCanary//- 火狐//- 歌剧//- Safari(仅限 Mac)//- 幻影JS//- IE(仅限 Windows)浏览器:['Chrome'],//持续集成模式//如果为真,它会捕获浏览器,运行测试并退出单跑:假});
};
我似乎已经解决了我的问题,对于任何有类似问题的人:
在我的 karma.conf.js 中,我添加了以下内容:
插件:['业力铬发射器','业力茉莉花'],
一开始我添加了karma-jasmine",但后来遇到无法加载Chrome",它没有注册!"通过添加karma-chrome-launcher"作为插件解决了这个问题
不确定是我的错还是 generator-angular 是否过时,但它现在可以工作了.
I am working off of this tutorial: http://www.sitepoint.com/kickstart-your-angularjs-development-with-yeoman-grunt-and-bower/ as a means to understand what files are created using yo generator-angular.
I have experience using AngularJS, but was looking for a way to get a best-practices directory set up; I am not sure how to set up dependencies and get karma running on my own, hence using the yeoman generator.
However, straight out of the box, without editing anything else, when I run grunt test I get the following:
running "clean:server" (clean) task
Cleaning .tmp...OK
Running "concurrent:test" (concurrent) task
Running "copy:styles" (copy) task
Copied 1 files
Done, without errors
Running "autoprefixer:dist" (autoprefixer) task
Prefixed file ".tmp/styles/main.css" created.
Running "connect:test" (connect) task
Started connect web server on 127.0..0.1:9001.
Running "karma:unit" (karma) task
Warning: No provider for "framework:jasmine"! (resolving: framework:jasmine) Use --force to continue.
Aborted due to warnings.
I don't understand why jasmine has no provider, and not sure how to go about resolving this issue. is it a matter of fixing my package.json files and updating node?
EDIT: Here is the config file:
// Karma configuration
// http://karma-runner.github.io/0.10/config/configuration-file.html
module.exports = function(config) {
config.set({
// base path, that will be used to resolve files and exclude
basePath: '',
// testing framework to use (jasmine/mocha/qunit/...)
frameworks:['jasmine'],
// list of files / patterns to load in the browser
files: [
'app/bower_components/angular/angular.js',
'app/bower_components/angular-mocks/angular-mocks.js',
'app/bower_components/angular-resource/angular-resource.js',
'app/scripts/*.js',
'app/scripts/**/*.js',
'test/mock/**/*.js',
'test/spec/**/*.js'
],
// list of files / patterns to exclude
exclude: [],
// web server port
port: 8080,
// level of logging
// possible values: LOG_DISABLE || LOG_ERROR || LOG_WARN || LOG_INFO || LOG_DEBUG
logLevel: config.LOG_INFO,
// enable / disable watching file and executing tests whenever any file changes
autoWatch: false,
// Start these browsers, currently available:
// - Chrome
// - ChromeCanary
// - Firefox
// - Opera
// - Safari (only Mac)
// - PhantomJS
// - IE (only Windows)
browsers: ['Chrome'],
// Continuous Integration mode
// if true, it capture browsers, run tests and exit
singleRun: false
});
};
I seem to have fixed my problem, for anyone with a similar problem:
Within my karma.conf.js I added the following:
plugins: [
'karma-chrome-launcher',
'karma-jasmine'
],
At first I added 'karma-jasmine' but was then met with "Can not load "Chrome", it is not registered!" This was solved by adding 'karma-chrome-launcher' as a plug-in
Not sure if it was my fault or whether generator-angular is out of date, but it is now working.
这篇关于如何修复我的生成器角度项目以便 grunt 测试工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!