如何修复我的生成器角度项目以便进行咕噜声测试?

use*_*083 31 jasmine angularjs gruntjs yeoman karma-runner

我正在使用本教程:http://www.sitepoint.com/kickstart-your-angularjs-development-with-yeoman-grunt-and-bower/作为一种方法来了解使用yo generator-angular创建的文件.

我有使用AngularJS的经验,但正在寻找一种方法来设置最佳实践目录; 我不确定如何设置依赖关系并让我自己运行业力,因此使用yeoman生成器.

但是,开箱即用,没有编辑任何其他内容,当我运行grunt测试时,我得到以下内容:

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.
Run Code Online (Sandbox Code Playgroud)

我不明白为什么茉莉花没有提供者,也不知道如何解决这个问题.是修复我的package.json文件和更新节点的问题?

编辑:这是配置文件:

// 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
  });
Run Code Online (Sandbox Code Playgroud)

};

use*_*083 54

我似乎解决了我的问题,对于有类似问题的人:

在我的karma.conf.js中,我添加了以下内容:

plugins: [
    'karma-chrome-launcher',
    'karma-jasmine'
    ],
Run Code Online (Sandbox Code Playgroud)

起初我添加了"karma-jasmine"但后来遇到了"无法加载"Chrome",它没有注册!" 这是通过添加'karma-chrome-launcher'作为插件来解决的

不确定这是我的错还是发电机角度是否过时,但它现在正在工作.

  • 那是非常有用的信息.我发现[本期](https://github.com/yeoman/generator-angular/issues/614)on generator-angular和[this issue](https://github.com/yeoman/generator-karma/issues/44)关于生成器业力,似乎与你所看到的有关. (2认同)
  • 需要解决的问题包括:但由于社区对SOF的支持,这些问题很容易解决.谢谢!非常小的一点 - 默认情况下,名称是"karma.conf.js",而不是"karma.config.js".干杯. (2认同)

phe*_*ris 10

@Jim Schubert指出的github问题有这样的评论:

我需要安装以获得测试的业力依赖关系的完整列表(coffeescript).

npm install --save-dev karma-chrome-launcher karma-firefox-launcher karma-safari-launcher karma-opera-launcher karma-ie-launcher karma-jasmine karma-coffee-preprocessor
Run Code Online (Sandbox Code Playgroud)

  • 更糟糕的是,我预测我会参考karma`~0.10.2`和所有其他业力代码的波浪版本...版本0.10.10并且它的所有依赖关系都不同步并导致我的团队出现大量错误. (2认同)