【问题标题】:Karma Not Running - cannot find module gulpKarma Not Running - 找不到模块 gulp
【发布时间】:2015-12-11 16:00:10
【问题描述】:

我正在尝试在我的 Angular 项目中使用 Jasmine 设置业力测试。

我无法进行基本测试

`it("dummy", function() {
    expect(true).toBe(true);`

运行,我得到了错误:

PhantomJS 1.9.8 (Linux 0.0.0) 错误 错误:找不到模块“gulp”

这是我的 gulp 测试任务:

gulp.task('test', function(coverage) {
   gulp.src('dummy')
   .pipe(karma({
   configFile: 'karma.conf.js',
   action: 'run'
  }))
  .on('error', function(err) {
      // Make sure failed tests cause gulp to exit non-zero
      throw err;
  });

});

这是我的 karma conf 文件:

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: ['browserify', 'jasmine'],

    plugins : [
      'karma-browserify',
      'karma-jasmine',
      'karma-phantomjs-launcher'
    ],

    preprocessors: {
      'src/app/**/*.spec.js': [ 'browserify' ], 
      'src/components/**/*.spec.js': [ 'browserify' ], 
      'src/services/**/*.spec.js': [ 'browserify' ]
    },

    // list of files / patterns to load in the browser
    files: [
      'bower_components/jquery/dist/jquery.js',
      'bower_components/angular/angular.js',
      'bower_components/angular-cookies/angular-cookies.js',
      'bower_components/angular-mocks/angular-mocks.js',
      'bower_components/angular-resource/angular-resource.js',
      'bower_components/**/*.js',
      'src/**/*.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: ['PhantomJS'],


    // Continuous Integration mode
    // if true, it capture browsers, run tests and exit
    singleRun: false
  });
};

请帮我stackoverflow,你是我唯一的希望!

【问题讨论】:

    标签: angularjs unit-testing gulp karma-runner


    【解决方案1】:

    最常见的问题:你是否正确安装了 gulp?

    npm install gulp
    

    同时检查您将哪些文件加载​​到karma.conf.js 中的files 属性中。应该只有您的 3rd 方库 js 文件、您的自定义 js 文件和您的测试文件。

    你的 gulp 任务也有可能不正确,但由于我经常使用 grunt,所以我在这方面真的帮不上忙 :P

    【讨论】:

    • 成功了。我正在使用 **. glob 加载 karma.conf 文件属性中的文件。现在工作得很好,非常感谢你是明星。
    猜你喜欢
    • 2017-06-24
    • 2019-05-26
    • 2017-01-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-11-07
    • 2018-10-19
    • 1970-01-01
    相关资源
    最近更新 更多