mortsahl
mortsahl

Reputation: 602

Karma.conf.js does not exist

I just reinstalled node from scratch. I also installed yeoman, generator-angular, and karma.

After generating a project with yo angular, I can successfully grunt serve. However, whenever I try grunt test, the following error is thrown:

karma.conf.js does not exist

However, karma.conf.js does indeed exist in the generated test directory. Why would this happen?

Upvotes: 10

Views: 9289

Answers (3)

ackuser
ackuser

Reputation: 5889

In my case, I didn't even find karma.conf.js. However, I realized if you do

grunt --force

you will be able to get more info and you might get what is going on inside

Running "karma:unit" (karma) task
08 09 2015 13:16:33.928:WARN [plugin]: Cannot find plugin "karma-phantomjs-launcher".
  Did you forget to install it ?
  npm install karma-phantomjs-launcher --save-dev
08 09 2015 13:16:33.939:WARN [plugin]: Cannot find plugin "karma-jasmine".
  Did you forget to install it ?
  npm install karma-jasmine --save-dev
Warning: No provider for "framework:jasmine"! (Resolving: framework:jasmine) Used --force, continuing.

Finally, I was able to figure it out what I missed.

Hope this help.

Upvotes: 0

eljamez
eljamez

Reputation: 11

I also had this problem but I was using CoffeeScript. It turned out that the CoffeeScript for karma.conf.js wasn't being created. karma.conf.coffee was placed properly in the test folder but it wasn't being compiled. So in my gruntfile (under the coffee task) I replaced this...

  test: {
    files: [{
      expand: true,
      cwd: 'test/spec',
      src: '{,*/}*.coffee',
      dest: '.tmp/spec',
      ext: '.js'
    }]
  }

With this...

      test: {
    files: [{
      expand: true,
      cwd: 'test/spec',
      src: '{,*/}*.coffee',
      dest: '.tmp/spec',
      ext: '.js'
    },
    {
      expand: true,
      cwd: 'test',
      src: 'karma.conf.coffee',
      dest: 'test',
      ext: '.conf.js'
    }]
  }

All I did was make sure that the karma.conf.coffee compiled in the test directory.

This worked but I was still getting errors because in karma.conf.coffee some of the files had incorrect extensions ('cs' instead of 'coffee'), for these 3 lines in particular.

  'app/scripts/**/*.cs'
  'test/mock/**/*.cs'
  'test/spec/**/*.cs'

I just changed the extensions to coffeescript (and removed the mock folder,as I wasn't using it).

  'app/scripts/**/*.coffee'
  'test/spec/**/*.coffee'

after that, the builds and test worked. I'm new to Yeoman so I'm not sure if this could have easily been avoided, but it's what I had to do to get things working.

Upvotes: 1

elimelech
elimelech

Reputation: 126

Gruntfile.js refers to karma.conf.js in the root-dir. The Angular generator puts it in the test-directory, so you'll need to update Gruntfile.js

// Test settings
karma: {
  unit: {
    configFile: 'test/karma.conf.js',
    singleRun: true
  }
}

There's also a problem when running grunt test with this generated karma.conf.js. It will say

test/karma.conf.js:63
    colors: true,
    ^^^^^^
ERROR [config]: Invalid config file!
  SyntaxError: Unexpected identifier

Reason: comma missing after 'singleRun: false'.

Upvotes: 11

Related Questions