jejacks0n / teaspoon

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

How to get jquery working with teaspoon? Uncaught ReferenceError: jQuery is not defined #525

Closed dalexander01 closed 7 years ago

dalexander01 commented 7 years ago

This is a super noob question I'm sure but I'm working on a legacy rails project that's a big ball of spaghetti and uses teaspoon for unit testing. I am having a hard time figuring out why teaspoon is not loading jquery. Here is a gemfile

source 'https://rubygems.org'

source 'http://repo.release.cerner.corp/main/rubygems'
source 'http://repo.release.cerner.corp/internal/rubygems'
gemspec

gem 'uglifier', '~> 2.5'
gem 'yui-compressor', '~> 0.12'
gem 'pry'
gem 'pry-stack_explorer'
gem 'pry-byebug'
gem 'sprockets-rails', '~> 2.3'
gem 'eventmachine', '1.0.9.1'

group :development, :test do
  gem 'ion_develop_rails', '~> 2.7.0'
  gem 'teaspoon-jasmine', '~> 2.3'
end

teaspoon_env.rb

unless defined?(Rails)
  ENV['RAILS_ROOT'] = File.expand_path('..', __FILE__)
  load File.expand_path('../../config.ru', __FILE__)
end

Teaspoon.configure do |config|
  # Determines where the Teaspoon routes will be mounted.
  config.mount_at = '/teaspoon'

  # Specifies the root where Teaspoon will look for files.
  config.root = Orion::DateTimePicker::Engine.root

  # Paths that will be appended to the Rails assets paths
  # Note: Relative to `config.root`.
  config.asset_paths = ['spec/javascripts', 'app/assets/javascripts']

  config.use_coverage = true

  config.coverage do |coverage|
    coverage.reports = ['text', 'html', 'cobertura']
    coverage.output_path = 'target/coverage/javascripts'
    coverage.ignore = coverage.ignore + [%r{/usr/}]
  end

  # SUITES
  #
  # To run a specific suite
  # - in the browser: http://localhost/teaspoon/[suite_name]
  # - with the rake task: rake teaspoon suite=[suite_name]
  # - with the cli: teaspoon --suite=[suite_name]
  config.suite do |suite|

    suite.use_framework :jasmine, '2.3.4'

    # Specify a file matcher as a regular expression and all matching files will be loaded when the suite is run. These
    # files need to be within an asset path. You can add asset paths using the `config.asset_paths`.
    suite.matcher = 'spec/javascripts/**/*_spec.js'
  end

end

Here's spec_helper.rb

// Teaspoon includes some support files, but you can use anything from your own support path too.
// require support/jasmine-jquery
// require support/sinon
// require support/your-support-file
//
// 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 config/initializers/teaspoon.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
//
// You can require javascript files here. A good place to start is by requiring your application.js.
//
//= require d3_3.3.6
//= require third_party/terra/modernizr_2.7.1
//= require third_party/terra/cldrjs/cldr.min.js
//= require third_party/terra/cldrjs/cldr/event.min.js
//= require third_party/terra/cldrjs/cldr/supplemental.min.js
//= require third_party/terra/jquery/globalize/globalize.min.js
//= require third_party/terra/jquery/globalize/globalize/message.min.js
//= require jquery_globalize/terra_locales/globalize_init_en.js
//= require jquery_globalize/blue_steel_locales/en.js
//= require support/sinon
//= require mock/mocks
//= require orion/date_time_core
//= require orion-common
//= require orion-legacy

When I run teaspoon I get the following a couple of errors in 2 of my JS files that are using jquery. Uncaught ReferenceError: jQuery is not defined

Anyone have any ideas of what could be wrong, or give me any pointers of what to look for? I'm stuck at the moment.

jejacks0n commented 7 years ago

for the life of me I can't see anyplace where you require jquery.. am I missing something? I see third_party/terra/jquery/globalize/globalize.min.js -- is jQuery defined inside of that?

dalexander01 commented 7 years ago

for the life of me I can't see anyplace where you require jquery.. am I missing something? I see third_party/terra/jquery/globalize/globalize.min.js -- is jQuery defined inside of that?

I honestly have no idea. This is a legacy project that I have been assigned too and I have no idea what a lot of those third party dependencies are there for. If I wanted to require jquery on my own and not rely on a transitive dependency what would I need to do?

jejacks0n commented 7 years ago

