2
votes

I'm using karma 0.10.9 with requirejs, coffeescript, jasmine and jasmine-sprockets (because I'm working on a RoR project, and we have a few files that only contain sprockets directives).

When I start karma, I get that "Executed 0 of 0 ERROR" message.

Looks like on the runner page (localhost:9876) the lib and src files don't get loaded but the specs do. No errors in the console. When I copy the url of a lib or src file directly into the address bar, the file gets loaded.

On the debug page all files (libs, sources and tests) get loaded.

I'm clueless...

Here's my karma.conf.js:

module.exports = function(config) {
  config.set({
    basePath: '../../..',

    frameworks: ['jasmine', 'requirejs'],

    files: [
      {pattern: 'vendor/assets/javascripts/**/*.js', included: false},
      {pattern: 'app/assets/javascripts/v5/**/*.coffee', included: false},
      'spec/javascripts/helpers/jasmine-jquery.js',
      'spec/javascripts/helpers/maps-helper.js',
      {pattern: 'spec/javascripts/fixtures/*.html', watched: true, included: false, served: true},
      {pattern: 'spec/javascripts/v5/**/*_spec.coffee', included: false},
      'spec/javascripts/v5/test-main.coffee'
    ],

    hostname: [
      'localhost'
    ],

    exclude: [
    ],

    preprocessors: {
      '**/*.coffee': ['coffee']
    },

    coffeePreprocessor: {
      // transforming the filenames
      transformPath: function(path) {
        return path.replace(/(.js.coffee|.coffee)/, '.js');
      }
    },

    reporters: ['progress'],

    port: 9876,

    colors: true,

    logLevel: config.LOG_INFO,

    autoWatch: true,

    browsers: [],

    captureTimeout: 20000,

    singleRun: false,

    reportSlowerThan: 500,

    sprocketsPath: 'vendor/assets/javascripts',
    sprocketsBundles: [
      'bootstrap.js',
      'plugins_jquery.js'
    ],

    plugins: [
      'karma-jasmine',
      'karma-requirejs',
      'karma-coffee-preprocessor',
      'karma-sprockets'
    ]
  });
};

And the test-main.coffee:

tests = []
for file of window.__karma__.files
  tests.push file  if /_spec\.js$/.test(file) if window.__karma__.files.hasOwnProperty(file)

# https://github.com/karma-runner/karma-requirejs/issues/6#issuecomment-23037725
for file of window.__karma__.files
  window.__karma__.files[file.replace(/^\//, "")] = window.__karma__.files[file]

requirejs.config

  baseUrl: 'base/app/assets/javascripts/'

  paths:
    jquery: '../../../vendor/assets/javascripts/jquery'
    underscore: '../../../vendor/assets/javascripts/lodash'
    backbone: '../../../vendor/assets/javascripts/backbone'
    // etc.pp.

  shim:
    backbone:
      deps: ['jquery', 'underscore', 'json2']
      exports: 'Backbone'
    json2:
      exports: 'JSON'

  deps: tests

  callback: window.__karma__.start

Any help appreciated.

Thanks!

1
Maybe it's the same problem as my own: stackoverflow.com/questions/26656102/… - user1338054

1 Answers

0
votes

Your spec should require the file it tests. In your karma.conf.js the files section should have your src files. once the files are served by karma. then you can require them in your spec.