0

I have a karma test runner that dynamically writes rail's javascript files to a karma.conf.js file.

Now, everything works (the tests run) if I remove actioncable's javascript files manually from the files list. However, when actioncable's files are added, the preprocessor chokes.

24 08 2016 16:56:22.095:ERROR [preprocessor.coffee]: unexpected < at /home/vagrant/.rvm/gems/ruby-2.2.2/bundler/gems/actioncable-6be2604aa719/lib/assets/javascripts/cable.coffee.erb:4 24 08 2016 16:56:22.296:INFO [karma]: Karma v0.13.14 server started at http://localhost:9876/ 24 08 2016 16:56:22.309:INFO [launcher]: Starting browser PhantomJS 24 08 2016 16:56:23.106:INFO [PhantomJS 1.9.8 (Linux 0.0.0)]: Connected on socket RyL0QOEWkq8inzwAAAAA with id 22283032 PhantomJS 1.9.8 (Linux 0.0.0) ERROR You need to include some adapter that implements karma.start method!

Oke doke. So looking at the actioncable erb file:

#= require_self
#= require cable/consumer

@Cable =
  INTERNAL: <%= ActionCable::INTERNAL.to_json %>

  createConsumer: (url) ->
    new Cable.Consumer url

So the preprocessor is definitely choking on the erb tags in this specific file. I have erb tags in other files, that get processed fine, but those are wrapped in quotes. Is this a preprocessor bug, or is there a quick fix for this that I'm not thinking of?

daino3
  • 4,386
  • 37
  • 48

1 Answers1

0

I ran into this too. My understanding is that you need to compile the erb files down to js files, which will remove the rails syntax. What I did was add to my development.rb file:

config.assets.prefix = "/dev-assets"

Which creates the finger printed application.js file with all of your compiled scripts, same as production, and places it into public/dev-assets

In my karma.conf I have:

files: [
  './public/dev-assets/*.js',
   ...
]

It's not exactly ideal, since you're working with one big file when writing/debugging tests, but it works with the asset pipeline.

Before I came to that solution, I did add only my specific ng folders to the files array, skipping the cables file (you could add it to the excluded files list), which resolved the issue too, but I went with this route because I couldn't get it to play nice with angular-rails-templates

Justin Kruse
  • 1,020
  • 12
  • 27