微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

javascript – Karma找不到配置文件中指定的文件

我正在为我的 Angularjs应用程序编写Jasmine测试.
我使用karma init生成了karma.conf.js,但是当我运行karma start时,我得到这样的警告:
WARN [web-server]: 404: /bower_components/angular/angular.js
WARN [web-server]: 404: /js/app.js

karma.conf.js在我的app文件夹中,也就是bower_components文件夹的位置.

我想也许这可能是因为我使用这种方法的本地测试服务器:https://github.com/mhevery/angular-node-socketio

(我已经能够在没有测试服务器的其他项目中设置这样的测试)

请问有谁可以指出我正确的方向吗?

更新:

我的karma.conf.js看起来像这样:

module.exports = function(config) {
  config.set({
    basePath: '.',frameworks: ['jasmine','requirejs'],files: [
      'tests/*.js','js/*.js','bower_components/angular/angular.js','bower_components/angular-mocks/angular-mocks.js','bower_components/angular-resource/angular-resource.js','bower_components/d3/d3.js'
    ],exclude: [],reporters: ['progress'],port: 9876,colors: true,logLevel: config.LOG_INFO,autoWatch: true,browsers: ['Chrome'],captureTimeout: 60000,singleRun: false
  });
};

这是我的目录结构:

解决方法

现在您已经修复了基本路径(从’.’到”,请参阅上面的问题评论),您应该更改karma.conf.js中加载的文件的顺序:
module.exports = function(config) {
  config.set({
    basePath: '.',files: [
      //load angular.js first
      //(unless if you use jQuery which must be first if I remember well)
      'bower_components/angular/angular.js',//Then angular-modules
      'bower_components/angular-resource/angular-resource.js',//Other libs
      'bower_components/d3/d3.js',//Your app scripts
      'js/*.js',//And your specs 
      'tests/*.js'
    ],singleRun: false
  });
};

你可以在这里找到更多信息:http://karma-runner.github.io/0.10/config/files.html

Ordering

  1. The order of patterns determines the order of files in which they are included in the browser.
  2. Multiple files matching a single pattern are sorted alphabetically.
  3. Each file is included exactly once. If multiple patterns match the same file,it’s included as if it only matched the first pattern.

原文地址:https://www.jb51.cc/js/157232.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