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

时间:2014-03-14 00:53:07

标签: angularjs gruntjs jasmine 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.

我不明白为什么茉莉花没有提供者,也不知道如何解决这个问题。是修复我的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
  });

};

3 个答案:

答案 0 :(得分:54)

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

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

plugins: [
    'karma-chrome-launcher',
    'karma-jasmine'
    ],

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

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

答案 1 :(得分: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

答案 2 :(得分:2)

如果您在--coffee命令上使用了yo angular标记,则需要:

安装一些浏览器启动器(本例中为chrome)和以下npm包:

npm install --save-dev karma-chrome-launcher karma-jasmine karma-coffee-preprocessor

并将以下内容添加到您的karma.conf.js文件中:

plugins:['karma-chrome-launcher', 'karma-jasmine', 'karma-coffee-preprocessor'],
preprocessors:{'**/*.coffee':['coffee']}

之后运行grunt test应该有效。