Skip to content
Browse files

Fix browser.clock to user Date.now instead of new Date (faster!)

Fix browser.dump()

In debug mode, show when firing timeout/interval.
  • Loading branch information...
1 parent 4582104 commit 65c84ccf12bec3eec76b425fd0e562de80bae770 @assaf assaf committed
Showing with 26 additions and 17 deletions.
  1. +6 −0 CHANGELOG.md
  2. +9 −9 spec/script-spec.coffee
  3. +3 −2 src/zombie/browser.coffee
  4. +2 −2 src/zombie/cookies.coffee
  5. +5 −3 src/zombie/eventloop.coffee
  6. +1 −1 src/zombie/storage.coffee
View
6 CHANGELOG.md
@@ -11,6 +11,12 @@ Fixes #71 cookie names now preserve case.
Fixes #69 incorrectly resolving partial URLs in XHR requests.
+Fixes browser.clock to use Date.now instead of new Date (faster).
+
+Fixes browser.dump.
+
+In debug mode, show when firing timeout/interval.
+
293 Tests
3.6 sec to complete
View
18 spec/script-spec.coffee
@@ -21,7 +21,7 @@ brains.get "/script/order", (req, res)-> res.send """
"""
brains.get "/script/order.js", (req, res)-> res.send "document.title = document.title + 'One'";
-brains.get "/dead", (req, res)-> res.send """
+brains.get "/script/dead", (req, res)-> res.send """
<html>
<head>
<script src="/jquery.js"></script>
@@ -64,7 +64,7 @@ brains.get "/script/append", (req, res)-> res.send """
</html>
"""
-brains.get "/living", (req, res)-> res.send """
+brains.get "/script/living", (req, res)-> res.send """
<html>
<head>
<script src="/jquery.js"></script>
@@ -73,7 +73,7 @@ brains.get "/living", (req, res)-> res.send """
</head>
<body>
<div id="main">
- <a href="/dead">Kill</a>
+ <a href="/script/dead">Kill</a>
<form action="#/dead" method="post">
<label>Email <input type="text" name="email"></label>
<label>Password <input type="password" name="password"></label>
@@ -141,25 +141,25 @@ vows.describe("Scripts").addBatch(
"should not run scripts": (browser)-> assert.equal browser.document.title, "Zero"
"run app":
- zombie.wants "http://localhost:3003/living"
+ zombie.wants "http://localhost:3003/script/living"
"should execute route": (browser)-> assert.equal browser.document.title, "The Living"
- "should change location": (browser)-> assert.equal browser.location, "http://localhost:3003/living#/"
+ "should change location": (browser)-> assert.equal browser.location.href, "http://localhost:3003/script/living#/"
"move around":
topic: (browser)->
browser.visit browser.location.href + "dead", @callback
"should execute route": (browser)-> assert.equal browser.text("#main"), "The Living Dead"
- "should change location": (browser)-> assert.equal browser.location.href, "http://localhost:3003/living#/dead"
+ "should change location": (browser)-> assert.equal browser.location.href, "http://localhost:3003/script/living#/dead"
"live events":
- zombie.wants "http://localhost:3003/living"
+ zombie.wants "http://localhost:3003/script/living"
topic: (browser)->
browser.fill("Email", "armbiter@zombies").fill("Password", "br41nz").
pressButton "Sign Me Up", @callback
- "should change location": (browser)-> assert.equal browser.location, "http://localhost:3003/living#/"
+ "should change location": (browser)-> assert.equal browser.location.href, "http://localhost:3003/script/living#/"
"should process event": (browser)-> assert.equal browser.document.title, "Signed up"
"evaluate":
- zombie.wants "http://localhost:3003/living"
+ zombie.wants "http://localhost:3003/script/living"
topic: (browser)->
browser.evaluate "document.title"
"should evaluate in context and return value": (title)-> assert.equal title, "The Living"
View
5 src/zombie/browser.coffee
@@ -195,7 +195,7 @@ class Browser extends require("events").EventEmitter
#
# You can change this to advance the system clock during tests. It will
# also advance when handling timeout/interval events.
- @clock = new Date().getTime()
+ @clock = Date.now()
# ### browser.now => Date
#
# The current system time according to the browser (see also
@@ -655,6 +655,7 @@ class Browser extends require("events").EventEmitter
# doesn't agree with jQuery, Sammy and other scripts I tested,
# so each script gets a new context.
context = vm.Script.createContext(window)
+
# But we need to carry global variables from one script to the
# next, so we're going to store them in window._vars and add them
# back to the new context.
@@ -662,7 +663,7 @@ class Browser extends require("events").EventEmitter
context[v[0]] = v[1] for v in @window._vars
script = new vm.Script(code, filename || "eval")
try
- return script.runInContext context
+ return script.runInContext(context)
catch ex
this.log ex.stack.split("\n").slice(0,2)
throw ex
View
4 src/zombie/cookies.coffee
@@ -182,7 +182,7 @@ exports.use = (browser)->
for path, in_path of in_domain
for name, cookie of in_path
serialized.push serialize(browser, domain, path, name, cookie)
- serialized.join("\n")
+ serialized
# browser.saveCookies uses this
save = ->
serialized = ["# Saved on #{new Date().toISOString()}"]
@@ -198,4 +198,4 @@ exports.use = (browser)->
cookie = deserialize(cookie)
new Cookies(browser, cookies, cookie.domain, cookie.path).set(cookie.name, cookie.value, cookie)
- return access: access, extend: extend, save: save, load: load
+ return access: access, extend: extend, save: save, load: load, dump: dump
View
8 src/zombie/eventloop.coffee
@@ -15,6 +15,7 @@ class EventLoop
when: browser.clock + delay
timeout: true
fire: =>
+ browser.log "Firing timeout #{handle}, delay: #{delay}"
try
browser.evaluate fn
finally
@@ -31,6 +32,7 @@ class EventLoop
when: browser.clock + delay
interval: true
fire: =>
+ browser.log "Firing interval #{handle}, interval: #{delay}"
try
browser.evaluate fn
finally
@@ -123,9 +125,9 @@ class EventLoop
this.dump = ()->
[ "The time: #{browser.clock}",
- "Timers: #{timers.length}",
- "Processing: #{processing}",
- "Waiting: #{waiting.length}" ]
+ "Timers: #{Object.keys(timers).length}",
+ "Processing: #{processing}",
+ "Waiting: #{waiting.length}" ]
exports.use = (browser)->
return new EventLoop(browser)
View
2 src/zombie/storage.coffee
@@ -134,7 +134,7 @@ class Storages
serialized.push "#{domain} session:"
for pair in pairs
serialized.push " #{pair[0]} = #{pair[1]}"
- serialized.join("\n")
+ serialized
# browser.saveStorage uses this
this.save = ->
serialized = ["# Saved on #{new Date().toISOString()}"]

0 comments on commit 65c84cc

Please sign in to comment.
Something went wrong with that request. Please try again.