//= require jquery

before other things? As I said, how would jQuery be loaded if you're not loading it?

dalexander01 commented 7 years ago

I've tried adding that to spec_helper.js and when I run teaspoon I get:

Error: ActionView::Template::Error: couldn't find file 'jquery' (in /home/duane/orion-date_time_picker/spec/javascripts/spec_helper.js:27)

Should it go in teaspoon_env.rb?

dalexander01 commented 7 years ago

Here is my gemfile.lock in case that tells us anything:

PATH
  remote: .
  specs:
    orion-date_time_picker (2.5.0.SNAPSHOT)
      blue_steel (~> 9.3)
      jquery-ui-rails (~> 6.0)
      moment_timezone-rails (~> 0.5)
      momentjs-rails (~> 2.15)
      orion-rails-layouts (~> 1.2)
      rails (~> 4.1)
      terra-rails-view_models (~> 3.0)

GEM
  remote: https://rubygems.org/
  remote: http://repo.release.cerner.corp/main/rubygems/
  remote: http://repo.release.cerner.corp/internal/rubygems/
  specs:
    actionmailer (4.2.9)
      actionpack (= 4.2.9)
      actionview (= 4.2.9)
      activejob (= 4.2.9)
      mail (~> 2.5, >= 2.5.4)
      rails-dom-testing (~> 1.0, >= 1.0.5)
    actionpack (4.2.9)
      actionview (= 4.2.9)
      activesupport (= 4.2.9)
      rack (~> 1.6)
      rack-test (~> 0.6.2)
      rails-dom-testing (~> 1.0, >= 1.0.5)
      rails-html-sanitizer (~> 1.0, >= 1.0.2)
    actionview (4.2.9)
      activesupport (= 4.2.9)
      builder (~> 3.1)
      erubis (~> 2.7.0)
      rails-dom-testing (~> 1.0, >= 1.0.5)
      rails-html-sanitizer (~> 1.0, >= 1.0.3)
    activejob (4.2.9)
      activesupport (= 4.2.9)
      globalid (>= 0.3.0)
    activemodel (4.2.9)
      activesupport (= 4.2.9)
      builder (~> 3.1)
    activerecord (4.2.9)
      activemodel (= 4.2.9)
      activesupport (= 4.2.9)
      arel (~> 6.0)
    activesupport (4.2.9)
      i18n (~> 0.7)
      minitest (~> 5.1)
      thread_safe (~> 0.3, >= 0.3.4)
      tzinfo (~> 1.1)
    addressable (2.5.1)
      public_suffix (~> 2.0, >= 2.0.2)
    arel (6.0.4)
    ast (2.3.0)
    astrolabe (1.3.1)
      parser (~> 2.2)
    basset-client (2.1.1)
      cerner-oauth1a (~> 1.0, >= 1.0.1)
      cerner-timber (~> 2.1, >= 2.1.1)
    binding_of_caller (0.7.2)
      debug_inspector (>= 0.0.1)
    blue_steel (9.5.0)
      haml (~> 4.0.4)
      haml-rails (~> 0.4)
      hamlbars (~> 2.0.1)
      handlebars_assets (= 0.14.1)
      hi-format (>= 1.6)
      less-rails (~> 2.7)
      rails (~> 4.0)
      sprockets-rails (~> 2.3)
    brakeman (3.7.0)
    builder (3.2.3)
    bundler-audit (0.6.0)
      bundler (~> 1.2)
      thor (~> 0.18)
    byebug (9.0.6)
    capybara (2.14.4)
      addressable
      mime-types (>= 1.16)
      nokogiri (>= 1.3.3)
      rack (>= 1.0.0)
      rack-test (>= 0.5.4)
      xpath (~> 2.0)
    cerner-oauth1a (1.0.1)
    cerner-timber (2.1.1)
      activesupport (>= 4.2.0)
    childprocess (0.7.1)
      ffi (~> 1.0, >= 1.0.11)
    cliver (0.3.2)
    coderay (1.1.1)
    coffee-rails (4.2.2)
      coffee-script (>= 2.2.0)
      railties (>= 4.0.0)
    coffee-script (2.4.1)
      coffee-script-source
      execjs
    coffee-script-source (1.12.2)
    colorize (0.7.7)
    combustion (0.7.0)
      activesupport (>= 3.0.0)
      railties (>= 3.0.0)
      thor (>= 0.14.6)
    commonjs (0.2.7)
    connection_pool (2.2.1)
    daemons (1.2.4)
    debug_inspector (0.0.3)
    diff-lcs (1.3)
    docile (1.1.5)
    erubis (2.7.0)
    eventmachine (1.0.9.1)
    execjs (2.7.0)
    faraday (0.12.2)
      multipart-post (>= 1.2, < 3)
    ffi (1.9.18)
    gc_stats (1.0.1)
      rails (~> 4.1)
    globalid (0.4.0)
      activesupport (>= 4.2.0)
    haml (4.0.7)
      tilt
    haml-rails (0.9.0)
      actionpack (>= 4.0.1)
      activesupport (>= 4.0.1)
      haml (>= 4.0.6, < 5.0)
      html2haml (>= 1.0.1)
      railties (>= 4.0.1)
    hamlbars (2.0.1)
      execjs (>= 1.2)
      haml
      sprockets
      tilt
    handlebars_assets (0.14.1)
      execjs (>= 1.2.9)
      sprockets (>= 2.0.3)
      tilt
    hi-checkup (1.10.0)
      rails (~> 4.0)
    hi-date_time (1.3.0)
      iso8601 (~> 0.8.5)
    hi-format (1.10.0)
      hi-date_time (~> 1.1)
      i18n (~> 0.7.0)
      rails (>= 4.0.0, < 6.0)
    hike (1.2.3)
    html2haml (2.2.0)
      erubis (~> 2.7.0)
      haml (>= 4.0, < 6)
      nokogiri (>= 1.6.0)
      ruby_parser (~> 3.5)
    http_accept_language (1.0.2)
    httparty (0.15.5)
      multi_xml (>= 0.5.2)
    i18n (0.7.0)
    inline_svg (0.12.1)
      activesupport (>= 3.0)
      loofah (>= 2.0)
      nokogiri (>= 1.6)
    ion_common (4.3.2)
      activesupport (~> 4.1)
      basset-client (~> 2.1)
      cerner-timber (~> 2.1, >= 2.1.1)
      gc_stats (~> 1.0)
      http_accept_language (~> 1.0)
      i18n (~> 0.6)
      ion_request_store_registry (~> 1.0)
      millennium_service_discovery (~> 2.0)
      thrift (~> 0.9)
    ion_dcos (1.0.1)
      activesupport (~> 4.0)
      jwt (~> 1.5)
      marathon-api (~> 2.0)
      timber (~> 1.0)
    ion_develop_rails (2.7.0)
      activesupport (>= 3.0.0)
      capybara (~> 2.7)
      coffee-rails (~> 4.2)
      combustion (~> 0.5)
      hi-checkup (~> 1.8)
      ion_dcos (~> 1.0)
      orion-rails-layouts (~> 1.0)
      philter (~> 1.5)
      poltergeist (~> 1.8)
      pry-byebug (~> 3.3)
      rails (~> 4.1)
      railties (>= 3.0.0)
      rake (~> 0.9)
      rdoc (~> 4.0)
      roll_out (~> 1.10, < 1.14.0)
      roll_out-capybara (~> 1.0)
      roll_out-jira (~> 1.2)
      roll_out-security (~> 1.4)
      rspec (~> 3.0)
      rspec-its (~> 1.0)
      rspec-rails (~> 3.2)
      selenium-webdriver (~> 2.50)
      simplecov (~> 0.9)
      sprockets (~> 2.12)
      sprockets-rails (~> 2.3)
      therubyracer (~> 0.12)
      thin (~> 1.6)
      thor (>= 0.14.6)
    ion_errors (3.2.0)
      blue_steel (~> 9.1)
      ion_common (~> 4.0)
      orion-rails-layouts (~> 1.2)
      rails (~> 4.1)
      sprockets-rails (~> 2.3)
      terra-rails-view_model (~> 1.19)
      therubyracer (~> 0.12)
    ion_request_store_registry (1.1.0)
      activesupport (~> 4.1)
      request_store (~> 1.1)
    iso8601 (0.8.7)
    jquery-ui-rails (6.0.1)
      railties (>= 3.2.16)
    json (2.1.0)
    jwt (1.5.6)
    less (2.6.0)
      commonjs (~> 0.2.7)
    less-rails (2.8.0)
      actionpack (>= 4.0)
      less (~> 2.6.0)
      sprockets (> 2, < 4)
      tilt
    libv8 (3.16.14.19)
    loofah (2.0.3)
      nokogiri (>= 1.5.9)
    mail (2.6.6)
      mime-types (>= 1.16, < 4)
    marathon-api (2.1.0)
      httparty (>= 0.11)
      json
      trollop (>= 2.0)
    method_source (0.8.2)
    millennia_discovery (2.0.0)
      rails (~> 4.1)
      ruby-openid (~> 2.5)
    millennium_service_discovery (2.0.0)
      millennia_discovery (~> 2.0)
      rails (~> 4.1)
    mime-types (2.4.3)
    mini_portile2 (2.2.0)
    minitest (5.10.2)
    moment_timezone-rails (0.5.0)
    momentjs-rails (2.17.1)
      railties (>= 3.1)
    multi_json (1.12.1)
    multi_xml (0.6.0)
    multipart-post (2.0.0)
    nokogiri (1.8.0)
      mini_portile2 (~> 2.2.0)
    orion-rails-layouts (1.4.0)
      blue_steel (~> 9.3)
      rails (~> 4.1)
      react_on_rails (= 7.0.4)
    parser (2.4.0.0)
      ast (~> 2.2)
    philter (1.11.0)
      colorize (~> 0.7.3)
      execjs (~> 2.6)
      multi_json (~> 1.6)
      roll_out (~> 1.7)
      rubocop (~> 0.27.1)
      thor (~> 0.19.1)
    poltergeist (1.15.0)
      capybara (~> 2.1)
      cliver (~> 0.3.1)
      websocket-driver (>= 0.2.0)
    powerpack (0.0.9)
    pry (0.10.4)
      coderay (~> 1.1.0)
      method_source (~> 0.8.1)
      slop (~> 3.4)
    pry-byebug (3.4.2)
      byebug (~> 9.0)
      pry (~> 0.10)
    pry-stack_explorer (0.4.9.2)
      binding_of_caller (>= 0.7)
      pry (>= 0.9.11)
    public_suffix (2.0.5)
    rack (1.6.8)
    rack-test (0.6.3)
      rack (>= 1.0)
    rails (4.2.9)
      actionmailer (= 4.2.9)
      actionpack (= 4.2.9)
      actionview (= 4.2.9)
      activejob (= 4.2.9)
      activemodel (= 4.2.9)
      activerecord (= 4.2.9)
      activesupport (= 4.2.9)
      bundler (>= 1.3.0, < 2.0)
      railties (= 4.2.9)
      sprockets-rails
    rails-deprecated_sanitizer (1.0.3)
      activesupport (>= 4.2.0.alpha)
    rails-dom-testing (1.0.8)
      activesupport (>= 4.2.0.beta, < 5.0)
      nokogiri (~> 1.6)
      rails-deprecated_sanitizer (>= 1.0.1)
    rails-html-sanitizer (1.0.3)
      loofah (~> 2.0)
    railties (4.2.9)
      actionpack (= 4.2.9)
      activesupport (= 4.2.9)
      rake (>= 0.8.7)
      thor (>= 0.18.1, < 2.0)
    rainbow (2.2.2)
      rake
    rake (0.9.6)
    rdoc (4.3.0)
    react_on_rails (7.0.4)
      addressable
      connection_pool
      execjs (~> 2.5)
      rails (>= 3.2)
      rainbow (~> 2.1)
    redcarpet (3.2.3)
    ref (2.0.0)
    request_store (1.3.2)
    rmagick (2.16.0)
    roll_out (1.13.1)
      faraday (~> 0.11)
      haml (>= 3.1, < 5.0.0)
      mime-types (~> 2.4.3)
      rake
      redcarpet (~> 3.2.2)
    roll_out-capybara (1.3.0)
      activesupport (>= 4.0, < 6.0)
      rmagick (~> 2.16)
      roll_out (~> 1.10)
    roll_out-jira (1.4.0)
      cerner-timber (~> 2.1)
      roll_out (> 1.5)
    roll_out-security (1.4.0)
      brakeman (~> 3.0)
      bundler-audit (~> 0.3)
      roll_out (~> 1.6)
    rspec (3.6.0)
      rspec-core (~> 3.6.0)
      rspec-expectations (~> 3.6.0)
      rspec-mocks (~> 3.6.0)
    rspec-core (3.6.0)
      rspec-support (~> 3.6.0)
    rspec-expectations (3.6.0)
      diff-lcs (>= 1.2.0, < 2.0)
      rspec-support (~> 3.6.0)
    rspec-its (1.2.0)
      rspec-core (>= 3.0.0)
      rspec-expectations (>= 3.0.0)
    rspec-mocks (3.6.0)
      diff-lcs (>= 1.2.0, < 2.0)
      rspec-support (~> 3.6.0)
    rspec-rails (3.6.0)
      actionpack (>= 3.0)
      activesupport (>= 3.0)
      railties (>= 3.0)
      rspec-core (~> 3.6.0)
      rspec-expectations (~> 3.6.0)
      rspec-mocks (~> 3.6.0)
      rspec-support (~> 3.6.0)
    rspec-support (3.6.0)
    rubocop (0.27.1)
      astrolabe (~> 1.3)
      parser (>= 2.2.0.pre.7, < 3.0)
      powerpack (~> 0.0.6)
      rainbow (>= 1.99.1, < 3.0)
      ruby-progressbar (~> 1.4)
    ruby-openid (2.7.0)
    ruby-progressbar (1.8.1)
    ruby_parser (3.10.0)
      sexp_processor (~> 4.9)
    rubyzip (1.2.1)
    selenium-webdriver (2.53.4)
      childprocess (~> 0.5)
      rubyzip (~> 1.0)
      websocket (~> 1.0)
    sexp_processor (4.10.0)
    simplecov (0.14.1)
      docile (~> 1.1.0)
      json (>= 1.8, < 3)
      simplecov-html (~> 0.10.0)
    simplecov-html (0.10.1)
    slop (3.6.0)
    sprockets (2.12.4)
      hike (~> 1.2)
      multi_json (~> 1.0)
      rack (~> 1.0)
      tilt (~> 1.1, != 1.3.0)
    sprockets-rails (2.3.3)
      actionpack (>= 3.0)
      activesupport (>= 3.0)
      sprockets (>= 2.8, < 4.0)
    teaspoon (1.1.5)
      railties (>= 3.2.5, < 6)
    teaspoon-jasmine (2.3.4)
      teaspoon (>= 1.0.0)
    terra-rails-renderable (1.1.0)
      activesupport (~> 4.1)
    terra-rails-view_model (1.19.0)
      activesupport (~> 4.1)
      orion-rails-layouts (~> 1.2)
      rails (~> 4.1)
      terra-rails-renderable (~> 1.0)
    terra-rails-view_models (3.3.0)
      blue_steel (~> 9.4)
      inline_svg (~> 0.6)
      ion_common (~> 4.0)
      ion_errors (~> 3.1)
      orion-rails-layouts (~> 1.2)
      rails (~> 4.1)
      react_on_rails (= 7.0.4)
      terra-rails-view_model (~> 1.19)
    therubyracer (0.12.3)
      libv8 (~> 3.16.14.15)
      ref
    thin (1.7.2)
      daemons (~> 1.0, >= 1.0.9)
      eventmachine (~> 1.0, >= 1.0.4)
      rack (>= 1, < 3)
    thor (0.19.4)
    thread_safe (0.3.6)
    thrift (0.10.0.0)
    tilt (1.4.1)
    timber (1.9.0)
      activesupport
    trollop (2.1.2)
    tzinfo (1.2.3)
      thread_safe (~> 0.1)
    uglifier (2.7.2)
      execjs (>= 0.3.0)
      json (>= 1.8.0)
    websocket (1.2.4)
    websocket-driver (0.6.5)
      websocket-extensions (>= 0.1.0)
    websocket-extensions (0.1.2)
    xpath (2.1.0)
      nokogiri (~> 1.3)
    yui-compressor (0.12.0)

PLATFORMS
  ruby

DEPENDENCIES
  eventmachine (= 1.0.9.1)
  ion_develop_rails (~> 2.7.0)
  orion-date_time_picker!
  pry
  pry-byebug
  pry-stack_explorer
  sprockets-rails (~> 2.3)
  teaspoon-jasmine (~> 2.3)
  uglifier (~> 2.5)
  yui-compressor (~> 0.12)

BUNDLED WITH
   1.14.6
dalexander01 commented 7 years ago

I notice that jquery-ui-rails is being loaded. Is this causing any issue?