错误:需要包含一些实现__karma __。start方法的适配器

时间:2016-07-26 15:45:06

标签: ruby-on-rails karma-runner karma-jasmine sprockets

我试图在我们的Rails应用程序中使用Karma运行Jasmine测试,基于:http://sebastien.saunier.me/blog/2014/02/04/angular-rails-with-no-fuss.html。我收到了Chrome和PhantomJS的错误:

  

你需要包含一些实现__karma __ .start方法的适配器!

我看了一下这个question,但他们所有的问题看起来都像过时的节点模块或目录冲突。我已经运行npm update并且应该拥有所有当前版本。此外,当我运行调试时,所有预处理器输出都正确显示,因此它不应该是目录问题。

这是我的业力配置:

// spec/karma/config/unit.conf.js
module.exports = function(config) {
  config.set({

    // base path, based on tmp/ folder
    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: [
      APPLICATION_SPEC,
      'app/assets/javascripts/ng/*/*.{coffee,js,js.coffee}',
      'spec/javascripts/**/*_spec.{coffee,js,js.coffee}'
    ],


    // 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
    preprocessors: {
      '**/*.coffee': ['coffee', 'coverage'],
      '**/*.coffee.erb': ['coffee', 'coverage'],
      '**/*.haml': ['haml', 'ng-html2js']
    },

    coffeePreprocessor: {
      // options passed to the coffee compiler
      options: {
        bare: true,
        sourceMap: false
      },
      // transforming the filenames
      transformPath: function(path) {
        return path.replace(/(\.js)?.coffee$/, '.js')
      }
    },

    ngHtml2JsPreprocessor: {
      moduleName: 'zipapp.templates',
      stripPrefix: 'app/assets/javascripts',
      stripSufix: '.haml',
      prependPrefix: '/assets'
    },

    coverageReporter: {
      includeAllSources: true
    },

    hamlPreprocessor: {
      options: {
        language: 'js'
      }
    },


    // test results reporter to use
    // possible values: 'dots', 'progress'
    // available reporters: https://npmjs.org/browse/keyword/karma-reporter
    reporters: ['progress', 'coverage'],


    // 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: ['PhantomJS','Chrome'],

    // If browser does not capture in given timeout [ms], kill it
    captureTimeout: 60000,

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

这是我的佣金任务:

namespace :karma do
  task debug: :environment do
    with_tmp_config :start, "--single-run --log-level debug"
  end

  task start: :environment do
    with_tmp_config :start
  end

  task run: :environment do
    with_tmp_config :start, "--single-run"
  end

  private

  def with_tmp_config(command, args = nil)
    Tempfile.open('karma_unit.js', Rails.root.join('tmp')) do |f|
      f.write unit_js(application_spec_files)
      f.flush

      system "karma #{command} #{f.path} #{args}"
    end
  end

  def application_spec_files
    sprockets = Rails.application.assets
    sprockets.append_path Rails.root.join("spec/karma")
    Rails.application.assets.find_asset("application_spec.js").to_a.map { |e| e.pathname.to_s }
  end

  def unit_js(files)
    unit_js = File.open('spec/karma/config/unit.conf.js', 'r').read
    unit_js.gsub "APPLICATION_SPEC", "\"#{files.join("\",\n\"")}\""
  end
end

修改

PhantomJS 2.1.1 (Mac OS X 0.0.0) ERROR
  You need to include some adapter that implements \__karma__.start method!

01:44:46 {javascript_tests} ~/$ npm list
app@1.0.0 /Users/aaron/
├── jasmine-core@2.4.1
├─┬ karma@1.1.2

npm list output

修改

因为调试

而关注karma / static / context.js
// Define our start handler
var UNIMPLEMENTED_START = function () {
  this.error('You need to include some adapter that implements __karma__.start method!')
}
// all files loaded, let's start the execution
this.loaded = function () {
  // has error -> cancel
  if (!hasError) {
    this.start(this.config)
  }

  // remove reference to child iframe
  this.start = UNIMPLEMENTED_START
}
// supposed to be overriden by the context
// TODO(vojta): support multiple callbacks (queue)
this.start = UNIMPLEMENTED_START

看起来总是在呼叫UNIPMLEMENTED_START

调试

  

04 08 2016 14:13:15.423:DEBUG [发射器]:PhantomJS(id 40031903)在5.167秒内被捕获   04 08 2016 14:13:15.426:DEBUG [phantomjs.launcher]:

     

04 08 2016 14:13:15.427:DEBUG [middleware:karma]:自定义文件null null   04 08 2016 14:13:15.427:DEBUG [middleware:karma]:提供静态请求/context.html   04 08 2016 14:13:15.428:DEBUG [web-server]:服务:/Users/aaron/app/node_modules/karma/static/context.html   04 08 2016 14:13:15.429:DEBUG [web-server]:服务:/Users/aaron/app/node_modules/karma/static/context.js   PhantomJS 2.1.1(Mac OS X 0.0.0)错误     您需要包含一些实现业力 .start方法的适配器!

0 个答案:

没有答案