2

Just learning angularjs right now with the book 'AngularJS Up and Running' from O'Reilly.. Got to the chapter on unit testing with Karma & Jasmine, but having trouble making it work

EDIT: Changing logLevel to config.LOG_DEBUG now matches file patterns correctly. But I still have the ultimate 'adapter' error at the end.

running the 'karma start' command gives me the following:

DEBUG [plugin]: Loading karma-* from /Work/[lab]/angularjs-up-and-running/chapter3/node_modules
DEBUG [plugin]: Loading plugin /Work/[lab]/angularjs-up-and-running/chapter3/node_modules/karma-chrome-launcher.
DEBUG [plugin]: Loading plugin /Work/[lab]/angularjs-up-and-running/chapter3/node_modules/karma-jasmine.
INFO [karma]: Karma v0.12.16 server started at http://localhost:8080/
INFO [launcher]: Starting browser Chrome
DEBUG [temp-dir]: Creating temp dir at /var/folders/dw/qt56vk_s4cz5h6hg8qddvmrm0000gn/T/karma-24748311
DEBUG [launcher]: /Applications/Google Chrome.app/Contents/MacOS/Google Chrome --user-data-dir=/var/folders/dw/qt56vk_s4cz5h6hg8qddvmrm0000gn/T/karma-24748311 --no-default-browser-check --no-first-run --disable-default-apps --disable-popup-blocking --disable-translate http://localhost:8080/?id=24748311
WARN [watcher]: Pattern "/Work/[lab]/angularjs-up-and-running/chapter3/node_modules/karma-jasmine/lib/jasmine.js" does not match any file.
WARN [watcher]: Pattern "/Work/[lab]/angularjs-up-and-running/chapter3/angular-mocks.js" does not match any file.
WARN [watcher]: Pattern "/Work/[lab]/angularjs-up-and-running/chapter3/node_modules/karma-jasmine/lib/adapter.js" does not match any file.
WARN [watcher]: Pattern "/Work/[lab]/angularjs-up-and-running/chapter3/angular.min.js" does not match any file.
WARN [watcher]: Pattern "/Work/[lab]/angularjs-up-and-running/chapter3/simpleSpec.js" does not match any file.
WARN [watcher]: Pattern "/Work/[lab]/angularjs-up-and-running/chapter3/controller.js" does not match any file.
WARN [watcher]: Pattern "/Work/[lab]/angularjs-up-and-running/chapter3/controllerSpec.js" does not match any file.
DEBUG [watcher]: Resolved files:

DEBUG [watcher]: Watching "/Work/[lab]/angularjs-up-and-running/chapter3/angular.min.js"
DEBUG [watcher]: Watching "/Work/[lab]/angularjs-up-and-running/chapter3/angular-mocks.js"
DEBUG [watcher]: Watching "/Work/[lab]/angularjs-up-and-running/chapter3/controller.js"
DEBUG [watcher]: Watching "/Work/[lab]/angularjs-up-and-running/chapter3/simpleSpec.js"
DEBUG [watcher]: Watching "/Work/[lab]/angularjs-up-and-running/chapter3/controllerSpec.js"
DEBUG [web-server]: serving: /Work/[lab]/angularjs-up-and-running/chapter3/node_modules/karma/static/client.html
DEBUG [web-server]: serving: /Work/[lab]/angularjs-up-and-running/chapter3/node_modules/karma/static/karma.js
DEBUG [web-server]: upgrade /socket.io/1/websocket/YVK_k4vczJIuLIdg5a_f
DEBUG [karma]: A browser has connected on socket YVK_k4vczJIuLIdg5a_f
INFO [Chrome 38.0.2125 (Mac OS X 10.10.0)]: Connected on socket YVK_k4vczJIuLIdg5a_f with id 24748311
DEBUG [launcher]: Chrome (id 24748311) captured in 5.575 secs
DEBUG [karma]: All browsers are ready, executing
DEBUG [web-server]: serving: /Work/[lab]/angularjs-up-and-running/chapter3/node_modules/karma/static/context.html
Chrome 38.0.2125 (Mac OS X 10.10.0) ERROR
  You need to include some adapter that implements __karma__.start method!

So first of all it has warnings finding files, however all of those files do exist at that location.

My karma.conf.js file looks like this:

module.exports = function(config) {
  config.set({
    // base path, that will be used to resolve files and exclude
    basePath: '',

    // testing framework to use (jasmine/mocha/qunit/...)
    frameworks: ['jasmine'],

    // list of files / patterns to load in the browser
    files: [
      'angular.min.js',
      'angular-mocks.js',
      'controller.js',
      'simpleSpec.js',
      'controllerSpec.js'
    ],

    // list of files / patterns to exclude
    exclude: [],

    // web server port
    port: 8080,

    // level of logging
    // possible values: LOG_DISABLE || LOG_ERROR ||
    //                  LOG_WARN || LOG_INFO || LOG_DEBUG
    logLevel: config.LOG_DEBUG,


    // enable / disable watching file and executing tests
    // whenever any file changes
    autoWatch: true,

    // Start these browsers, currently available:
    // - Chrome
    // - ChromeCanary
    // - Firefox
    // - Opera
    // - Safari (only Mac)
    // - PhantomJS
    // - IE (only Windows)
    browsers: ['Chrome'],


    // Continuous Integration mode
    // if true, it capture browsers, run tests and exit
    singleRun: false
  });
};

karma is installed in my project folder (where karma.conf.js is located)

I really have no idea what's wrong and I can't see a way to contact the author of this book. Thanks!

Richard Lovejoy
  • 663
  • 10
  • 18
  • 1
    Have you installed [karma-chrome launcher](https://www.npmjs.org/package/karma-chrome-launcher) and [karma-jasmine](https://www.npmjs.org/package/karma-jasmine) ? – glepretre Oct 31 '14 at 08:50
  • 1
    By the way, you should just pick one log level in the `logLevel` option. I suggest you to use `config.LOG_DEBUG` to have full log which could help you to understand what happens ;) – glepretre Oct 31 '14 at 08:53
  • Yes karma-chrome-launcher and karma-jasmine are installed. – Richard Lovejoy Oct 31 '14 at 15:48
  • Interesting I changed it to LOG_DEBUG and now the 'missing' files are found, but I still get the error about including an adapter. Edited post. – Richard Lovejoy Oct 31 '14 at 15:50
  • Have you seen http://stackoverflow.com/q/24220888/ ? – glepretre Oct 31 '14 at 15:59
  • Yes I've seen it but it doesn't help me. For me it seems karma can't attach to the jasmine adapter for whatever reason. I don't have a package.json but the book doesn't mention needing one. – Richard Lovejoy Oct 31 '14 at 17:25

1 Answers1

2

I was facing that same issue and my mind was about to explode. I couldn't find anything anywhere, all the configurations were ok and nothing seemed wrong. Your question was the closest thing I could find.

I realized that both, your project filepath and mine contained square braces (.../[lab]/... in yours) and that it might be the cause. It is known that special caracters sometimes are troublesome.

I deleted the square braces from my filepath and all the tests worked perfectly.

If you pay attention to the Debug lines, jasmine.js and adapter.js were not resolved.

I hope this could be of some help.

Alejo G
  • 86
  • 1
  • 6