Skip to content
Browse files

Switching from Vows to Mocha.

  • Loading branch information...
1 parent 471f976 commit f6c04bb6a7161a40e7d408e935186e1837ea8986 @assaf committed Apr 25, 2012
Showing with 3,446 additions and 3,012 deletions.
  1. +9 −0 CHANGELOG.md
  2. +10 −0 Makefile
  3. +1 −1 package.json
  4. +0 −338 spec/browser_spec.coffee
  5. +0 −219 spec/cookie_spec.coffee
  6. +0 −46 spec/event_source_spec.coffee
  7. +0 −178 spec/eventloop_spec.coffee
  8. +0 −812 spec/forms_spec.coffee
  9. +0 −41 spec/google_map_spec.coffee
  10. +0 −92 spec/helpers.coffee
  11. +0 −343 spec/history_spec.coffee
  12. +0 −42 spec/iframe_spec.coffee
  13. +0 −75 spec/jquery_compat_spec.coffee
  14. +0 −46 spec/resources_spec.coffee
  15. +0 −101 spec/selection_spec.coffee
  16. +0 −108 spec/storage_spec.coffee
  17. +0 −109 spec/websocket_spec.coffee
  18. +0 −155 spec/window_spec.coffee
  19. +0 −99 spec/xpath_spec.coffee
  20. +44 −39 spec/authentication_spec.coffee → test/authentication_test.coffee
  21. +388 −0 test/browser_test.coffee
  22. +249 −0 test/cookies_test.coffee
  23. +18 −12 spec/css_spec.coffee → test/css_test.coffee
  24. 0 {spec → test}/data/file_scheme.html
  25. 0 {spec → test}/data/file_scheme.js
  26. 0 {spec → test}/data/index.html
  27. 0 {spec → test}/data/random.txt
  28. 0 {spec → test}/data/zombie.jpg
  29. +207 −0 test/event_loop_test.coffee
  30. +48 −0 test/event_source_test.coffee
  31. +901 −0 test/forms_test.coffee
  32. +41 −0 test/google_map_test.coffee
  33. +40 −0 test/helpers/brains.coffee
  34. +20 −0 test/helpers/index.coffee
  35. +420 −0 test/history_test.coffee
  36. +45 −0 test/iframe_test.coffee
  37. +91 −0 test/jquery_compat_test.coffee
  38. +4 −0 test/mocha.opts
  39. +2 −2 spec/protocol_spec.coffee → test/protocol_test.coffee
  40. 0 {spec → test}/replay/maps.googleapis.com/1326781231603
  41. 0 {spec → test}/replay/maps.gstatic.com/1326781231887
  42. 0 {spec → test}/replay/maps.gstatic.com/1326781344752
  43. +45 −0 test/resources_test.coffee
  44. +169 −118 spec/script_spec.coffee → test/script_test.coffee
  45. 0 {spec → test}/scripts/jquery-1.4.4.js
  46. 0 {spec → test}/scripts/jquery-1.5.1.js
  47. 0 {spec → test}/scripts/jquery-1.6.3.js
  48. 0 {spec → test}/scripts/jquery-1.7.1.js
  49. 0 {spec → test}/scripts/sammy.js
  50. +103 −0 test/selection_test.coffee
  51. +134 −0 test/storage_test.coffee
  52. +117 −0 test/websocket_test.coffee
  53. +172 −0 test/window_test.coffee
  54. +51 −36 spec/xhr_spec.coffee → test/xhr_test.coffee
  55. +117 −0 test/xpath_test.coffee
