Error: You need to include some adapter that implements __karma__.start method

后端 未结 26 1344
梦谈多话
梦谈多话 2020-12-01 11:53

I\'m trying to add some unit tests to one of my projects.

So far I\'ve installed and configured karma, and have installed jasmine. I\'ve one test file in my te

相关标签:
26条回答
  • 2020-12-01 12:18

    If you typing "karma start", you must have a karma.conf.js file in the current folder. or just "karma start /path/karma.conf.js"

    Try to create a new karmar.conf.js by "karma init /path/karma.conf.js"

    0 讨论(0)
  • 2020-12-01 12:20

    I had a problem with karma.conf.js file code format:

    files: [
        // Modules
        ,"client/bower_components/angular/angular.min.js"
        ,"client/bower_components/angular-mocks/angular-mocks.js"
        // App
        ,"client/app/app.module.js"
        // Test
        // ,"test/**/*.spec.js"
    ],
    

    The extra comma in files array have cause this error:

    You need to include some adapter that implements __karma__.start method!
    
    0 讨论(0)
  • 2020-12-01 12:21

    I received this error because I required the same dependency twice!

    Removing the duplicate file dependency removed the error for me. Circled in blue below.

    0 讨论(0)
  • 2020-12-01 12:22

    You must specify the the karma configuration file to karma.

    karma start karma.config.js 
    

    It works for me

    0 讨论(0)
  • 2020-12-01 12:23

    In my case, the message was in fact very descriptive: I forgot to add an adapter, in my case Jasmine, into the config file. Thus:

    module.exports = function(config) {
      config.set({
          browsers: ['Chrome'],
          singleRun: true,
          frameworks: ['jasmine'],
          files: [
              // ... files ...
          ],
          // other configs
        });
    };
    
    0 讨论(0)
  • 2020-12-01 12:23

    In my case, the configuration file name was different. So, running the command specifying the conf file solved my issue.

    >> karma start unit-tests.conf.js
    No captured browser, open http://localhost:9876/
    ...
    

    And for 'PhantomJS', opening the link specified(localhost:9876) in the browser executes the test cases.

    Hope it helps. :)

    EDIT 1: My Karma Config File

    module.exports = function(config) {
      config.set({
    
        // base path that will be used to resolve all patterns (eg. files, exclude)
        basePath: '',
    
    
        // frameworks to use
        // available frameworks: https://npmjs.org/browse/keyword/karma-adapter
        frameworks: ['jasmine'],
    
    
        // list of files / patterns to load in the browser
        files: [
          './node_modules/angular/angular.js',
          './node_modules/angular-ui-router/release/angular-ui-router.js',
          './node_modules/angular-mocks/angular-mocks.js',
          './app/services/users/users.js',
          './app/app.js',
          './app/services/users/users.spec.js'
        ],
    
    
        // list of files to exclude
        exclude: [
        ],
    
    
        // preprocess matching files before serving them to the browser
        // available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
        preprocessors: {
        },
    
    
        // test results reporter to use
        // possible values: 'dots', 'progress'
        // available reporters: https://npmjs.org/browse/keyword/karma-reporter
        reporters: ['spec'],
    
    
        // web server port
        port: 9876,
    
    
        // enable / disable colors in the output (reporters and logs)
        colors: true,
    
    
        // level of logging
        // possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
        logLevel: config.LOG_INFO,
    
    
        // enable / disable watching file and executing tests whenever any file changes
        autoWatch: true,
    
    
        // start these browsers
        // available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
        browsers: ['Chrome'],
    
    
        // Continuous Integration mode
        // if true, Karma captures browsers, runs the tests and exits
        singleRun: false,
    
        // Concurrency level
        // how many browser should be started simultaneous
        concurrency: Infinity
      })
    }
    
    0 讨论(0)
提交回复
热议问题