I'm trying to run Jasmine tests with Karma in our Rails application based on: http://sebastien.saunier.me/blog/2014/02/04/angular-rails-with-no-fuss.html. I'm getting an error for both Chrome and PhantomJS:
You need to include some adapter that implements __karma__.start method!
I took a look at this question, but all of their issues looked like outdated node modules or directory conflicts. I've run npm update
and should have all current versions. Also when I run debug, all of the preprocessor output is appearing correctly, so it shouldn't be a directory issue.
Here is my karma configuration:
// 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
})
}
Here is my rake task:
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
EDIT
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
EDIT
Looking into karma/static/context.js because of the debug
// 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
Looks like it's always calling UNIPMLEMENTED_START
Debug
04 08 2016 14:13:15.423:DEBUG [launcher]: PhantomJS (id 40031903) captured in 5.167 secs 04 08 2016 14:13:15.426:DEBUG [phantomjs.launcher]:
04 08 2016 14:13:15.427:DEBUG [middleware:karma]: custom files null null 04 08 2016 14:13:15.427:DEBUG [middleware:karma]: Serving static request /context.html 04 08 2016 14:13:15.428:DEBUG [web-server]: serving: /Users/aaron/app/node_modules/karma/static/context.html 04 08 2016 14:13:15.429:DEBUG [web-server]: serving: /Users/aaron/app/node_modules/karma/static/context.js PhantomJS 2.1.1 (Mac OS X 0.0.0) ERROR You need to include some adapter that implements karma.start method!