jejacks0n / teaspoon

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

Extra failing test being run on command line #159

Closed mykoweb closed 10 years ago

mykoweb commented 10 years ago

I'm pretty new to Teaspoon so this may be user error.

I'm running Rails 4.0.2, Ruby 2.0.0p353, Teaspoon 0.7.8, Qunit, and Ember 1.3.0. I only have one test and it passes when I run teaspoon from the browser.

However, when I try to run from the command line, it runs my one and only passing test, but then it seems to run another test and that test fails. I can't figure out what that second test is. I've looked in my assets and tests directories to try to find this rogue test and can't find it. Here is the output:

[~/Projects/Kp/kp](add-ember) $ bundle exec teaspoon test/javascripts/models/director_test.js
Starting the Teaspoon server...
Teaspoon running default suite at http://127.0.0.1:63755/teaspoon/default?file[]=/Users/mk/Projects/Kp/kp/test/javascripts/models/director_test.js
DEBUG: -------------------------------
DEBUG: Ember      : 1.3.0
DEBUG: Ember Data : 1.0.0-beta.4
DEBUG: Handlebars : 1.2.1
DEBUG: jQuery     : 1.10.2
DEBUG: -------------------------------
.F

Failures:

  1)  global failure (1, 0, 1)
     Failure/Error: TypeError: 'undefined' is not a function (evaluating 'get$(this, 'findUser').bind(this)')

Finished in 0.01800 seconds
2 examples, 1 failure

Failed examples:

teaspoon -s default --filter="undefined global failure"

[~/Projects/Kp/kp](add-ember) $

My test_helper.js file includes all the relevant JS files:

//= require application
//= require_tree .
//= require_self

Here is the manifest from application.js:

//= require jquery
//= require handlebars
//= require ember
//= require ember-data
//= require ember-auth
//= require ember-auth-request-jquery
//= require ember-auth-response-json
//= require ember-auth-strategy-token
//= require ember-auth-session-cookie
//= require ember-auth-module-ember-data
//= require_self
//= require kp

and the manifest from kp.js:

//= require ./store
//= require_tree ./mixins
//= require_tree ./models
//= require_tree ./controllers
//= require_tree ./views
//= require_tree ./helpers
//= require_tree ./components
//= require_tree ./templates
//= require ./router
//= require_tree ./routes
//= require_self

I looked in all of these files and directories to see if some errant test was defined, but there is none.

Any clue as to where that second test is coming from and why it's failing?

Again, when I run teaspoon from the browser, it runs fine and this errant test is not run.

Thanks

jejacks0n commented 10 years ago

So, it may pass in the browser, but you probably see the same exception if you open the debug console.. correct? I'll move forward with that assumption, but it may be incorrect. I've never seen the get$ method, but it may exist in one of your dependencies, or it could be a typo? @gvarela took a quick look, and thinks it may be a closure issue.

If you want advice about what you're using to test with, you may consider jasmine over qunit.

Either way, let me know what you figure out.

jejacks0n commented 10 years ago

Oh, to clarify, it's not an errant test, it's an exception that qunit captures.. you'll notice it's a "global failure" -- meaning you shouldn't have any exceptions.

mykoweb commented 10 years ago

I do not see the same exception in the debug console which is weird.

I found the get$ method in the ember-auth-* gems. When I removed these gems from the manifest, the test passes without the global failure.

I'll dig some more to see why this is failing the way it is. Closing this issue.

Thanks

jejacks0n commented 10 years ago

Good. It's worth mentioning, that phantomjs (the default runner) is pretty much the same as a browser, but it's not entirely 1:1.. If you want to use those, try using the selenium runner, because it will fire up firefox and run your tests in a full browser. If you're curious you can give that a shot, and see if it has something to do with phantomjs vs a real browser.

mykoweb commented 10 years ago

I dug some more and it looks like it may be a browser issue.

The piece of code causing the error is from one of the ember-auth gems (ember-auth-module-ember-data):

get$(this, 'auth').addHandler('signInSuccess', get$(this, 'findUser').bind(this));

This code is automatically generated by EmberScript.

Anyway, when I debug in the Chrome console (btw, the tests are passing in Chrome without errors), it looks like my tests are properly parsing native code provided by Chrome. Here is the output from the debug console:

> get$(this, 'findUser').bind(this).toString()
  "function () { [native code] }"

However, when doing the same thing in Safari (where the tests are passing, but I see an error in the debug console), this is what I get:

> get$(this, 'findUser').bind(this).toString()
  TypeError: 'undefined' is not an object (evaluating 'get$(this, 'findUser').bind')
    line: 2
    message: "'undefined' is not an object (evaluating 'get$(this, 'findUser').bind')"
    stack: "eval code↵eval@[native code]↵_evaluateOn↵↵_evaluateAndWrap↵↵evaluate↵↵[native code]"
    __proto__: Error
      constructor: function TypeError() {
      message: ""
      name: "TypeError"
      toString: function toString() {
      __proto__: Error

In PhantomJS, I get the same 'undefined' error.

At least I have tests working in Chrome. Switching to Selenium won't help since this error also occurs in Firefox.

Any ideas on how I could resolve this would be greatly appreciated, other than just running my tests in Chrome.

Thanks.

jejacks0n commented 10 years ago

Ah, I've seen this issue before -- and it has nothing to do with Teaspoon etc.. I'll help by clarifying, but in the future please be kind to open source devs and do the digging before creating an issue. =) Not meant to be a dig, but I do have a day job.

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind

.bind in your case is binding the function scope, but that's not available everywhere.. phantomjs is safari more or less, so it's good that you are checking there -- it will give you the same results 99% of the time. The link I provide has a polyfill, so you may want to use that to get it behaving everywhere. That's your problem.

jejacks0n commented 10 years ago

see #139 as well.

mykoweb commented 10 years ago

Thanks @jejacks0n, and apologies for the bother. Cheers

mykoweb commented 10 years ago

BTW, I added the polyfill and it resolved the issue.

Many thanks @jejacks0n !