jejacks0n / teaspoon

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

Hook produces ReferenceError: url is not defined #493

Closed RGreinacher closed 8 years ago

RGreinacher commented 8 years ago

Hey!

I try to create a hook like so:

(_teaspoonenv.rb, in config.suite do |suite|)

suite.hook :create_document do
      require 'factory_girl_rails'

      MyDocument.destroy_all

      FactoryGirl.definition_file_paths = ['./spec/factories']
      FactoryGirl.find_definitions
      FactoryGirl.create(:annotation_document)
    end

and call it in my _my_testspec.coffee with

before ->
  Teaspoon.hook('create_document')

This leads me to the following error in both, browser and CLI:

"before all" hook ReferenceError: url is not defined (http://localhost:3000/assets/teaspoon-mocha.self-b15d919...

What am I doing wrong? Thanks a lot! : )

RGreinacher commented 8 years ago

I filed the issue using teaspoon-mocha. Today I tried to use teaspoon-jasmine and I still get the same error. Via CLI I tried to call Teaspoon.hook('test_hook') in my _testspec.coffee and got the following:

ReferenceError: Can't find variable: url
  # teaspoon-jasmine2.self-193432e902b3943f7e511bf7ba322e1ce098119d180978aaff50918567da9361.js:456
  # :0 -- send
  # teaspoon-jasmine2.self-193432e902b3943f7e511bf7ba322e1ce098119d180978aaff50918567da9361.js:447 -- xhrRequest
  # teaspoon-jasmine2.self-193432e902b3943f7e511bf7ba322e1ce098119d180978aaff50918567da9361.js:451 -- hook
  # support/annotation_document_manager_spec.self-3b741f4f9c671769efb6d88a542bc1349a97c04e75257ef128be885deaa25d67.js:3
  # jasmine/2.3.4.self-aa35a2d6ef4c597846860937831b786d7a7b61cf7b7d860a06b484aa1b637276.js:1790 -- attemptSync
  # jasmine/2.3.4.self-aa35a2d6ef4c597846860937831b786d7a7b61cf7b7d860a06b484aa1b637276.js:1778 -- run
  # jasmine/2.3.4.self-aa35a2d6ef4c597846860937831b786d7a7b61cf7b7d860a06b484aa1b637276.js:1763 -- execute
  # jasmine/2.3.4.self-aa35a2d6ef4c597846860937831b786d7a7b61cf7b7d860a06b484aa1b637276.js:628 -- queueRunnerFactory
  # jasmine/2.3.4.self-aa35a2d6ef4c597846860937831b786d7a7b61cf7b7d860a06b484aa1b637276.js:2210 -- execute
  # jasmine/2.3.4.self-aa35a2d6ef4c597846860937831b786d7a7b61cf7b7d860a06b484aa1b637276.js:679 -- execute
  # teaspoon-jasmine2.self-193432e902b3943f7e511bf7ba322e1ce098119d180978aaff50918567da9361.js:1462 -- Runner
  # teaspoon-jasmine2.self-193432e902b3943f7e511bf7ba322e1ce098119d180978aaff50918567da9361.js:35 -- execute
  # teaspoon-jasmine2.self-193432e902b3943f7e511bf7ba322e1ce098119d180978aaff50918567da9361.js:49 -- onload

for the following hook:

suite.hook :test_hook do
  ap 'wow, such test!'
end

Interesting thing is that I nevertheless got the console output "wow, such test!" - so the hook is working, but throwing an error anyways.

ZackMattor commented 8 years ago

Yeah, I get this same error... I'm trying to dive into it today. Its all working as expected but throws a TON of errors when i'm running my test suite. We've been just living with it for about 2 months now. 🐻

jejacks0n commented 8 years ago

so, it looks like this:

https://github.com/modeset/teaspoon/blob/master/app/assets/javascripts/teaspoon/hook.coffee#L22

That will let you know (and will in theory break a test) if the response isn't a 200.. but it's using a variable that's not defined url.

I'll try and get to this today.

ZackMattor commented 8 years ago

I solved my case. I will have a PR open when i get back from lunch.

:success is not a valid status code symbol so the server always returns 500.

jejacks0n commented 8 years ago

ah, yes.. it's :ok, not :success.

jejacks0n commented 8 years ago

but the underlying problem is still there with the url variable.

ZackMattor commented 8 years ago

@jejacks0n, I'm thining about not relying on the url variable, but returning an error message from the server with a :not_found - 404 status code if there is no hook present (exactly what the hook.coffee throw was trying to show).

  def hook
    hooks = Teaspoon::Suite.new(params).hooks[params[:hook].to_s]

    if hooks.present?
      hooks.each { |hook| hook.call(hook_params(params[:args])) }
      head(:ok)
    else
      render status: :not_found, json: {err: "The `#{params[:hook].to_s}` hook is not defined in the `#{params[:suite].to_s}` suite "}
    end
  end

Then just render that err from the response in the throw. If you agree i'll open up a PR.

ZackMattor commented 8 years ago

Working error output.

image