Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fix JSDOM queue and with it issue #6.

  • Loading branch information...
commit d47f08643670ed87dcfc3bf32d532850b2711443 1 parent 6ba4058
Assaf Arkin assaf authored
9 CHANGELOG.md
View
@@ -1,6 +1,15 @@
zombie.js-changelog(1) -- Changelog
===================================
+
+## Version 0.7.7 2010-12-28
+
+Fix JSDOM queue and with it issue #6.
+
+ 189 Tests
+ 2.3 sec to complete
+
+
## Version 0.7.6 2010-12-28
HTML5 doesn't play nice with JSDOM, bringing back html-parser to handle
2  package.json
View
@@ -1,6 +1,6 @@
{
"name": "zombie",
- "version": "0.7.6",
+ "version": "0.7.7",
"description": "Insanely fast, full-stack, headless testing using node.js",
"homepage": "http://zombie.labnotes.org/",
"author": "Assaf Arkin <assaf@labnotes.org> (http://labnotes.org/)",
2  src/zombie/browser.coffee
View
@@ -126,6 +126,7 @@ class Browser extends require("events").EventEmitter
#
# Returns a string
this.text = (selector, context)->
+ return "" unless @document.documentElement
elements = if selector then (context || @document).querySelectorAll(selector).toArray() else [@document]
elements.map((e)-> e.textContent).join("")
@@ -138,6 +139,7 @@ class Browser extends require("events").EventEmitter
#
# Returns a string
this.html = (selector, context)->
+ return "" unless @document.documentElement
elements = if selector then (context || @document).querySelectorAll(selector).toArray() else [@document]
elements.map((e)-> e.outerHTML.trim()).join("")
2  src/zombie/eventloop.coffee
View
@@ -137,8 +137,8 @@ class EventLoop
# argument, a done callback. It must call the done callback when it
# completes processing, passing error and response arguments.
this.request = (request, fn)->
- browser.debug -> "#{request.method} #{url}"
url = request.url.toString()
+ browser.debug -> "#{request.method} #{url}"
requests.push url
pending = browser.record request
fn (err, response)->
1  src/zombie/history.coffee
View
@@ -59,6 +59,7 @@ class History
document = new aug.HTMLDocument(url: URL.format(url), deferClose: false)
jsdom.applyDocumentFeatures document
document.write = html.HTMLDocument.prototype._write
+ document.fixQueue()
window.document = document
# Make the actual request: called again when dealing with a redirect.
59 src/zombie/jsdom_patches.coffee
View
@@ -21,22 +21,6 @@ core.HTMLElement.prototype.dispatchEvent = (event)->
core.HTMLElement.prototype._eventDefault = (event)->
-# Scripts
-# -------
-
-# Need to use the same context for all the scripts we load in the same document,
-# otherwise simple things won't work (e.g $.xhr)
-core.languageProcessors =
- javascript: (element, code, filename)->
- document = element.ownerDocument
- window = document.parentWindow
- window.browser.debug -> "Running script from #{filename}" if filename
- if window
- ctx = vm.Script.createContext(window)
- script = new vm.Script(code, filename)
- script.runInContext ctx
-
-
# Links/Resources
# ---------------
@@ -75,7 +59,7 @@ core.resourceLoader.download = (url, callback)->
request.on "response", (response)->
response.setEncoding "utf8"
data = ""
- response.on "data", (chunk)-> data += chunk.toString()
+ response.on "data", (chunk)-> data += chunk
response.on "end", ()->
switch response.statusCode
when 301, 302, 303, 307
@@ -90,6 +74,18 @@ core.resourceLoader.download = (url, callback)->
# Scripts
# -------
+# Need to use the same context for all the scripts we load in the same document,
+# otherwise simple things won't work (e.g $.xhr)
+core.languageProcessors =
+ javascript: (element, code, filename)->
+ document = element.ownerDocument
+ window = document.parentWindow
+ window.browser.debug -> "Running script from #{filename}" if filename
+ if window
+ ctx = vm.Script.createContext(window)
+ script = new vm.Script(code, filename)
+ script.runInContext ctx
+
# Here we deal with four JSDOM issues:
# - JSDOM assumes a SCRIPT element would have one text node, it may have
# more, and in the second case, it has none.
@@ -173,3 +169,32 @@ core.HTMLDocument.prototype._write = (html)->
@_parser.parse(html)
html
core.HTMLDocument.prototype.writeln = (html)-> @write html + "\n"
+
+
+# Queue
+# -----
+
+# Fixes two bugs in ResourceQueue:
+# - Queue doesn't process items that have empty data (this.data == "")
+# - Should change tail to null if current item is tail, but should not
+# change tail to next, since item.next may be few items before tail
+core.HTMLDocument.prototype.fixQueue = ->
+ @_queue.push = (callback)->
+ q = this
+ item =
+ prev: q.tail
+ check: ()->
+ if !q.paused && (this.data != undefined || this.err) && !this.prev # fix #1
+ callback(this.err, this.data)
+ if q.tail == this # fix #2
+ q.tail = null
+ if this.next
+ this.next.prev = null
+ this.next.check()
+ if q.tail
+ q.tail.next = item
+ q.tail = item
+ return (err, data)->
+ item.err = err
+ item.data = data
+ item.check()
Please sign in to comment.
Something went wrong with that request. Please try again.