View
9 CHANGELOG.md
@@ -2,6 +2,15 @@ zombie.js-changelog(7) -- Changelog
===================================
+## Version 0.13.0 2012-04-26
+
+Switched from testing with Vows to testing with Mocha. Tests now running
+sequentially.
+
+ 412 tests
+ 9.6 sec to complete
+
+
## Version 0.13.0 2012-04-25
Now requires Node 0.6.x or later. Also upgraded to CoffeeScript 1.3.1, which
View
10 Makefile
@@ -1,3 +1,13 @@
+default : test
+.PHONY : test setup
+
+
+# Setup everything
+setup :
+ npm install
+
+
+# Run test suite
test :
npm test
View
2 package.json
@@ -13,7 +13,7 @@
"html", "html5", "dom", "css", "javascript", "integration", "ajax", "full-stack", "DSL" ],
"main": "lib/zombie",
"scripts": {
- "test": "vows --spec"
+ "test": "mocha"
},
"engines": {
"node": ">= 0.6.0"
View
338 spec/browser_spec.coffee
@@ -1,338 +0,0 @@
-{ Vows, assert, brains, Browser } = require("./helpers")
-JSDOM = require("jsdom")
-
-
-Vows.describe("Browser").addBatch
-
- "browsing":
- topic: ->
- brains.get "/browser/scripted", (req, res)->
- res.send """
- <html>
- <head>
- <title>Whatever</title>
- <script src="/jquery.js"></script>
- </head>
- <body>Hello World</body>
- <script>
- document.title = "Nice";
- $(function() { $("title").text("Awesome") })
- </script>
- <script type="text/x-do-not-parse">
- <p>this is not valid JavaScript</p>
- </script>
- </html>
- """
-
- brains.get "/browser/errored", (req, res)->
- res.send """
- <script>this.is.wrong</script>
- """
-
-
- "open page":
- Browser.wants "http://localhost:3003/browser/scripted"
- "should create HTML document": (browser)->
- assert.instanceOf browser.document, JSDOM.dom.level3.html.HTMLDocument
- "should load document from server": (browser)->
- assert.match browser.html(), /<body>Hello World/
- "should load external scripts": (browser)->
- assert.ok jQuery = browser.window.jQuery, "window.jQuery not available"
- assert.typeOf jQuery.ajax, "function"
- "should run jQuery.onready": (browser)->
- assert.equal browser.document.title, "Awesome"
- "should return status code of last request": (browser)->
- assert.equal browser.statusCode, 200
- "should indicate success": (browser)->
- assert.ok browser.success
- "should have a parent": (browser)->
- assert.ok browser.window.parent
-
-
- "visit":
- "successful":
- topic: ->
- brains.ready =>
- browser = new Browser
- browser.visit "http://localhost:3003/browser/scripted", @callback
- "should call callback without error": ->
- assert.ok true
- "should pass browser to callback": (_, browser, status, errors)->
- assert.instanceOf browser, Browser
- "should pass status code to callback": (_, browser, status, errors)->
- assert.equal status, 200
- "should indicate success": (browser)->
- assert.ok browser.success
- "should pass zero errors to callback": (_, browser, status, errors)->
- assert.lengthOf errors, 0
- "should reset browser errors": (_, browser, status, errors)->
- assert.lengthOf browser.errors, 0
- "should have a resources object": (browser)->
- assert.ok browser.resources
-
- "with error":
- topic: ->
- brains.ready =>
- browser = new Browser
- browser.visit "http://localhost:3003/browser/errored", @callback
- "should call callback without error": ->
- assert.ok true
- "should indicate success": (browser)->
- assert.ok browser.success
- "should pass errors to callback": (_, browser, status, errors)->
- assert.lengthOf errors, 1
- assert.equal errors[0].message, "Cannot read property 'wrong' of undefined"
- "should set browser errors": (_, browser, status, errors)->
- assert.lengthOf browser.errors, 1
- assert.equal browser.errors[0].message, "Cannot read property 'wrong' of undefined"
-
- "404":
- topic: ->
- brains.ready =>
- browser = new Browser
- browser.visit "http://localhost:3003/browser/missing", @callback
- "should call callback without error": ->
- assert.ok true
- "should return status code": (_, browser, status)->
- assert.equal status, 404
- "should not indicate success": (browser)->
- assert.ok !browser.success
- "should capture response document": (browser)->
- assert.equal browser.source, "Cannot GET /browser/missing" # Express output
- "should return response document form text method": (browser)->
- assert.equal browser.text(), "Cannot GET /browser/missing" # Express output
- "should return response document form html method": (browser)->
- assert.equal browser.html(), "Cannot GET /browser/missing" # Express output
-
- "500":
- topic: ->
- brains.get "/browser/500", (req, res)->
- res.send "Ooops, something went wrong", 500
- brains.ready =>
- browser = new Browser
- browser.visit "http://localhost:3003/browser/500", @callback
- "should call callback without error": ->
- assert.ok true
- "should return status code 500": (_, browser, status)->
- assert.equal status, 500
- "should not indicate success": (browser)->
- assert.ok !browser.success
- "should capture response document": (browser)->
- assert.equal browser.source, "Ooops, something went wrong"
- "should return response document form text method": (browser)->
- assert.equal browser.text(), "Ooops, something went wrong"
- "should return response document form html method": (browser)->
- assert.equal browser.html(), "Ooops, something went wrong"
-
- "empty page":
- topic: ->
- brains.get "/browser/empty", (req, res)->
- res.send ""
- browser = new Browser
- browser.wants "http://localhost:3003/browser/empty", @callback
- "should load document": (browser)->
- assert.ok browser.body
- "should indicate success": (browser)->
- assert.ok browser.success
-
-.addBatch
-
- "event emitter":
- "successful":
- topic: ->
- brains.ready =>
- browser = new Browser
- browser.on "loaded", =>
- @callback null, browser
- browser.window.location = "http://localhost:3003/browser/scripted"
- "should fire load event": (browser)->
- assert.ok browser.visit
-
- "wait over":
- topic: ->
- brains.ready =>
- browser = new Browser
- browser.on "done", (browser)=>
- @callback null, browser
- browser.window.location = "http://localhost:3003/browser/scripted"
- browser.wait()
- "should fire done event": (browser)->
- assert.ok browser.visit
-
- "error":
- topic: ->
- brains.ready =>
- browser = new Browser
- browser.on "error", (error)=>
- @callback null, error
- browser.window.location = "http://localhost:3003/browser/errored"
- "should fire onerror event": (err)->
- assert.ok err.message && err.stack
- assert.equal err.message, "Cannot read property 'wrong' of undefined"
-
-
-.addBatch
-
- "with options":
- "per call":
- topic: ->
- browser = new Browser
- browser.wants "http://localhost:3003/browser/scripted", { runScripts: false }, @callback
- "should set options for the duration of the request": (browser)->
- assert.equal browser.document.title, "Whatever"
- "should reset options following the request": (browser)->
- assert.isTrue browser.runScripts
-
- "global":
- topic: ->
- Browser.site = "http://localhost:3003"
- browser = new Browser
- browser.wants "/browser/scripted", @callback
- "should set browser options from global options": (browser)->
- assert.equal browser.site, "http://localhost:3003"
- assert.equal browser.document.title, "Awesome"
- teardown: ->
- Browser.site = null
-
- "global with file: url scheme":
- topic: ->
- Browser.site = "file://" + __dirname + "/data/";
- browser = new Browser;
- browser.wants "index.html", @callback
- "should set the browser options from global options": (browser)->
- assert.equal browser.site, "file://" + __dirname + "/data/";
- assert.match browser.document.title, /Insanely fast, headless/
-
- "user agent":
- topic: ->
- brains.get "/browser/useragent", (req, res)->
- res.send "<html><body>#{req.headers["user-agent"]}</body></html>"
- browser = new Browser
- browser.wants "http://localhost:3003/browser/useragent", @callback
- "should send own version to server": (browser)->
- assert.match browser.text("body"), /Zombie.js\/\d\.\d/
- "should be accessible from navigator": (browser)->
- assert.match browser.window.navigator.userAgent, /Zombie.js\/\d\.\d/
-
- "specified":
- topic: (browser)->
- browser.visit "http://localhost:3003/browser/useragent", { userAgent: "imposter" }, @callback
- "should send user agent to server": (browser)->
- assert.equal browser.text("body"), "imposter"
- "should be accessible from navigator": (browser)->
- assert.equal browser.window.navigator.userAgent, "imposter"
-
-
-.addBatch
-
- "click link":
- topic: ->
- brains.get "/browser/head", (req, res)->
- res.send """
- <html>
- <body>
- <a href="/browser/headless">Smash</a>
- </body>
- </html>
- """
- brains.get "/browser/headless", (req, res)->
- res.send """
- <html>
- <head>
- <script src="/jquery.js"></script>
- </head>
- <body>
- <script>
- $(function() { document.title = "The Dead" });
- </script>
- </body>
- </html>
- """
- browser = new Browser(waitFor: 700)
- browser.wants "http://localhost:3003/browser/head", =>
- browser.clickLink "Smash", @callback
-
- "should change location": (_, browser)->
- assert.equal browser.location, "http://localhost:3003/browser/headless"
- "should run all events": (_, browser)->
- assert.equal browser.document.title, "The Dead"
- "should return status code": (_, browser, status)->
- assert.equal status, 200
-
-
- ###
- # NOTE: htmlparser doesn't handle tag soup.
- "tag soup using HTML5 parser":
- topic: ->
- brains.get "/browser/soup", (req, res)-> res.send """
- <h1>Tag soup</h1>
- <p>One paragraph
- <p>And another
- """
- browser = new Browser
- browser.wants "http://localhost:3003/browser/soup", { htmlParser: require("html5").HTML5 }, @callback
- "should parse to complete HTML": (browser)->
- assert.ok browser.querySelector("html head")
- assert.equal browser.text("html body h1"), "Tag soup"
- "should close tags": (browser)->
- paras = browser.querySelectorAll("body p").toArray().map((e)-> e.textContent.trim())
- assert.deepEqual paras, ["One paragraph", "And another"]
- ###
-
-
-.addBatch
-
-
- "fork":
- topic: ->
- brains.get "/browser/living", (req, res)->
- res.send """
- <html><script>dead = "almost"</script></html>
- """
- brains.get "/browser/dead", (req, res)->
- res.send """
- <html><script>dead = "very"</script></html>
- """
-
- browser = new Browser
- browser.wants "http://localhost:3003/browser/living", =>
- browser.cookies("www.localhost").update("foo=bar; domain=.localhost")
- browser.localStorage("www.localhost").setItem("foo", "bar")
- browser.sessionStorage("www.localhost").setItem("baz", "qux")
-
- forked = browser.fork()
- forked.visit "http://localhost:3003/browser/dead", (err)=>
- browser.cookies("www.localhost").update("foo=baz; domain=.localhost")
- browser.localStorage("www.localhost").setItem("foo", "new")
- browser.sessionStorage("www.localhost").setItem("baz", "value")
- @callback null, [forked, browser]
-
- "should not be the same object": ([forked, browser])->
- assert.notStrictEqual browser, forked
- "should have two browser objects": ([forked, browser])->
- assert.isNotNull forked
- assert.isNotNull browser
- "should navigate independently": ([forked, browser])->
- assert.equal browser.location.href, "http://localhost:3003/browser/living"
- assert.equal forked.location, "http://localhost:3003/browser/dead"
- "should manipulate cookies independently": ([forked, browser])->
- assert.equal browser.cookies("localhost").get("foo"), "baz"
- assert.equal forked.cookies("localhost").get("foo"), "bar"
- "should manipulate storage independently": ([forked, browser])->
- assert.equal browser.localStorage("www.localhost").getItem("foo"), "new"
- assert.equal browser.sessionStorage("www.localhost").getItem("baz"), "value"
- assert.equal forked.localStorage("www.localhost").getItem("foo"), "bar"
- assert.equal forked.sessionStorage("www.localhost").getItem("baz"), "qux"
- "should have independent history": ([forked, browser])->
- assert.equal "http://localhost:3003/browser/living", browser.location.href
- assert.equal "http://localhost:3003/browser/dead", forked.location.href
- "should have independent globals": ([forked, browser])->
- assert.equal browser.evaluate("window.dead"), "almost"
- assert.equal forked.evaluate("window.dead"), "very"
- "should clone history from source": ([forked, browser])->
- assert.equal "http://localhost:3003/browser/dead", forked.location.href
- forked.window.history.back()
- assert.equal "http://localhost:3003/browser/living", forked.location.href
-
-
-.export(module)
View
219 spec/cookie_spec.coffee
@@ -1,219 +0,0 @@
-{ Vows, assert, brains, Browser } = require("./helpers")
-
-
-brains.get "/cookies", (req, res)->
- res.cookie "_name", "value"
- res.cookie "_expires1", "3s", expires: new Date(Date.now() + 3000)
- res.cookie "_expires2", "5s", "Max-Age": 5000
- res.cookie "_expires3", "0s", expires: new Date(Date.now() - 100)
- res.cookie "_path1", "yummy", path: "/cookies"
- res.cookie "_path2", "yummy", path: "/cookies/sub"
- res.cookie "_path3", "wrong", path: "/wrong"
- res.cookie "_path4", "yummy", path: "/"
- res.cookie "_domain1", "here", domain: ".localhost"
- res.cookie "_domain2", "not here", domain: "not.localhost"
- res.cookie "_domain3", "wrong", domain: "notlocalhost"
- res.cookie "_http_only","value", httpOnly: true
- res.send "<html></html>"
-
-brains.get "/cookies/echo", (req,res)->
- cookies = ("#{k}=#{v}" for k,v of req.cookies).join("; ")
- res.send "<html>#{cookies}</html>"
-
-brains.get "/cookies_redirect", (req, res)->
- res.cookie "_expires4", "3s", expires: new Date(Date.now() + 3000), "Path": "/"
- res.redirect "/"
-
-brains.get "/cookies/empty", (req,res)->
- res.send "<html></html>"
-
-
-Vows.describe("Cookies").addBatch(
-
- "get cookies":
- Browser.wants "http://localhost:3003/cookies"
- "cookies":
- topic: (browser)->
- browser.cookies("localhost", "/cookies")
- "should have access to session cookie": (cookies)->
- assert.equal cookies.get("_name"), "value"
- "should have access to persistent cookie": (cookies)->
- assert.equal cookies.get("_expires1"), "3s"
- assert.equal cookies.get("_expires2"), "5s"
- "should not have access to expired cookies": (cookies)->
- assert.isUndefined cookies.get("_expires3")
- "should have access to cookies for the path /cookies": (cookies)->
- assert.equal cookies.get("_path1"), "yummy"
- "should have access to cookies for paths which are ancestors of /cookies": (cookies)->
- assert.equal cookies.get("_path4"), "yummy"
- "should not have access to other paths": (cookies)->
- assert.isUndefined cookies.get("_path2")
- assert.isUndefined cookies.get("_path3")
- "should have access to .domain": (cookies)->
- assert.equal cookies.get("_domain1"), "here"
- "should not have access to other domains": (cookies)->
- assert.isUndefined cookies.get("_domain2")
- assert.isUndefined cookies.get("_domain3")
-
- "host in domain":
- topic: (browser)->
- browser.cookies("host.localhost")
- "should not have access to domain cookies": (cookies)->
- assert.isUndefined cookies.get("_name")
- "should have access to .host cookies": (cookies)->
- assert.equal cookies.get("_domain1"), "here"
- "should not have access to other hosts' cookies": (cookies)->
- assert.isUndefined cookies.get("_domain2")
- assert.isUndefined cookies.get("_domain3")
-
- "document.cookie":
- topic: (browser)->
- browser.document.cookie
- "should return name/value pairs": (cookie)->
- assert.match cookie, /^(\w+=\w+; )+\w+=\w+$/
- "pairs":
- topic: (serialized)->
- pairs = serialized.split("; ").reduce (map, pair)->
- [name, value] = pair.split("=")
- map[name] = value
- map
- , {}
- "should include only visible cookies": (pairs)->
- keys = (key for key, value of pairs).sort()
- assert.deepEqual keys, "_domain1 _expires1 _expires2 _name _path1 _path4".split(" ")
- "should match name to value": (pairs)->
- assert.equal pairs._name, "value"
- assert.equal pairs._path1, "yummy"
- "should not include httpOnly cookies": (pairs)->
- for key, value of pairs
- assert.notEqual key, "_http_only"
-
-
- "host":
- Browser.wants "http://host.localhost:3003/cookies"
- "cookies":
- topic: (browser)->
- browser.cookies("localhost", "/cookies")
- "should be able to set domain cookies": (cookies)->
- assert.equal cookies.get("_domain1"), "here"
-
-
- "get cookies and redirect":
- Browser.wants "http://localhost:3003/cookies_redirect"
- "cookies":
- topic: (browser)->
- browser.cookies("localhost", "/")
- "should have access to persistent cookie": (cookies)->
- assert.equal cookies.get("_expires4"), "3s"
-
-
- "send cookies":
- topic: ->
- browser = new Browser()
- browser.cookies("localhost" ).set "_name", "value"
- browser.cookies("localhost" ).set "_expires1", "3s", "max-age": 3000
- browser.cookies("localhost" ).set "_expires2", "0s", "max-age": 0
- browser.cookies("localhost", "/cookies" ).set "_path1", "here"
- browser.cookies("localhost", "/cookies/echo" ).set "_path2", "here"
- browser.cookies("localhost", "/jars" ).set "_path3", "there", "path": "/jars"
- browser.cookies("localhost", "/cookies/fido" ).set "_path4", "there", "path": "/cookies/fido"
- browser.cookies("localhost", "/jars" ).set "_path5", "here", "path": "/cookies"
- browser.cookies("localhost", "/jars" ).set "_path6", "here"
- browser.cookies("localhost", "/jars/" ).set "_path7", "there"
- browser.cookies(".localhost" ).set "_domain1", "here"
- browser.cookies("not.localhost" ).set "_domain2", "there"
- browser.cookies("notlocalhost" ).set "_domain3", "there"
- browser.wants "http://localhost:3003/cookies/echo", =>
- cookies = browser.text("html").split(/;\s*/).reduce (all, cookie)->
- [name, value] = cookie.split("=")
- all[name] = value.replace(/^"(.*)"$/, "$1")
- all
- , {}
- @callback null, cookies
-
- "should send session cookie": (cookies)->
- assert.equal cookies._name, "value"
- "should pass persistent cookie to server": (cookies)->
- assert.equal cookies._expires1, "3s"
- "should not pass expired cookie to server": (cookies)->
- assert.isUndefined cookies._expires2
- "should pass path cookies to server": (cookies)->
- assert.equal cookies._path1, "here"
- assert.equal cookies._path2, "here"
- "should pass cookies that specified a different path when they were assigned": (cookies)->
- assert.equal cookies._path5, "here"
- "should pass cookies that didn't specify a path when they were assigned": (cookies)->
- assert.equal cookies._path6, "here"
- "should not pass unrelated path cookies to server": (cookies)->
- assert.isUndefined cookies._path3
- assert.isUndefined cookies._path4
- assert.isUndefined cookies._path7
- "should pass sub-domain cookies to server": (cookies)->
- assert.equal cookies._domain1, "here"
- "should not pass other domain cookies to server": (cookies)->
- assert.isUndefined cookies._domain2
- assert.isUndefined cookies._domain3
-
-
- "setting cookies from subdomains":
- topic: ->
- browser = new Browser()
- browser.cookies("www.localhost").update("foo=bar; domain=.localhost")
- @callback null, browser
- "should be accessible": (browser)->
- assert.equal "bar", browser.cookies("localhost").get("foo")
- assert.equal "bar", browser.cookies("www.localhost").get("foo")
-
-
- "setting Cookie header":
- topic: ->
- browser = new Browser()
- header = { cookie: "" }
- browser.cookies().update("foo=bar;")
- browser.cookies().addHeader header
- header
- "should send V0 header": (header)->
- assert.equal header.cookie, "foo=bar"
-
-
- "document.cookie":
- topic: ->
- browser = new Browser()
- @callback null, browser
- "setting cookie":
- topic: (browser)->
- browser.wants "http://localhost:3003/cookies/empty", =>
- browser.document.cookie = "foo=bar"
- @callback null, browser
- "should be available from document": (browser)->
- assert.equal browser.document.cookie, "foo=bar"
- "send request":
- topic: (browser)->
- browser.wants "http://localhost:3003/cookies/echo", =>
- cookies = browser.text("html").split(/;\s*/).reduce (all, cookie)->
- [name, value] = cookie.split("=")
- all[name] = value.replace(/^"(.*)"$/, "$1")
- all
- , {}
- @callback null, cookies
- "should send to server": (cookies)->
- assert.equal cookies.foo, "bar"
-
- "setting cookie with quotes":
- topic: (browser)->
- browser.wants "http://localhost:3003/cookies/empty", =>
- browser.document.cookie = "foo=bar\"baz"
- @callback null, browser
- "should be available from document": (browser)->
- assert.equal browser.cookies().get("foo"), "bar\"baz"
-
- "setting cookie with semicolon":
- topic: (browser)->
- browser.wants "http://localhost:3003/cookies/empty", =>
- browser.document.cookie = "foo=bar; baz"
- @callback null, browser
- "should be available from document": (browser)->
- assert.equal browser.cookies().get("foo"), "bar"
-
-
-).export(module)
View
46 spec/event_source_spec.coffee
@@ -1,46 +0,0 @@
-{ Vows, assert, brains, Browser } = require("./helpers")
-
-
-Vows.describe("EventSource").addBatch(
-
- "sse":
- topic: ->
- brains.get "/stream", (req, res)->
- res.writeHead 200,
- "Content-Type": "text/event-stream; charset=utf-8"
- "Cache-Control": "no-cache"
- "Connection": "keep-alive"
- res.write "event: test\nid: 1\ndata: first\n\n"
- setTimeout ->
- res.write "event: test\nid: 2\ndata: second\n\n"
- res.end()
- , 10
-
- brains.get "/streaming", (req, res)->
- res.send """
- <html>
- <head>
- <script>
- var source = new EventSource("/stream");
- window.events = [];
- source.addEventListener("test", function(event) {
- window.events.push(event.data)
- });
- </script>
- </head>
- </html>
- """
-
- brains.ready =>
- browser = new Browser
- browser.visit "http://localhost:3003/streaming"
- completed = (window)->
- return window.events && window.events.length == 2
- browser.wait completed, =>
- @callback null, browser.evaluate("window.events")
-
- "should stream to browse": (events)->
- assert.deepEqual events, ["first", "second"]
-
-
-).export(module)
View
178 spec/eventloop_spec.coffee
@@ -1,178 +0,0 @@
-{ Vows, assert, brains, Browser } = require("./helpers")
-
-
-Vows.describe("EventLoop").addBatch(
-
- "setTimeout":
- topic: ->
- brains.get "/eventloop/timeout", (req, res)->
- res.send """
- <html>
- <head><title>One</title></head>
- <body></body>
- </html>
- """
- @callback null
-
- "no wait":
- Browser.wants "http://localhost:3003/eventloop/timeout"
- topic: (browser)->
- browser.window.setTimeout ->
- @document.title += " Two"
- , 100
- @callback null, browser
- "should not fire any timeout events": (browser)->
- assert.equal browser.document.title, "One"
-
- "from timeout":
- Browser.wants "http://localhost:3003/eventloop/timeout"
- topic: (browser)->
- browser.window.setTimeout ->
- browser.window.setTimeout ->
- @document.title += " Two"
- browser.window.setTimeout ->
- @document.title += " Three"
- , 100
- , 100
- , 100
- browser.wait @callback
- "should not fire any timeout events": (browser)->
- assert.equal browser.document.title, "One Two Three"
-
- "wait for all":
- Browser.wants "http://localhost:3003/eventloop/timeout"
- topic: (browser)->
- browser.window.setTimeout ->
- @document.title += " Two"
- , 100
- browser.window.setTimeout ->
- @document.title += " Three"
- , 200
- browser.wait 250, @callback
- "should fire all timeout events": (browser)->
- assert.equal browser.document.title, "One Two Three"
-
- "cancel timeout":
- Browser.wants "http://localhost:3003/eventloop/timeout"
- topic: (browser)->
- first = browser.window.setTimeout ->
- @document.title += " Two"
- , 100
- second = browser.window.setTimeout ->
- @document.title += " Three"
- , 200
- setTimeout ->
- browser.window.clearTimeout second
- , 100
- browser.wait 300, @callback
- "should fire only uncancelled timeout events": (browser)->
- assert.equal browser.document.title, "One Two"
- "should not choke on invalid timers": (browser)->
- assert.doesNotThrow ->
- # clearTimeout should not choke when clearing an invalid timer
- # https://developer.mozilla.org/en/DOM/window.clearTimeout
- browser.window.clearTimeout undefined
-
- "outside wait":
- Browser.wants "http://localhost:3003/eventloop/timeout"
- topic: (browser)->
- browser.wants "http://localhost:3003/eventloop/function", =>
- browser.window.setTimeout (-> @document.title += "1"), 100
- browser.window.setTimeout (-> @document.title += "2"), 200
- browser.window.setTimeout (-> @document.title += "3"), 300
- browser.wait 100, =>
- setTimeout =>
- browser.wait 100, @callback
- , 300
- "should not fire": (browser)->
- assert.equal browser.document.title, "12"
-
-
- "setInterval":
- topic: ->
- brains.get "/eventloop/interval", (req, res)-> res.send """
- <html>
- <head><title></title></head>
- <body></body>
- </html>
- """
- @callback null
-
- "no wait":
- Browser.wants "http://localhost:3003/eventloop/interval"
- topic: (browser)->
- browser.window.setInterval ->
- @document.title += "."
- , 100
- @callback null, browser
- "should not fire any timeout events": (browser)->
- assert.equal browser.document.title, ""
-
- "wait once":
- Browser.wants "http://localhost:3003/eventloop/interval"
- topic: (browser)->
- browser.window.setInterval ->
- @document.title += "."
- , 100
- browser.wait 150, @callback
- "should fire interval event once": (browser)->
- assert.equal browser.document.title, "."
-
- "wait long enough":
- Browser.wants "http://localhost:3003/eventloop/interval"
- topic: (browser)->
- browser.window.setInterval ->
- @document.title += "."
- , 100
- browser.wait 350, @callback
- "should fire five interval event": (browser)->
- assert.equal browser.document.title, "..."
-
- "cancel interval":
- Browser.wants "http://localhost:3003/eventloop/interval"
- topic: (browser)->
- interval = browser.window.setInterval ->
- @document.title += "."
- , 100
- browser.wait 250, =>
- browser.window.clearInterval interval
- browser.wait 200, @callback
- "should fire only uncancelled interval events": (browser)->
- assert.equal browser.document.title, ".."
- "should not throw an exception with invalid interval": (browser)->
- assert.doesNotThrow ->
- # clearInterval should not choke on invalid interval
- browser.window.clearInterval undefined
-
- "outside wait":
- Browser.wants "http://localhost:3003/eventloop/interval"
- topic: (browser)->
- browser.wants "http://localhost:3003/eventloop/function", =>
- browser.window.setInterval (-> @document.title += "."), 100
- browser.wait 100, =>
- setTimeout =>
- browser.wait 100, @callback
- , 300
- "should not fire": (browser)->
- assert.equal browser.document.title, ".."
-
-
- "browser.wait function":
- topic: ->
- brains.get "/eventloop/function", (req, res)-> res.send """
- <html>
- <head><title></title></head>
- </html>
- """
- browser = new Browser
- browser.wants "http://localhost:3003/eventloop/function", =>
- browser.window.setInterval (-> @document.title += "."), 100
- gotFourDots = (window)->
- return window.document.title == "...."
- browser.wait gotFourDots, @callback
- "should not wait longer than specified": (browser)->
- assert.equal browser.document.title, "...."
-
-
-
-).export(module)
View
812 spec/forms_spec.coffee
@@ -1,812 +0,0 @@
-{ Vows, assert, brains, Browser } = require("./helpers")
-File = require("fs")
-Crypto = require("crypto")
-
-
-load_form = (callback)->
- brains.get "/forms/form", (req, res)->
- res.send """
- <html>
- <body>
- <form action="/forms/submit" method="post">
- <label>Name <input type="text" name="name" id="field-name"></label>
- <label for="field-email">Email</label>
- <input type="text" name="email" id="field-email"></label>
- <textarea name="likes" id="field-likes">Warm brains</textarea>
- <input type="password" name="password" id="field-password">
- <input type="badtype" name="invalidtype" id="field-invalidtype" />
- <input type="text" name="email2" id="field-email2" />
- <input type="text" name="email3" id="field-email3" />
- <input type="text" name="disabled_input_field" disabled id="disabled_input_field" />
- <input type="text" name="readonly_input_field" readonly id="readonly_input_field" />
-
- <label>Hungry</label>
- <label>You bet<input type="checkbox" name="hungry[]" value="you bet" id="field-hungry"></label>
- <label>Certainly<input type="checkbox" name="hungry[]" value="certainly" id="field-hungry-certainly"></label>
-
- <label for="field-brains">Brains?</label>
- <input type="checkbox" name="brains" value="yes" id="field-brains">
- <input type="checkbox" name="green" id="field-green" value="Super green!" checked="checked">
-
- <input type="checkbox" name="check" id="field-check" value="Huh?" checked="checked">
- <input type="checkbox" name="uncheck" id="field-uncheck" value="Yeah!">
-
- <label>Looks
- <select name="looks" id="field-looks">
- <option value="blood" label="Bloody"></option>
- <option value="clean" label="Clean"></option>
- <option value="" label="Choose one"></option>
- </select>
- </label>
- <label>Scary <input name="scary" type="radio" value="yes" id="field-scary"></label>
- <label>Not scary <input name="scary" type="radio" value="no" id="field-notscary" checked="checked"></label>
-
- <select name="state" id="field-state">
- <option>alive</option>
- <option>dead</option>
- <option>neither</option>
- </select>
-
- <span>First address</span>
- <label for='address1_street'>Street</label>
- <input type="text" name="addresses[][street]" value="" id="address1_street">
-
- <label for='address1_city'>City</label>
- <input type="text" name="addresses[][city]" value="" id="address1_city">
-
- <span>Second address</span>
- <label for='address2_street'>Street</label>
- <input type="text" name="addresses[][street]" value="" id="address2_street">
-
- <label for='address2_city'>City</label>
- <input type="text" name="addresses[][city]" value="" id="address2_city">
-
- <select name="kills" id="field-kills">
- <option>Five</option>
- <option>Seventeen</option>
- <option id="option-killed-thousands">Thousands</option>
- </select>
-
- <select name="unselected_state" id="field-unselected-state">
- <option>alive</option>
- <option>dead</option>
- </select>
-
- <select name="hobbies[]" id="field-hobbies" multiple="multiple">
- <option>Eat Brains</option>
- <option id="hobbies-messy">Make Messy</option>
- <option>Sleep</option>
- </select>
-
- <input type="unknown" name="unknown" value="yes">
- <input type="reset" value="Reset">
- <input type="submit" name="button" value="Submit">
- <input type="image" name="image" id="image_submit" value="Image Submit">
-
- <button name="button" value="hit-me">Hit Me</button>
-
- <input type="checkbox" id="field-prevent-check">
- <input type="radio" id="field-prevent-radio">
- </form>
- <div id="formless_inputs">
- <label>Hunter <input type="text" name="hunter_name" id="hunter-name"></label>
- <textarea name="hunter_hobbies">Killing zombies.</textarea>
- <input type="password" name="hunter_password" id="hunter-password">
- <input type="badtype" name="hunter_invalidtype" id="hunter-invalidtype" />
- <label>Weapons</label>
- <label>Chainsaw<input type="checkbox" name="hunter_weapon[]" value="chainsaw"></label>
- <label>Shotgun<input type="checkbox" name="hunter_weapon[]" value="shotgun"></label>
- <label>Type
- <select name="hunter_type">
- <option value="regular" label="Regular"></option>
- <option value="evil" label="Evil"></option>
- <option value="tiny" label="tiny"></option>
- </select>
- </label>
- <label>Powerglove <input name="hunter_powerglove" type="radio" value="glove"></label>
- <label>No powerglove <input name="hunter_powerglove" type="radio" value="noglove" checked="checked"></label>
- </div>
- </body>
- </html>
- """
-
- brains.post "/forms/submit", (req, res)->
- res.send """
- <html>
- <body>
- <div id="name">#{req.body.name}</div>
- <div id="likes">#{req.body.likes}</div>
- <div id="green">#{req.body.green}</div>
- <div id="brains">#{req.body.brains}</div>
- <div id="looks">#{req.body.looks}</div>
- <div id="hungry">#{JSON.stringify(req.body.hungry)}</div>
- <div id="state">#{req.body.state}</div>
- <div id="scary">#{req.body.scary}</div>
- <div id="state">#{req.body.state}</div>
- <div id="unselected_state">#{req.body.unselected_state}</div>
- <div id="hobbies">#{JSON.stringify(req.body.hobbies)}</div>
- <div id="addresses">#{JSON.stringify(req.body.addresses)}</div>
- <div id="unknown">#{req.body.unknown}</div>
- <div id="clicked">#{req.body.button}</div>
- <div id="image_clicked">#{req.body.image}</div>
- </body>
- </html>
- """
-
- browser = new Browser
- browser.wants "http://localhost:3003/forms/form", ->
- callback browser
-
-
-Vows.describe("Forms").addBatch
-
- "fill field":
- topic: ->
- load_form (browser)=>
- for field in ["email", "likes", "name", "password", "invalidtype", "email2"]
- do (field)->
- browser.querySelector("#field-#{field}").addEventListener "change", ->
- browser["#{field}Changed"] = true
- @callback null, browser
-
- "text input enclosed in label":
- topic: (browser)->
- browser.fill "Name", "ArmBiter"
- "should set text field": (browser)->
- assert.equal browser.querySelector("#field-name").value, "ArmBiter"
- "should fire change event": (browser)->
- assert.ok browser.nameChanged
-
- "email input referenced from label":
- topic: (browser)->
- browser.fill "Email", "armbiter@example.com"
- "should set email field": (browser)->
- assert.equal browser.querySelector("#field-email").value, "armbiter@example.com"
- "should fire change event": (browser)->
- assert.ok browser.emailChanged
-
- "textarea by field name":
- topic: (browser)->
- browser.fill "likes", "Arm Biting"
- "should set textarea": (browser)->
- assert.equal browser.querySelector("#field-likes").value, "Arm Biting"
- "should fire change event": (browser)->
- assert.ok browser.likesChanged
-
- "password input by selector":
- topic: (browser)->
- browser.fill ":password[name=password]", "b100d"
- "should set password": (browser)->
- assert.equal browser.querySelector("#field-password").value, "b100d"
- "should fire change event": (browser)->
- assert.ok browser.passwordChanged
-
- "input without a valid type":
- topic: (browser)->
- browser.fill ":input[name=invalidtype]", "some value"
- "should set value": (browser)->
- assert.equal browser.querySelector("#field-invalidtype").value, "some value"
- "should fire change event": (browser)->
- assert.ok browser.invalidtypeChanged
-
- "email2 input by node":
- topic: (browser)->
- browser.fill browser.querySelector("#field-email2"), "headchomper@example.com"
- "should set email2 field": (browser)->
- assert.equal browser.querySelector("#field-email2").value, "headchomper@example.com"
- "should fire change event": (browser)->
- assert.ok browser.email2Changed
-
- "disabled input can not be modified":
- topic: (browser)->
- browser.fill browser.querySelector("#disabled_input_field"), "yeahh"
- "should raise error": (browser)->
- assert.ok (browser instanceof Error)
-
- "readonly input can not be modified":
- topic: (browser)->
- browser.fill browser.querySelector("#readonly_input_field"), "yeahh"
- "should raise error": (browser)->
- assert.ok (browser instanceof Error)
-
- "should callback":
- topic: (browser)->
- browser.fill browser.querySelector("#field-email3"), "headchomper@example.com", @callback
- "should fire the callback": (_, browser)->
- assert.equal browser.querySelector("#field-email3").value, "headchomper@example.com"
-
-.addBatch
-
- "check box":
- topic: ->
- load_form (browser)=>
- for field in ["hungry", "brains", "green"]
- do (field)->
- browser.querySelector("#field-#{field}").addEventListener "click", ->
- browser["#{field}Clicked"] = true
- browser.querySelector("#field-#{field}").addEventListener "change", ->
- browser["#{field}Changed"] = true
- @callback null, browser
-
- "checkbox enclosed in label":
- topic: (browser)->
- browser.check "You bet"
- browser.wait @callback
- "should check checkbox": (browser)->
- assert.ok browser.querySelector("#field-hungry").checked
- "should fire change event": (browser)->
- assert.ok browser.hungryChanged
- "should fire clicked event": (browser)->
- assert.ok browser.hungryClicked
- "with callback":
- Browser.wants "http://localhost:3003/forms/form"
- topic: (browser)->
- browser.check "Brains?", @callback
- "should callback": (_, browser)->
- assert.ok browser.querySelector("#field-brains").checked
-
- "checkbox referenced from label":
- topic: (browser)->
- browser.check "Brains?"
- browser.wait @callback
- "should check checkbox": (browser)->
- assert.ok browser.querySelector("#field-brains").checked
- "should fire change event": (browser)->
- assert.ok browser.brainsChanged
- "uncheck with callback":
- Browser.wants "http://localhost:3003/forms/form"
- topic: (browser)->
- browser.check "Brains?"
- browser.uncheck "Brains?", @callback
- "should callback": (_, browser)->
- assert.ok !browser.querySelector("#field-brains").checked
-
- "checkbox by name":
- topic: (browser)->
- browser.check "green"
- browser["greenChanged"] = false
- browser.uncheck "green"
- browser.wait @callback
- "should uncheck checkbox": (browser)->
- assert.ok !browser.querySelector("#field-green").checked
- "should fire change event": (browser)->
- assert.ok browser.greenChanged
- "check callback":
- topic: (browser)->
- browser.check "uncheck", @callback
- "should callback": (_, browser)->
- assert.ok browser.querySelector("#field-uncheck").checked
- "uncheck callback":
- topic: (browser)->
- browser.uncheck "check", @callback
- "should callback": (_, browser)->
- assert.ok !browser.querySelector("#field-check").checked
-
- "prevent default":
- topic: (browser)->
- check_box = browser.$$("#field-prevent-check")
- values = [check_box.checked]
- check_box.addEventListener "click", (event)=>
- values.push check_box.checked
- event.preventDefault()
- browser.check check_box, =>
- values.push check_box.checked
- @callback null, values
- "should turn checkbox on then off": (values)->
- assert.deepEqual values, [false, true, false]
-
-
-.addBatch
-
- "radio buttons":
- topic: (browser)->
- load_form (browser)=>
- for field in ["scary", "notscary"]
- do (field)->
- browser.querySelector("#field-#{field}").addEventListener "click", ->
- browser["#{field}Clicked"] = true
- browser.querySelector("#field-#{field}").addEventListener "change", ->
- browser["#{field}Changed"] = true
- @callback null, browser
-
- "radio button enclosed in label":
- topic: (browser)->
- browser.choose "Scary"
- "should check radio": (browser)->
- assert.ok browser.querySelector("#field-scary").checked
- "should fire click event": (browser)->
- assert.ok browser.scaryClicked
- "should fire change event": (browser)->
- assert.ok browser.scaryChanged
- "with callback":
- Browser.wants "http://localhost:3003/forms/form"
- topic: (browser)->
- browser.choose "Scary", @callback
- "should callback": (_, browser)->
- assert.ok browser.querySelector("#field-scary").checked
-
- "radio button by value":
- Browser.wants "http://localhost:3003/forms/form"
- topic: (browser)->
- browser.choose "no"
- "should check radio": (browser)->
- assert.ok browser.querySelector("#field-notscary").checked
- "should uncheck other radio": (browser)->
- assert.ok !browser.querySelector("#field-scary").checked
-
- "prevent default":
- topic: (browser)->
- radio = browser.$$("#field-prevent-radio")
- values = [radio.checked]
- radio.addEventListener "click", (event)=>
- values.push radio.checked
- event.preventDefault()
- browser.choose radio, =>
- values.push radio.checked
- @callback null, values
- "should turn radio on then off": (values)->
- assert.deepEqual values, [false, true, false]
-
-
-.addBatch
-
- "select option":
- topic: (browser)->
- load_form (browser)=>
- for field in ["looks", "state", "kills"]
- do (field)->
- browser.querySelector("#field-#{field}").addEventListener "change", ->
- browser["#{field}Changed"] = true
- @callback null, browser
-
- "enclosed in label using option label":
- topic: (browser)->
- browser.select "Looks", "Bloody"
- "should set value": (browser)->
- assert.equal browser.querySelector("#field-looks").value, "blood"
- "should select first option": (browser)->
- selected = (!!option.getAttribute("selected") for option in browser.querySelector("#field-looks").options)
- assert.deepEqual selected, [true, false, false]
- "should fire change event": (browser)->
- assert.ok browser.looksChanged
-
- "select name using option value":
- topic: (browser)->
- browser.select "state", "dead"
- "should set value": (browser)->
- assert.equal browser.querySelector("#field-state").value, "dead"
- "should select second option": (browser)->
- selected = (!!option.getAttribute("selected") for option in browser.querySelector("#field-state").options)
- assert.deepEqual selected, [false, true, false]
- "should fire change event": (browser)->
- assert.ok browser.stateChanged
-
- "select option value directly":
- topic: (browser)->
- browser.selectOption browser.querySelector("#option-killed-thousands")
- "should set value": (browser)->
- assert.equal browser.querySelector("#field-kills").value, "Thousands"
- "should select second option": (browser)->
- selected = (!!option.getAttribute("selected") for option in browser.querySelector("#field-kills").options)
- assert.deepEqual selected, [false, false, true]
- "should fire change event": (browser)->
- assert.ok browser.killsChanged
-
- "select callback":
- Browser.wants "http://localhost:3003/forms/form"
- topic: (browser)->
- browser.select "unselected_state", "dead", @callback
- "should callback": (_, browser)->
- assert.equal browser.querySelector("#field-unselected-state").value, "dead"
-
- "select option callback":
- Browser.wants "http://localhost:3003/forms/form"
- topic: (browser)->
- browser.selectOption browser.querySelector("#option-killed-thousands"), @callback
- "should callback": (_, browser)->
- assert.equal browser.querySelector("#field-kills").value, "Thousands"
-
-
-.addBatch
-
- "multiple select option":
- topic: (browser)->
- load_form (browser)=>
- browser.querySelector("#field-hobbies").addEventListener "change", ->
- browser["hobbiesChanged"] = true
- @callback null, browser
-
- "select name using option value":
- topic: (browser)->
- browser.select "#field-hobbies", "Eat Brains"
- browser.select "#field-hobbies", "Sleep"
- "should select first and second options": (browser)->
- selected = (!!option.getAttribute("selected") for option in browser.querySelector("#field-hobbies").options)
- assert.deepEqual selected, [true, false, true]
- "should fire change event": (browser)->
- assert.ok browser.hobbiesChanged
- "should not fire change event if nothing changed": (browser)->
- browser["hobbiesChanged"] = false
- browser.select "#field-hobbies", "Eat Brains"
- assert.ok !browser.hobbiesChanged
-
- "unselect name using option value":
- Browser.wants "http://localhost:3003/forms/form"
- topic: (browser)->
- browser.select "#field-hobbies", "Eat Brains"
- browser.select "#field-hobbies", "Sleep"
- browser.unselect "#field-hobbies", "Sleep"
- "should unselect items": (browser)->
- selected = (!!option.getAttribute("selected") for option in browser.querySelector("#field-hobbies").options)
- assert.deepEqual selected, [true, false, false]
-
- "with callback":
- Browser.wants "http://localhost:3003/forms/form"
- topic: (browser)->
- browser.unselect "#field-hobbies", "Eat Brains"
- browser.unselect "#field-hobbies", "Sleep"
- browser.select "#field-hobbies", "Eat Brains", @callback
- "should unselect callback": (_, browser)->
- selected = (!!option.getAttribute("selected") for option in browser.querySelector("#field-hobbies").options)
- assert.deepEqual selected, [true, false, false]
-
-.addBatch
- "fields not contained in a form":
- topic: ->
- load_form (browser)=>
- @callback null, browser
-
- "should fill text field": (browser) ->
- assert.ok browser.fill "Hunter", "Bruce"
- "should fill textarea": (browser) ->
- assert.ok browser.fill "hunter_hobbies", "Trying to get home"
- "should fill password": (browser) ->
- assert.ok browser.fill "#hunter-password", "klaatubarada"
- "should fill input with invalid type": (browser) ->
- assert.ok browser.fill ":input[name=hunter_invalidtype]", "necktie?"
- "should check checkbox": (browser) ->
- assert.ok browser.check "Chainsaw"
- "should choose radio": (browser) ->
- assert.ok browser.choose "Powerglove"
- "should choose select": (browser) ->
- assert.ok browser.select "Type", "Evil"
-
-.addBatch
-
- "reset form":
- "by calling reset":
- topic: (browser)->
- load_form (browser)=>
- browser.fill("Name", "ArmBiter").fill("likes", "Arm Biting").
- check("You bet").choose("Scary").select("state", "dead")
- browser.querySelector("form").reset()
- @callback null, browser
- "should reset input field to original value": (browser)->
- assert.equal browser.querySelector("#field-name").value, ""
- "should reset textarea to original value": (browser)->
- assert.equal browser.querySelector("#field-likes").value, "Warm brains"
- "should reset checkbox to original value": (browser)->
- assert.ok !browser.querySelector("#field-hungry").value
- "should reset radio to original value": (browser)->
- assert.ok !browser.querySelector("#field-scary").checked
- assert.ok browser.querySelector("#field-notscary").checked
- "should reset select to original option": (browser)->
- assert.equal browser.querySelector("#field-state").value, "alive"
-
- "with event handler":
- topic: (browser)->
- load_form (browser)=>
- browser.querySelector("form :reset").addEventListener "click", (event)=>
- @callback null, event
- browser.querySelector("form :reset").click()
- "should fire click event": (event)->
- assert.equal event.type, "click"
-
- "with preventDefault":
- topic: (browser)->
- load_form (browser)=>
- browser.fill("Name", "ArmBiter")
- browser.querySelector("form :reset").addEventListener "click", (event)->
- event.preventDefault()
- browser.querySelector("form :reset").click()
- @callback null, browser
- "should not reset input field": (browser)->
- assert.equal browser.querySelector("#field-name").value, "ArmBiter"
-
- "by clicking reset input":
- topic: (browser)->
- load_form (browser)=>
- browser.fill("Name", "ArmBiter")
- browser.querySelector("form :reset").click()
- @callback null, browser
- "should reset input field to original value": (browser)->
- assert.equal browser.querySelector("#field-name").value, ""
-
-
-.addBatch
-
- # Submitting form
- "submit form":
- "by calling submit":
- topic: (browser)->
- load_form (browser)=>
- browser.fill("Name", "ArmBiter").fill("likes", "Arm Biting").check("You bet").
- check("Certainly").choose("Scary").select("state", "dead").select("looks", "Choose one").
- select("#field-hobbies", "Eat Brains").select("#field-hobbies", "Sleep").check("Brains?").
- fill('#address1_city', 'Paris').fill('#address1_street', 'CDG').
- fill('#address2_city', 'Mikolaiv').fill('#address2_street', 'PGS')
- browser.querySelector("form").submit()
- browser.wait @callback
-
- "should open new page": (browser)->
- assert.equal browser.location, "http://localhost:3003/forms/submit"
- "should add location to history": (browser)->
- assert.lengthOf browser.window.history, 2
- "should send text input values to server": (browser)->
- assert.equal browser.text("#name"), "ArmBiter"
- "should send textarea values to server": (browser)->
- assert.equal browser.text("#likes"), "Arm Biting"
- "should send radio button to server": (browser)->
- assert.equal browser.text("#scary"), "yes"
- "should send unknown types to server": (browser)->
- assert.equal browser.text("#unknown"), "yes"
- "should send checkbox with default value to server (brains)": (browser)->
- assert.equal browser.text("#brains"), "yes"
- "should send checkbox with default value to server (green)": (browser)->
- assert.equal browser.text("#green"), "Super green!"
- "should send multiple checkbox values to server": (browser)->
- assert.equal browser.text("#hungry"), '["you bet","certainly"]'
- "should send selected option to server": (browser)->
- assert.equal browser.text("#state"), "dead"
- "should send first selected option if none was chosen to server": (browser)->
- assert.equal browser.text("#unselected_state"), "alive"
- assert.equal browser.text("#looks"), ""
- "should send multiple selected options to server": (browser)->
- assert.equal browser.text("#hobbies"), '["Eat Brains","Sleep"]'
- "should send nested attributes in the order they are declared": (browser) ->
- assert.equal browser.text("#addresses"), '["CDG","Paris","PGS","Mikolaiv"]'
-
- "by clicking button":
- topic: (browser)->
- load_form (browser)=>
- browser.fill("Name", "ArmBiter").fill("likes", "Arm Biting").pressButton "Hit Me", @callback
- "should open new page": (browser)->
- assert.equal browser.location, "http://localhost:3003/forms/submit"
- "should add location to history": (browser)->
- assert.lengthOf browser.window.history, 2
- "should send button value to server": (browser)->
- assert.equal browser.text("#clicked"), "hit-me"
- "should send input values to server": (browser)->
- assert.equal browser.text("#name"), "ArmBiter"
- assert.equal browser.text("#likes"), "Arm Biting"
- "should not send other button values to server": (browser)->
- assert.equal browser.text("#image_clicked"), "undefined"
-
- "by clicking image button":
- topic: (browser)->
- load_form (browser)=>
- browser.fill("Name", "ArmBiter").fill("likes", "Arm Biting").pressButton "#image_submit", @callback
- "should open new page": (browser)->
- assert.equal browser.location, "http://localhost:3003/forms/submit"
- "should add location to history": (browser)->
- assert.lengthOf browser.window.history, 2
- "should send image value to server": (browser)->
- assert.equal browser.text("#image_clicked"), "Image Submit"
- "should send input values to server": (browser)->
- assert.equal browser.text("#name"), "ArmBiter"
- assert.equal browser.text("#likes"), "Arm Biting"
- "should not send other button values to server": (browser)->
- assert.equal browser.text("#clicked"), "undefined"
-
- "by clicking input":
- topic: (browser)->
- load_form (browser)=>
- browser.fill("Name", "ArmBiter").fill("likes", "Arm Biting").pressButton "Submit", @callback
- "should open new page": (browser)->
- assert.equal browser.location, "http://localhost:3003/forms/submit"
- "should add location to history": (browser)->
- assert.lengthOf browser.window.history, 2
- "should send submit value to server": (browser)->
- assert.equal browser.text("#clicked"), "Submit"
- "should send input values to server": (browser)->
- assert.equal browser.text("#name"), "ArmBiter"
- assert.equal browser.text("#likes"), "Arm Biting"
-
- "cancel event":
- topic: (browser)->
- brains.get "/forms/cancel", (req, res)->
- res.send """
- <html>
- <head>
- <script src="/jquery.js"></script>
- <script>
- $(function() {
- $("form").submit(function() {
- return false;
- })
- })
- </script>
- </head>
- <body>
- <form action="/forms/submit" method="post">
- <button>Submit</button>
- </form>
- </body>
- </html>
- """
- browser = new Browser
- browser.wants "http://localhost:3003/forms/cancel", =>
- browser.pressButton "Submit", @callback
- "should not change page": (browser)->
- assert.equal browser.location.href, "http://localhost:3003/forms/cancel"
-
-
-.addBatch
-
- # File upload
- "file upload":
- topic: ->
- brains.get "/forms/upload", (req, res)->
- res.send """
- <html>
- <body>
- <form method="post" enctype="multipart/form-data">
- <input name="text" type="file">
- <input name="image" type="file">
- <button>Upload</button>
- </form>
- </body>
- </html>
- """
- brains.post "/forms/upload", (req, res)->
- if req.files
- [text, image] = [req.files.text, req.files.image]
- data = File.readFileSync((text || image).path)
- if image
- digest = Crypto.createHash("md5").update(data).digest("hex")
- res.send """
- <html>
- <head><title>#{(text || image).filename}</title></head>
- <body>#{digest || data}</body>
- </html>
- """
- else
- res.send """
- <html>
- <body>nothing</body>
- </html>
- """
-
- "text":
- Browser.wants "http://localhost:3003/forms/upload"
- topic: (browser)->
- filename = __dirname + "/data/random.txt"
- browser.attach("text", filename).pressButton "Upload", @callback
- "should upload file": (browser)->
- assert.equal browser.text("body").trim(), "Random text"
- "should upload include name": (browser)->
- assert.equal browser.text("title"), "random.txt"
-
- "binary":
- Browser.wants "http://localhost:3003/forms/upload"
- topic: (browser)->
- @filename = __dirname + "/data/zombie.jpg"
- browser.attach("image", @filename).pressButton "Upload", @callback
- "should upload include name": (browser)->
- assert.equal browser.text("title"), "zombie.jpg"
- "should upload file": (browser)->
- digest = Crypto.createHash("md5").update(File.readFileSync(@filename)).digest("hex")
- assert.equal browser.text("body").trim(), digest
-
- "empty":
- Browser.wants "http://localhost:3003/forms/upload"
- topic: (browser)->
- browser.attach "text", ""
- browser.pressButton "Upload", @callback
- "should not upload any file": (browser)->
- assert.equal browser.text("body").trim(), "nothing"
-
- "not set":
- Browser.wants "http://localhost:3003/forms/upload"
- topic: (browser)->
- browser.pressButton "Upload", @callback
- "should not send inputs without names": (browser)->
- assert.equal browser.text("body").trim(), "nothing"
-
-
-.addBatch
-
- "file upload with JS":
- topic: ->
- brains.get "/forms/upload-js", (req, res)->
- res.send """
- <html>
- <head>
- <title>Upload a file</title>
- <script>
- function handleFile() {
- document.title = "Upload done";
- var file = document.getElementById("my_file").files[0];
- document.getElementById("filename").innerHTML = file.name;
- document.getElementById("type").innerHTML = file.type;
- document.getElementById("size").innerHTML = file.size;
- document.getElementById("is_file").innerHTML = (file instanceof File);
- }
- </script>
- </head>
- <body>
- <form>
- <input name="my_file" id="my_file" type="file" onchange="handleFile()">
- </form>
- <div id="filename"></div>
- <div id="type"></div>
- <div id="size"></div>
- <div id="is_file"></div>
- </body>
- </html>
- """
-
- "text":
- Browser.wants "http://localhost:3003/forms/upload-js"
- topic: (browser)->
- filename = "#{__dirname}/data/random.txt"
- browser.attach "my_file", filename, @callback
-
- "should call callback": (browser)->
- assert.equal browser.text("title"), "Upload done"
- "should have filename": (browser)->
- assert.equal browser.text("#filename"), "random.txt"
- "should know file type": (browser)->
- assert.equal browser.text("#type"), "text/plain"
- "should know file size": (browser)->
- assert.equal browser.text("#size"), "12"
- "should be of type File": (browser)->
- assert.equal browser.text("#is_file"), "true"
-
-
-.addBatch
-
- "content length":
- topic: ->
- brains.get "/forms/urlencoded", (req, res)->
- res.send """
- <html>
- <body>
- <form method="post">
- <input name="text" type="text">
- <input type="submit" value="submit">
- </form>
- </body>
- </html>
- """
- brains.post "/forms/urlencoded", (req, res)->
- text = req.body.text
- res.send """
- <html>
- <head><title>bite back</title></head>
- <body>#{text}</body>
- </html>
- """
-
- "post form urlencoded having content":
- Browser.wants "http://localhost:3003/forms/urlencoded"
- topic: (browser)->
- browser.fill("text", "bite").pressButton "submit", @callback
- "should send content-length header": (browser) ->
- assert.include browser.lastRequest.headers, "content-length"
- "should match expected content-length": (browser) ->
- assert.equal browser.lastRequest.headers["content-length"], "text=bite".length
- "should have body with content of input field": (browser) ->
- assert.equal browser.text("body"), "bite"
-
- "post form urlencoded being empty":
- Browser.wants "http://localhost:3003/forms/urlencoded"
- topic: (browser)->
- browser.pressButton "submit", @callback
- "should send content-length header": (browser) ->
- assert.include browser.lastRequest.headers, "content-length"
- "should have size of 0": (browser) ->
- assert.equal browser.lastRequest.headers["content-length"], 0
-
-
-.export(module)
View
41 spec/google_map_spec.coffee
@@ -1,41 +0,0 @@
-{ Vows, assert, brains, Browser } = require("./helpers")
-
-
-Vows.describe("Google map").addBatch
-
- "display":
- topic: ->
- brains.get "/browser/map", (req, res)->
- res.send """
- <html>
- <head>
- <script type="text/javascript" src="//maps.googleapis.com/maps/api/js?v=3&sensor=false&callback=initialize"></script>
- <script type="text/javascript">
- window.initialize = function() {
- window.map = new google.maps.Map(document.getElementById("map"), {
- center: new google.maps.LatLng(-34.397, 150.644),
- zoom: 8,
- mapTypeId: google.maps.MapTypeId.ROADMAP
- });
- }
- </script>
- </head>
- <body>
- <div id="map"></div>
- </body>
- </html>
- """
-
- brains.ready =>
- browser = new Browser
- browser.visit "http://localhost:3003/browser/map", =>
- browser.wait @callback
- "should load map": (browser)->
- assert.ok browser.window.map
- "should set bounds": (browser)->
- bounds = browser.window.map.getBounds()
- assert.ok bounds, "No map bounds yet"
- assert.equal bounds.toString(), "((-34.62332513513795, 150.369341796875), (-34.17006113241608, 150.918658203125))"
-
-
-.export(module)
View
92 spec/helpers.coffee
@@ -1,92 +0,0 @@
-DNS = require("dns")
-Express = require("express")
-File = require("fs")
-Path = require("path")
-Replay = require("replay")
-Browser = require("../lib/zombie.js")
-
-
-# Always run in verbose mode on Travis.
-Browser.debug = true if process.env.TRAVIS
-Browser.silent = !Browser.debug
-
-
-# Redirect all HTTP requests to localhost
-Replay.fixtures = "#{__dirname}/replay"
-Replay.networkAccess = true
-Replay.localhost "host.localhost"
-Replay.ignore "mt0.googleapis.com", "mt1.googleapis.com"
-
-
-# An express server we use to test the browser.
-brains = Express.createServer()
-brains.use Express.bodyParser()
-brains.use Express.cookieParser()
-
-
-brains.get "/", (req, res)->
- res.send "<html><title>Tap, Tap</title></html>"
-
-# Prevent sammy from polluting the output. Comment this if you need its
-# messages for debugging.
-brains.get "/sammy.js", (req, res)->
- File.readFile "#{__dirname}/scripts/sammy.js", (err, data)->
- # unless process.env.DEBUG
- # data = data + ";window.Sammy.log = function() {}"
- res.send data
-
-brains.get "/jquery.js", (req, res)->
- res.redirect "/jquery-1.7.1.js"
-brains.get "/jquery-:version.js", (req, res)->
- version = req.params.version
- File.readFile "#{__dirname}/scripts/jquery-#{version}.js", (err, data)->
- res.send data
-
-
-brains.ready = (callback)->
- if @active
- process.nextTick callback
- else
- @active = true
- brains.listen 3003, callback
- return # nothing
-
-# Creates a new Vows context that will wait for the HTTP server to be ready,
-# then create a new Browser, visit the specified page (url), run all the tests
-# and shutdown the HTTP server.
-#
-# The second argument is the context with all its tests (and subcontexts). The
-# topic passed to all tests is the browser window after loading the document.
-# However, you can (and often need to) supply a ready function that will be
-# called with err and window; the ready function can then call this.callback.
-Browser.wants = (url, context)->
- topic = context.topic
- context.topic = ->
- browser = new Browser
- browser.wants url, {}, (err, rest...)=>
- if topic
- try
- value = topic.apply(this, rest)
- if value
- @callback null, value
- catch err
- @callback err
- else
- throw err if err
- browser.wait @callback
- return # nothing
- return context
-
-Browser.prototype.wants = (url, options, callback)->
- if !callback && typeof options == "function"
- [options, callback] = [null, options]
- brains.ready =>
- @visit url, options, (err, browser)=>
- callback err, browser if callback
- return # nothing
-
-
-exports.assert = require("assert")
-exports.brains = brains
-exports.Vows = require("vows")
-exports.Browser = Browser
View
343 spec/history_spec.coffee
@@ -1,343 +0,0 @@
-{ Vows, assert, brains, Browser } = require("./helpers")
-JSDOM = require("jsdom")
-
-
-brains.get "/history/boo", (req, res)->
- response = if req.query.redirected then "Redirected" else "Eeek!"
- res.send "<html><title>#{response}</title></html>"
-
-brains.get "/history/redirect", (req, res)->
- res.redirect "/history/boo?redirected=true"
-
-brains.get "/history/redirect_back", (req, res)->
- res.redirect req.headers["referer"]
-
-brains.get "/history/referer", (req, res)->
- res.send "<html><title>#{req.headers["referer"]}</title></html>"
-
-file_url = "file://#{__dirname}/data/index.html"
-
-
-Vows.describe("History").addBatch
-
- "URL without path":
- Browser.wants "http://localhost:3003"
- "should resolve URL": (browser)->
- assert.equal browser.location.href, "http://localhost:3003/"
- "should load page": (browser)->
- assert.equal browser.text("title"), "Tap, Tap"
-
- "new window":
- topic: ->
- new Browser().window
- "should start out empty": (window)->
- assert.lengthOf window.history, 0
- "should start out with no location": (window)->
- assert.isUndefined window.location.href
- "go forward":
- topic: (window)->
- window.history.forward()
- window
- "should have no effect": (window)->
- assert.lengthOf window.history, 0
- assert.isUndefined window.location.href
- "go backwards":
- topic: (window)->
- window.history.back()
- window
- "should have no effect": (window)->
- assert.lengthOf window.history, 0
- assert.isUndefined window.location.href
-
- "history":
- "pushState":
- Browser.wants "http://localhost:3003/"
- topic: (browser)->
- browser.history.pushState { is: "start" }, null, "/start"
- browser.history.pushState { is: "end" }, null, "/end"
- @callback null, browser.window
- "should add state to history": (window)->
- assert.lengthOf window.history, 3
- "should change location URL": (window)->
- assert.equal window.location.href, "http://localhost:3003/end"
-
- "go backwards":
- topic: (window)->
- window.document.magic = 123
- window.addEventListener "popstate", (evt)=>
- @callback(null, evt)
- window.history.back()
- return
- "should fire popstate event": (evt)->
- assert.instanceOf evt, JSDOM.dom.level3.events.Event
- "should include state": (evt)->
- assert.equal evt.state.is, "start"
- "should not reload page from same host": (evt)->
- # Get access to the *current* document
- document = evt.target.window.browser.document
- assert.equal document.magic, 123
-
- "go forwards":
- Browser.wants "http://localhost:3003/"
- topic: (browser)->
- browser.history.pushState { is: "start" }, null, "/start"
- browser.history.pushState { is: "end" }, null, "/end"
- browser.back()
- browser.window.addEventListener "popstate", (evt)=>
- @callback(null, evt)
- browser.history.forward()
- return
- "should fire popstate event": (evt)->
- assert.instanceOf evt, JSDOM.dom.level3.events.Event
- "should include state": (evt)->
- assert.equal evt.state.is, "end"
-
- "replaceState":
- Browser.wants "http://localhost:3003/"
- topic: (browser)->
- browser.history.pushState { is: "start" }, null, "/start"
- browser.history.replaceState { is: "end" }, null, "/end"
- @callback null, browser.window
- "should not add state to history": (window)->
- assert.lengthOf window.history, 2
- "should change location URL": (window)->
- assert.equal window.location.href, "http://localhost:3003/end"
-
- "go backwards":
- topic: (window)->
- window.addEventListener "popstate", (evt)=>
- window.popstate = true
- window.history.back()
- @callback null, window
- "should change location URL": (window)->
- assert.equal window.location.href, "http://localhost:3003/"
- "should not fire popstate event": (window)->
- assert.isUndefined window.popstate
-
- "redirect":
- Browser.wants "http://localhost:3003/history/redirect"
- "should redirect to final destination": (browser)->
- assert.equal browser.location, "http://localhost:3003/history/boo?redirected=true"
- "should pass query parameter": (browser)->
- assert.equal browser.text("title"), "Redirected"
- "should not add location in history": (browser)->
- assert.lengthOf browser.history, 1
- "should indicate last request followed a redirect": (browser)->
- assert.ok browser.redirected
-
- "redirect back":
- Browser.wants "http://localhost:3003/history/boo"
- topic: (browser)->
- browser.visit "http://localhost:3003/history/redirect_back"
- browser.window.document.addEventListener "DOMContentLoaded", =>
- @callback null, browser
- return
- "should redirect to the previous path": (browser)->
- assert.equal browser.location.href, "http://localhost:3003/history/boo"
- "should pass query parameter": (browser)->
- assert.match browser.text("title"), /Eeek!/
- "should not add location in history": (browser)->
- assert.lengthOf browser.history, 2
- "should indicate last request followed a redirect": (browser)->
- assert.ok browser.redirected
-
-
- "location":
- "open page":
- Browser.wants "http://localhost:3003/"
- "should add page to history": (browser)->
- assert.lengthOf browser.history, 1
- "should change location URL": (browser)->
- assert.equal browser.location, "http://localhost:3003/"
- "should load document": (browser)->
- assert.match browser.html(), /Tap, Tap/
- "should set window location": (browser)->
- assert.equal browser.window.location.href, "http://localhost:3003/"
- "should set document location": (browser)->
- assert.equal browser.document.location.href, "http://localhost:3003/"
-
- "open from file system":
- Browser.wants `file_url`
- "should add page to history": (browser)->
- assert.lengthOf browser.history, 1
- "should change location URL": (browser)->
- assert.equal browser.location, file_url
- "should load document": (browser)->
- assert.include browser.html("title"), "Insanely fast, headless full-stack testing using Node.js"
- "should set window location": (browser)->
- assert.equal browser.window.location.href, file_url
- "should set document location": (browser)->
- assert.equal browser.document.location.href, file_url
-
- "change pathname":
- Browser.wants "http://localhost:3003/"
- topic: (browser)->
- browser.window.location.pathname = "/history/boo"
- browser.window.document.addEventListener "DOMContentLoaded", =>
- @callback null, browser
- return
- "should add page to history": (browser)->
- assert.lengthOf browser.history, 2
- "should change location URL": (browser)->
- assert.equal browser.location, "http://localhost:3003/history/boo"
- "should load document": (browser)->
- assert.match browser.html(), /Eeek!/
-
- "change relative href":
- Browser.wants "http://localhost:3003/"
- topic: (browser)->
- browser.window.location.href = "/history/boo"
- browser.window.document.addEventListener "DOMContentLoaded", =>
- @callback null, browser
- return
- "should add page to history": (browser)->
- assert.lengthOf browser.history, 2
- "should change location URL": (browser)->
- assert.equal browser.location, "http://localhost:3003/history/boo"
- "should load document": (browser)->
- assert.match browser.html(), /Eeek!/
-
- "change hash":
- Browser.wants "http://localhost:3003/"
- topic: (browser)->
- browser.document.innerHTML = "Wolf"
- browser.window.addEventListener "hashchange", =>
- @callback null, browser
- browser.window.location.hash = "boo"
- return
- "should add page to history": (browser)->
- assert.lengthOf browser.history, 2
- "should change location URL": (browser)->
- assert.equal browser.location, "http://localhost:3003/#boo"
- "should not reload document": (browser)->