forked from josephg/ShareJS
-
Notifications
You must be signed in to change notification settings - Fork 0
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
Thomas Scholtes
committed
Oct 11, 2013
1 parent
6b3daa1
commit 950e122
Showing
6 changed files
with
86 additions
and
14 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
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,45 @@ | ||
path = require('path') | ||
|
||
module.exports = (grunt)-> | ||
|
||
grunt.registerTask 'test:phantom', 'Run browser tests in phantom', -> | ||
|
||
done = this.async() | ||
|
||
phantomProxy = require('phantom-proxy') | ||
url = 'http://127.0.0.1:3000' | ||
phantomProxy.create (proxy)-> | ||
|
||
fail = (msg)-> | ||
proxy.end -> | ||
grunt.fail.fatal(msg) | ||
done() | ||
|
||
page = proxy.page | ||
page.open url, (status)-> | ||
if status != true | ||
fail "Could not connect to #{url}\nStart test server with `grunt test:server`" | ||
|
||
page.on 'error', (error, trace)-> | ||
if trace && trace.length | ||
grunt.log.error(error.red + ' at ') | ||
trace.forEach (line)-> | ||
file = line.file.replace(/^file:/,'') | ||
message = grunt.util._('%s:%d %s') | ||
.sprintf(path.relative('.',file), line.line, line.function) | ||
grunt.log.error(message.red) | ||
else | ||
grunt.log.error(error.red) | ||
fail('Errors on site') | ||
|
||
page.on 'callback', (args)-> | ||
page.emit(args...) | ||
|
||
page.on 'console', console.log.bind(console.log) | ||
page.on 'write', process.stdout.write.bind(process.stdout) | ||
page.on 'finished', (failures)-> | ||
if failures > 0 | ||
fail("#{failures} test(s) failed") | ||
else | ||
proxy.end(done) | ||
|
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 |
---|---|---|
@@ -1,2 +1,7 @@ | ||
require './connection.coffee' | ||
require './doc.coffee' | ||
mocha.setup('bdd') | ||
phantom = require '../helpers/phantom' | ||
require './connection' | ||
require './doc' | ||
|
||
mocha.run().on 'end', -> | ||
phantom('finished', this.failures) |
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 |
---|---|---|
@@ -1,19 +1,13 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<title>ShareJS Client Tests</title> | ||
|
||
<script src="/mocha.js"></script> | ||
<script> | ||
mocha.setup('bdd') | ||
</script> | ||
<script src="/tests.js"></script> | ||
<link rel="stylesheet" href="/mocha.css"> | ||
|
||
</head> | ||
|
||
<body> | ||
<div id="mocha"></div> | ||
<script> | ||
mocha.run() | ||
</script> | ||
<script src="/mocha.js"></script> | ||
<script src="/tests.js"></script> | ||
</body> | ||
</html> |
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 @@ | ||
# Communicate with phantom if available | ||
if window && window.callPhantom | ||
|
||
Function.prototype.bind = (object)-> | ||
=> this.apply(object, arguments) | ||
|
||
|
||
phantom = (type, args...)-> | ||
if args.length > 0 | ||
window.callPhantom [type].concat(args) | ||
else | ||
(args...)-> window.callPhantom [type].concat(args) | ||
|
||
console.log = phantom('console') | ||
console.error = phantom('console') | ||
Mocha.process.stdout.write = phantom('write') | ||
|
||
mocha.reporter('spec') | ||
|
||
module.exports = phantom | ||
module.exports.available = true | ||
|
||
else | ||
module.exports = -> | ||
module.exports.available = false |