Zombie.js "assert is not defined" for multiple visits?

I'm setting up integration testing with Zombie.js and Mocha, and running into the puzzling problem that only the first browser.visit() call seems to succeed. My specs look like this:

browser = new Browser site: "http://localhost:101010"

describe '/docs', ->
  ['app', 'server', 'timetable', 'util'].forEach (file) ->
    describe "/#{file}.html", -> it "documents #{file}.coffee", (done) ->
      browser.visit "/docs/#{file}.html", ->
        browser.text('title').should.equal "#{file}.coffee"
        do done

The first of those tests, which loads /docs/app.html, passes without incident. However, all subsequent tests fail, producing a stacktrace like the following:

 ReferenceError: assert is not defined
  at Object.HTML5Parser.phases.inBody.startTagBody (/home/$USER/projects/timetable/node_modules/zombie/node_modules/html5/lib/html5/parser.js:1828:4)
  at Object.HTML5Parser.phases.base.processStartTag (/home/$USER/projects/timetable/node_modules/zombie/node_modules/html5/lib/html5/parser.js:65:40)
  at EventEmitter.Parser.do_token (/home/$USER/projects/timetable/node_modules/zombie/node_modules/html5/lib/html5/parser.js:2436:21)
  at EventEmitter.<anonymous> (/home/$USER/projects/timetable/node_modules/zombie/node_modules/html5/lib/html5/parser.js:2457:30)
  at EventEmitter.emit (events.js:117:20)
  at EventEmitter.emitToken (/home/$USER/projects/timetable/node_modules/zombie/node_modules/html5/lib/html5/tokenizer.js:99:9)
  at emit_current_token (/home/$USER/projects/timetable/node_modules/zombie/node_modules/html5/lib/html5/tokenizer.js:873:3)
  at tag_name_state (/home/$USER/projects/timetable/node_modules/zombie/node_modules/html5/lib/html5/tokenizer.js:400:4)
  at EventEmitter.<anonymous> (/home/$USER/projects/timetable/node_modules/zombie/node_modules/html5/lib/html5/tokenizer.js:941:10)
  at EventEmitter.emit (events.js:95:17)
  at EventEmitter.HTML5Tokenizer.pump (/home/$USER/projects/timetable/node_modules/zombie/node_modules/html5/lib/html5/tokenizer.js:932:11)
  at EventEmitter.HTML5Tokenizer.tokenize (/home/$USER/projects/timetable/node_modules/zombie/node_modules/html5/lib/html5/tokenizer.js:89:23)
  at EventEmitter.Parser.parse (/home/$USER/projects/timetable/node_modules/zombie/node_modules/html5/lib/html5/parser.js:2391:17)
  at HtmlToDom.appendHtmlToElement (/home/$USER/projects/timetable/node_modules/zombie/node_modules/jsdom/lib/jsdom/browser/htmltodom.js:91:50)
  at Object.innerHTML (/home/$USER/projects/timetable/node_modules/zombie/node_modules/jsdom/lib/jsdom/browser/index.js:481:17)
  at Object.core.HTMLDocument.write (/home/$USER/projects/timetable/node_modules/zombie/node_modules/jsdom/lib/jsdom/level2/html.js:406:22)
  at Object.exports.jsdom (/home/$USER/projects/timetable/node_modules/zombie/node_modules/jsdom/lib/jsdom.js:70:9)
  at History._createDocument (/home/$USER/projects/timetable/node_modules/zombie/lib/zombie/history.js:174:22)
  at /home/$USER/projects/timetable/node_modules/zombie/lib/zombie/history.js:126:30
  at /home/$USER/projects/timetable/node_modules/zombie/lib/zombie/resources.js:147:16
  at Request._callback (/home/$USER/projects/timetable/node_modules/zombie/lib/zombie/resources.js:335:16)
  at Request.self.callback (/home/$USER/projects/timetable/node_modules/zombie/node_modules/request/main.js:120:22)
  at Request.EventEmitter.emit (events.js:98:17)
  at Request.<anonymous> (/home/$USER/projects/timetable/node_modules/zombie/node_modules/request/main.js:633:16)
  at Request.EventEmitter.emit (events.js:95:17)
  at IncomingMessage.<anonymous> (/home/$USER/projects/timetable/node_modules/zombie/node_modules/request/main.js:595:14)
  at IncomingMessage.EventEmitter.emit (events.js:117:20)
  at _stream_readable.js:872:14
  at process._tickCallback (node.js:415:13)

Is Zombie's browser.visit() not intended to be called more than once, or is there some other issue here?

Editing to note versions:

  • Node.js v0.10.1
  • Mocha v1.8.1
  • Chai v1.5.0
  • Zombie.js v1.4.1

It seems this is a compatibility issue arising in Node versions >=0.10, as mentioned here: https://github.com/assaf/zombie/issues/487

The workaround mentioned at https://github.com/assaf/zombie/issues/487#issuecomment-15548684 solves my particular problem. I added the following code to my testi/common.coffee file immediately before importing Zombie:

do patchEventEmitterToHideMaxListenerWarning = ->
  return if global.eventEmitterPatched
  global.eventEmitterPatched = true
  events = require 'events'
  Old = events.EventEmitter
  events.EventEmitter = ->
    this.setMaxListeners(0)
  events.EventEmitter.prototype = Old.prototype

Having done so, all my tests pass without complaint. I expect that this issue will be patched up in future Zombie revisions, but for now the above hack renders it workable.