Files
zulip/zerver/tests/frontend/casperjs/samples/dynamic.coffee
Tim Abbott e111a2f9a5 [manual] Rename Django app from zephyr to zerver.
This needs to be deployed to both staging and prod at the same
off-peak time (and the schema migration run).

At the time it is deployed, we need to make a few changes directly in
the database:

(1) UPDATE django_content_type set app_label='zerver' where app_label='zephyr';
(2) UPDATE south_migrationhistory set app_name='zerver' where app_name='zephyr';

(imported from commit eb3fd719571740189514ef0b884738cb30df1320)
2013-08-06 07:39:36 -04:00

61 lines
1.4 KiB
CoffeeScript

casper = require("casper").create
verbose: true
# The base links array
links = [
"http://google.com/"
"http://yahoo.com/"
"http://bing.com/"
]
currentLink = 0;
# If we don't set a limit, it could go on forever
upTo = ~~casper.cli.get(0) || 10
###
Get the links, and add them to the links array
(It could be done all in one step, but it is intentionally splitted)
###
addLinks = (link) ->
@then ->
found = @evaluate searchLinks
@echo "#{found.length} links found on #{link}"
links = links.concat found
###
Fetch all <a> elements from the page and return
the ones which contains a href starting with 'http://'
###
searchLinks = ->
filter = Array::filter
map = Array::map
map.call filter.call(document.querySelectorAll("a"), (a) ->
(/^http:\/\/.*/i).test a.getAttribute("href")
), (a) ->
a.getAttribute "href"
# Just opens the page and prints the title
start = (link) ->
@start link, ->
@echo "Page title: #{ @getTitle() }"
# As long as it has a next link, and is under the maximum limit, will keep running
check = ->
if links[currentLink] && currentLink < upTo
@echo "--- Link #{currentLink} ---"
start.call @, links[currentLink]
addLinks.call @, links[currentLink]
currentLink++
@run check
else
@echo "All done."
@exit()
casper.start()
casper.then ->
@echo "Starting"
casper.run check