Valid unit tests always fail when run through phantomjs on Ubuntu or Debian #174

Closed
blairvanderhoof opened this Issue Jan 8, 2012 · 10 comments

Comments

Projects
None yet
7 participants

Please see the following discussion:
https://github.com/elemoine/jasmine/commit/760a61a65f34921f1a1e9742cef75704ab53355b#commitcomment-847068

More info
http://groups.google.com/group/jasmine-js/browse_thread/thread/4712b34f2099f05e

There is a suggested fix with jasmine.js to make it work.

Any ideas on if this is a jasmine bug that can be fixed?

@ghost

ghost commented Jan 8, 2012

.

jcoglan commented Feb 8, 2012

I've been digging into this and found the following rather bizarre problem that Jasmine has while installing its matchers. Apply this diff:

diff --git a/lib/jasmine-core/jasmine.js b/lib/jasmine-core/jasmine.js
index 2e562a8..ee2891d 100644
--- a/lib/jasmine-core/jasmine.js
+++ b/lib/jasmine-core/jasmine.js
@@ -1155,6 +1155,15 @@ jasmine.Matchers.prototype.report = function(result, failing_message, details) {

 jasmine.Matchers.wrapInto_ = function(prototype, matchersClass) {
   for (var methodName in prototype) {
+    if (methodName === 'toEqual') {
+      console.log(prototype['toEqual'].toString());
+      console.log(prototype.toEqual.toString());
+      console.log(prototype[methodName].toString());
+      console.log(methodName);
+      console.log(methodName === 'toEqual');
+      console.log(methodName == 'toEqual');
+      console.log(typeof methodName);
+    }
     if (methodName == 'report') continue;
     var orig = prototype[methodName];
     matchersClass.prototype[methodName] = jasmine.Matchers.matcherFn_(methodName, orig);

Here's what should be output when you run this (running in a browser, or using the Ruby Harmony gem):

function (expected) {
    return this.env.equals_(this.actual, expected);
}
function (expected) {
    return this.env.equals_(this.actual, expected);
}
function (expected) {
    return this.env.equals_(this.actual, expected);
}
toEqual
true
true
string

Here's what is output by PhantomJS on Ubuntu:

function (expected) {
  return this.env.equals_(this.actual, expected);
}
function (expected) {
  return this.env.equals_(this.actual, expected);
}
function (expected) {
  return this.actual !== expected;
}
toEqual
true
true
string

So prototype.toEqual and prototype[methodName] give different values even though methodName === 'toEqual'. I'm not sure why this is -- I run the JS.Class project, whose test framework works fine on Phantom and uses this for in idiom all over the place to set up prototypes.

jcoglan commented Feb 8, 2012

Additionally, this line inserted on line 730 fixes the problem but only for toEqual:

this.matchersClass.prototype.toEqual = jasmine.Matchers.prototype.toEqual;

Thanks jcoglan, hoping they can publish an update to make jasmine compatible with phantom soon.

Contributor

ragaskar commented Feb 14, 2012

This sounds more like an issue with PhantomJS than Jasmine. On first glance it looks like something is getting weirdly clobbered on the prototype.

Can we figure out why PhantomJS is doing this? If Jasmine is truly doing something illegal, we'll change it, but it sounds more like there's a Phantom issue here.

jcoglan commented Feb 14, 2012

It certainly looks like a PhantomJS issue, and I've reported this thread on their issue tracker. The weird thing is why does this instance of a very common idiom break, but most everything else runs?

also why is it not broken for phantomjs on the mac?

philpill commented Apr 1, 2012

PhantomJS 1.5 was recently released - any chance the issue might've been fixed?

Contributor

infews commented May 27, 2013

We've changed the matchers implementation a lot for 2.0. See the matchers_redo branch.

There was some crazy indirect, less-performant wrapping going on. This is far more straightforward now.

I've added to an existing story in our backlog to add PhantomJS to the upcoming cross-browser CI build. We should be able to find this during development and at least code around it.

We do have several PhantomJS builds on projects at Pivotal Labs and we've not seen this. Not that it means anything.

Closing.

@infews infews closed this May 27, 2013

qris commented Jul 23, 2014

Try PhantomJS 2.0, which fixed a bunch of weird javascript problems for me: things that worked fine in the browser but failed in PhantomJS for no apparent reason.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment