Search code examples
node.jszombie.js

'Maximum call stack size exceeded' loading jQuery page with zombie.js


For about 4 days, most of my functional test suite on a node.js project has been failing, both in CI on linux and locally on OS X. I don't think it's due to any changes in my codebase, as I can rollback to earlier states of the git repo and see tests which used to pass are now failing similarly. The fact that it's failing on different platforms makes me think it's unlikely to be a particularly local environment change.

I suspect it's likely to be a problem somewhere in the dependency tree, and most likely in one of the packages used by zombie.js, as my app still seems to work fine. However, I have no record of the versions of all the packages in the tree when tests last worked.

I've reduced to the following test case:

so_test.js

"use strict";

var zombie = require('zombie');
var browser = zombie.create({ debug: true });
var assert = require('assert');

describe('Stack Overflow', function() {
  it('should be alive', function(done) {
    browser.visit('http://stackoverflow.com/')
      .then(function() {
        browser.dump();

        assert.equal(browser.location.pathname, '/', 'It is not the SO home page.');
        assert.ok(browser.success, 'It did not load successfully.');
      })
      .then(done, done);
  });
});

which fails for me as follows:

$ mocha -R spec test/functional/stack_overflow.js 


  Stack Overflow
Zombie: Opened window http://stackoverflow.com/ 
Zombie: GET http://stackoverflow.com/ => 200
Zombie: Loaded document http://stackoverflow.com/
Zombie: GET http://cdn.sstatic.net/Js/stub.en.js?v=26cc3a09b135 => 200
Zombie: GET http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js => 200
Maximum call stack size exceeded undefined
$ is not defined ReferenceError: $ is not defined
    at <anonymous>:1:8168
    at Contextify.sandbox.run (/Users/nanoamp/src/p/node_modules/zombie/node_modules/jsdom/node_modules/contextify/lib/contextify.js:12:24)
    at DOMWindow.window._evaluate (/Users/nanoamp/src/p/node_modules/zombie/lib/zombie/window.js:188:25)
    at Object.HTML.languageProcessors.javascript (/Users/nanoamp/src/p/node_modules/zombie/lib/zombie/scripts.js:23:21)
    at define.proto._eval (/Users/nanoamp/src/p/node_modules/zombie/node_modules/jsdom/lib/jsdom/level2/html.js:1480:47)
    at loaded (/Users/nanoamp/src/p/node_modules/zombie/lib/zombie/scripts.js:74:23)
    at /Users/nanoamp/src/p/node_modules/zombie/node_modules/jsdom/lib/jsdom/level2/html.js:76:20
    at Object.item.check (/Users/nanoamp/src/p/node_modules/zombie/node_modules/jsdom/lib/jsdom/level2/html.js:345:11)
    at Object.item.check (/Users/nanoamp/src/p/node_modules/zombie/node_modules/jsdom/lib/jsdom/level2/html.js:348:23)
    at /Users/nanoamp/src/p/node_modules/zombie/node_modules/jsdom/lib/jsdom/level2/html.js:363:12

... similar deleted for brevity ...

Zombie: Event loop is empty
    1) should be alive


  0 passing (2s)
  1 failing

  1) Stack Overflow should be alive:
     Maximum call stack size exceeded

If I change the URL to www.google.com (which doesn't use jQuery) it passes. If I change zombie.js for another version between 2.0.0-alpha31 (which was working before) and 2.0.4, it makes no difference. On my original code, I can change jQuery version loaded freely between 1.7 and 1.11 without benefit. Whilst jQuery seems to be a trigger, I don't know if it's anything specific to that library, or just the fact that it hooks heavily into the DOM.

I've also put the test case on Runnable: http://runnable.com/VDf4OLzyU64cSSuz/zombie-js-test-loading-page-with-jquery-for-node-js-and-mocha (although it seems a bit flaky at the time of writing).

Can anyone suggest how to resolve this or, failing that, how to better investigate?


Solution

  • It now works correctly with zombie 2.0.7.

    I finally managed to retrieve the dependency tree from of my previous working version from logs, which has allowed me to track down the specific source of the problem:

    [email protected] <-- last working version
    - [email protected]
    -- [email protected]
    
    [email protected] <-- unchanged top-level package.json
    - [email protected]           routine `npm install` must've updated deeper cssstyle
    -- [email protected]
    
    zombie 2.0.4         <-- tried updating zombie, still failing
    - [email protected]
    -- [email protected]
    -- [email protected]
    
    zombie 2.0.7         <-- working today
    - [email protected]
    -- [email protected]
    -- [email protected]
    -- [email protected]
    

    If I recreated the exact initial working package tree and did:

    cd node_modules/zombie/node_modules/jsdom && npm install [email protected]
    

    then it would stop working. I therefore attribute the problem to an incompatibility introduced in the cssstyle dependency of the jsdom dependency of zombie.js. So much for the node.js module pattern saving us from dependency hell :)