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

标签 javascript angularjs unit-testing karma-runner

我正在为我的 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 在我的应用程序文件夹中,这也是 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
  });
};

这是我的目录结构:

enter image description here

最佳答案

现在您已经修复了基本路径(从“.”到“”,请参阅上面的问题评论),您应该更改 karma.conf.js 中文件加载的顺序:

module.exports = function(config) {
  config.set({
    basePath: '.',
    frameworks: ['jasmine', 'requirejs'],
    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',
      'bower_components/angular-mocks/angular-mocks.js',
      //Other libs
      'bower_components/d3/d3.js',
      //Your app scripts
      'js/*.js',
      //And your specs 
      'tests/*.js'
    ],
    exclude: [],
    reporters: ['progress'],
    port: 9876,
    colors: true,
    logLevel: config.LOG_INFO,
    autoWatch: true,
    browsers: ['Chrome'],
    captureTimeout: 60000,
    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.

关于javascript - Karma 找不到配置文件中指定的文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21581700/

相关文章:

javascript - AngularJs 停止特定 Controller 的 $interval

android - Gradle connectedAndroidTest 失败并显示 "No tests found."但输出测试结果

unit-testing - 单元测试 MonoDroid

javascript - 单击可拖动层顶部时如何获得准确的指针位置?

javascript - 使用 angularjs 时轮播不工作?

javascript - 为什么我不能简单地使用 Javascript 中的赋值语句更新 array[i]

javascript - Angular $parsers 在 View 更改和模型更改后调用

unit-testing - UIApplication.sharedApplication().delegate 作为 AppDelegate 导致 EXC_BAD_ACCESS 在快速单元测试中使用它

javascript - 无法读取未定义的 angular2 的属性 'version'

javascript - 使用 _.differenceBy 从一个对象数组中删除另一个对象数组中的项目