jejacks0n / teaspoon

Teaspoon: Javascript test runner for Rails. Use Selenium, BrowserStack, or PhantomJS.
1.43k stars 244 forks source link

How to get Teaspoon to point to its own assets? #486

Open snoblenet opened 8 years ago

snoblenet commented 8 years ago

My Teaspoon :: Javascript Test Runner pages is successfully loading this asset

<link rel="stylesheet" media="screen" href="/assets/teaspoon-a1d6d5ff0b67e23a151d7be3b7dadfc9.css?body=1" />

However, it is also failing to load all these assets.

<script src="/javascripts/jasmine/2.3.4.js"></script>
<script src="/javascripts/teaspoon-jasmine2.js"></script>
<script src="/javascripts/spec_helper.js" debug="true" allow_non_precompiled="true"></script>
<script src="/javascripts/demo_spec.js" debug="true" allow_non_precompiled="true"></script>

spec_helper.js and demo_spec.js (actually spec_helper.coffee and demo_spec.coffee) are in /spec/javascripts. The other two files are presumably loaded by the gem:

group :development, :test do
  gem 'teaspoon' # also tried without
  gem 'teaspoon-jasmine'
  gem 'phantomjs'
end

Perhaps the absence of these files is not surprising, given my JavaScript is usually found at /assets/filename.js, not /javascripts/filename.js. However, these files are not being served at these other locations either.

What's going on?

Relevant excerpts from my codebase are:

config/initializers/assets.rb:

Rails.application.config.assets.precompile += %w( teaspoon.css )
Rails.application.config.assets.precompile += %w( jasmine/2.3.4.js )
Rails.application.config.assets.precompile += %w( teaspoon-jasmine2.js )
Rails.application.config.assets.precompile += %w( teaspoon-teaspoon.js )

If you check Rails.application.config.assets.precompile in rails console, the input includes:

 "teaspoon.css",
 "jasmine/2.3.4.js",
 "teaspoon-jasmine2.js",
 "teaspoon-teaspoon.js",
 "teaspoon.css",
 "teaspoon-filterer.js",
 "teaspoon/*.js",
 "support/*.js",
 "jasmine/1.3.1.js",
 "teaspoon-jasmine1.js",
 "jasmine/2.0.3.js",
 "teaspoon-jasmine2.js",
 "jasmine/2.1.3.js",
 "teaspoon-jasmine2.js",
 "jasmine/2.2.0.js",
 "teaspoon-jasmine2.js",
 "jasmine/2.2.1.js",
 "teaspoon-jasmine2.js",
 "jasmine/2.3.4.js",
 "teaspoon-jasmine2.js"

(I've shown the repetition, in case it is significant.)

When I run bundle exec rake assets:precompile, the precompiler creates the following:

/public/assets/teaspoon-*.css
/public/assets/teaspoon-filterer-*.js
/public/assets/teaspoon/*

However, it does not create the files like teaspoon-jasmine2.js that I can see in the gem's source code at teaspoon/teaspoon-jasmine/lib/teaspoon/jasmine/assets/.

BTW, my teaspoon_env.rb & spec_helper.coffee are both exactly as generated by rails generate teaspoon:install --coffee:

Teaspoon.configure do |config|
  config.mount_at = "/teaspoon"
  config.root = nil
  config.asset_paths = ["spec/javascripts", "spec/javascripts/stylesheets"]
  config.fixture_paths = ["spec/javascripts/fixtures"]
  config.suite do |suite|
    suite.use_framework :jasmine, "2.3.4"
    suite.matcher = "{spec/javascripts,app/assets}/**/*_spec.{js,js.coffee,coffee}"
    suite.helper = "spec_helper"
    suite.boot_partial = "boot"
  end
end
# Teaspoon includes some support files, but you can use anything from your own support path too.
# require support/jasmine-jquery-1.7.0
# require support/jasmine-jquery-2.0.0
# require support/jasmine-jquery-2.1.0
# require support/sinon
# require support/your-support-file
#
# PhantomJS (Teaspoons default driver) doesn't have support for Function.prototype.bind, which has caused confusion.
# Use this polyfill to avoid the confusion.
#= require support/phantomjs-shims
#
# You can require your own javascript files here. By default this will include everything in application, however you
# may get better load performance if you require the specific files that are being used in the spec that tests them.
#= require application
#
# Deferring execution
# If you're using CommonJS, RequireJS or some other asynchronous library you can defer execution. Call
# Teaspoon.execute() after everything has been loaded. Simple example of a timeout:
#
# Teaspoon.defer = true
# setTimeout(Teaspoon.execute, 1000)
#
# Matching files
# By default Teaspoon will look for files that match _spec.{js,js.coffee,.coffee}. Add a filename_spec.js file in your
# spec path and it'll be included in the default suite automatically. If you want to customize suites, check out the
# configuration in teaspoon_env.rb
#
# Manifest
# If you'd rather require your spec files manually (to control order for instance) you can disable the suite matcher in
# the configuration and use this file as a manifest.
#
# For more information: http://github.com/modeset/teaspoon

UPDATE

Using ActionController::Base.helpers.asset_path("teaspoon-jasmine2.js"), I've established that file is meant to be at "/teaspoon-jasmine2.js". However, loading that page instead raises this error:

Unknown suite configuration: expected "-jasmine2" to be a configured suite.

rbishop commented 8 years ago

I'm experiencing this as well. We want to run teaspoon in the test RAILS_ENV (it seems that teaspoon runs in development by default,) and make use of our already precompiled assets on CI. We want our app assets precompiled but don't necessarily need to precompile the jasmine spec files.

jejacks0n commented 8 years ago

These are all due to changes in the default behavior in sprockets. Have you tried with master? If master doesn't work, I'll need to come up with a workaround, but I have personal life things going on that are keeping me from being able to work on Teaspoon at the moment.

rbishop commented 8 years ago

Thanks for the quick reply! I thought that might be the case after finding another issue. We have some other gems that cause a stack overflow (still trying to narrow down which one is causing it) when we upgrade to latest Sprockets. If I can figure that out I'll just upgrade Sprockets.

Best wishes with your personal life.

jejacks0n commented 8 years ago

Thank you. Please provide any details you find when investigating the issue with Teaspoon and in general. The change to sprockets, and the seemingly inability to opt in to allowing assets that are not defined in the precompile list when requesting assets is burdensome on gems like Teaspoon, but that's not your fault. =)

snoblenet commented 8 years ago

Hi @jejacks0n -- Thanks for your response and best wishes for your current issues.

Since I posted this, I've got the raw Jasmine gem going. This has the advantage of being non-Rails specific, so it makes no particular assumption about the app using the assets pipeline. As it worked, we'll continue with that for the time being.