Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Karma doesn't find files specified in config file

I'm writing Jasmine tests to my Angularjs app. I generated karma.conf.js using karma init but when I run karma start i get warnings like this:

WARN [web-server]: 404: /bower_components/angular/angular.js
WARN [web-server]: 404: /js/app.js

karma.conf.js is in my app folder, which is the place for the bower_components folder as well.

I think maybe that could be because of my local test server where I'm using this approach: https://github.com/mhevery/angular-node-socketio

(I've been able to set up the tests like this in other project without a test server)

Can anybody please point me in the right direction here?


Update:

My karma.conf.js looks like this:

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
  });
};

Here's my directory structure:

enter image description here

like image 313
gelly Avatar asked Feb 05 '14 15:02

gelly


2 Answers

Now that you've fixed the basepath (from '.' to '', see question comments above), you should change the order of files loading in your 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
  });
};

You can find more info here: 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.
like image 75
glepretre Avatar answered Nov 20 '22 05:11

glepretre


Your problem is probably the order you're loading your files in.

You may need to change the order to something like:

files: [
  'bower_components/angular/angular.js',
  'bower_components/angular-mocks/angular-mocks.js',
  'bower_components/angular-resource/angular-resource.js',
  'bower_components/d3/d3.js',
  'js/*.js',
  'tests/*.js'
],
like image 34
thelastshadow Avatar answered Nov 20 '22 05:11

thelastshadow