-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
129 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| require 'guard/guard' | ||
|
|
||
| class ::Guard::PhantomJS < ::Guard::Guard | ||
| def run_all | ||
| run_on_change([]) | ||
| end | ||
|
|
||
| def run_on_change(paths) | ||
| passed = system @options[:runner], *paths | ||
|
|
||
| ::Guard::Notifier.notify \ | ||
| (passed ? 'passed' : 'failed'), | ||
| :title => 'Zepto test results', | ||
| :image => (passed ? :success : :failed) | ||
| end | ||
| end | ||
|
|
||
| guard :phantomjs, :runner => 'script/test' do | ||
| watch(%r{src/(.+)\.js$}) do |m| | ||
| "test/#{m[1]}.html" | ||
| end | ||
| watch(%r{test/(.+)\.html$}) do |m| | ||
| m[0] unless m[1].include? '_functional' | ||
| end | ||
| end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| #!/bin/sh | ||
| if [ -z "$BUNDLE_GEMFILE" ]; then | ||
| export BUNDLE_GEMFILE=shutup | ||
| fi | ||
|
|
||
| exec guard --no-notify "$@" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| #!/bin/sh | ||
| phantomjs test/runner.coffee "$@" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| # Test runner for PhantomJS <phantomjs.org> | ||
| # Usage: | ||
| # $ phantomjs test/runner.coffee [<page1>, <page2>, ...] | ||
| # | ||
| # When no test pages specified, runs all automated tests. | ||
|
|
||
| system = require('system') | ||
| fs = require('fs') | ||
|
|
||
| if system.args.length > 1 | ||
| # list of test pages to run | ||
| suites = system.args.slice(1) | ||
| else | ||
| # by default, run all test/*.html pages | ||
| modules = 'zepto ajax data detect event form fx selector stack'.split /\s+/ | ||
| suites = modules.map (name)-> "test/#{name}.html" | ||
|
|
||
| page = require('webpage').create() | ||
|
|
||
| page.onConsoleMessage = (msg) -> | ||
| console.log msg | ||
|
|
||
| page.onError = (msg, trace) -> | ||
| console.log 'ERROR: ' + msg | ||
|
|
||
| # used for waiting until the tests finish running | ||
| waitFor = (testFn, onReady, timeout=3000) -> | ||
| start = new Date() | ||
| interval = setInterval -> | ||
| if testFn() | ||
| clearInterval interval | ||
| onReady() | ||
| else if new Date() - start > timeout | ||
| console.log "timed out." | ||
| phantom.exit(1) | ||
| , 100 | ||
|
|
||
| loadNextSuite = -> | ||
| if not suites.length | ||
| phantom.exit() | ||
| else | ||
| url = suites.shift() + "?verbosity=WARN" | ||
| # PhantomJS chokes on the query string on relative paths | ||
| url = "file://#{fs.workingDirectory}/#{url}" if not /:\/\//.test url | ||
|
|
||
| page.open url, (status) -> | ||
| if status isnt "success" | ||
| console.log "failed opening #{url}" | ||
| phantom.exit(1) | ||
|
|
||
| waitFor -> | ||
| page.evaluate -> | ||
| # the "#results" element needs to have the "finished" class | ||
| res = document.getElementById 'results' | ||
| /finished/.test res.className if res | ||
| , -> | ||
| passed = page.evaluate -> | ||
| res = document.getElementById 'results' | ||
| paths = location.pathname.split('/') | ||
| # echo test results to the console | ||
| console.log "#{paths[paths.length - 1]} - " + res.textContent | ||
| /passed/.test res.className | ||
|
|
||
| if passed | ||
| loadNextSuite() | ||
| else | ||
| phantom.exit(1) | ||
|
|
||
| loadNextSuite() |