-
Notifications
You must be signed in to change notification settings - Fork 47k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #451 from subtleGradient/subtlegradient/browser-te…
…sting Browser testing.
- Loading branch information
Showing
22 changed files
with
562 additions
and
277 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 |
---|---|---|
|
@@ -22,4 +22,4 @@ docs/js/live_editor.js | |
docs/js/examples | ||
docs/downloads | ||
examples/shared/*.js | ||
|
||
test/the-files-to-test.generated.js |
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 was deleted.
Oops, something went wrong.
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,47 @@ | ||
var pxlgif = Buffer('R0lGODlhAQABAIAAAP///wAAACH5BAAAAAAALAAAAAABAAEAAAICRAEAOw==', 'base64'); | ||
|
||
module.exports = function(grunt){ | ||
|
||
function printMiddleware(req, res, next) { | ||
if (req._parsedUrl.pathname != '/print') return next(); | ||
if (req.query.message.indexOf('ok') === 0){ | ||
grunt.log.ok(req.query.message); | ||
} else if (req.query.message.indexOf('not ok') === 0){ | ||
grunt.log.error(req.query.message); | ||
} else { | ||
grunt[req.query.type || 'log'].writeln('[%s][%s]', req.headers['user-agent'], Date.now(), req.query.message); | ||
} | ||
res.end(pxlgif); | ||
} | ||
function testResultLoggerMiddleware(req, res, next) { | ||
if (!(req.body && req.body.data)) return next(); | ||
grunt.log.writeln('[%s][%s]', req.headers['user-agent'], Date.now(), req.body.data); | ||
res.end('Got it, thanks!'); | ||
} | ||
|
||
return { | ||
server: { | ||
options: { | ||
base: '.', | ||
hostname: '*', | ||
port: 9999, | ||
middleware: function(connect, options) { | ||
connect.logger.token('user-agent', function(req, res){ return req.headers['user-agent']; }); | ||
connect.logger.token('timestamp', function(req, res){ return Date.now(); }); | ||
|
||
return [ | ||
connect.query(), | ||
printMiddleware, | ||
|
||
connect.logger({format:'[:user-agent][:timestamp] :method :url', stream:grunt.verbose}), | ||
connect.bodyParser(), | ||
testResultLoggerMiddleware, | ||
|
||
connect.static(options.base), | ||
connect.directory(options.base) | ||
]; | ||
}, | ||
} | ||
} | ||
} | ||
} |
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,18 @@ | ||
var grunt = require('grunt'); | ||
|
||
|
||
exports.local = { | ||
webdriver: { | ||
remote: { protocol: 'http:', hostname: '127.0.0.1', port: 9515, path: '/' } | ||
}, | ||
url: "http://127.0.0.1:9999/test/index.html", | ||
onComplete: function(report){ | ||
var browser = this; | ||
if (!report.passed){ | ||
grunt.fatal("tests failed"); | ||
} | ||
}, | ||
onError: function(error){ | ||
grunt.fatal(error); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
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,44 @@ | ||
var grunt = require("grunt"); | ||
var wd = require('wd'); | ||
|
||
module.exports = function(){ | ||
var config = this.data; | ||
var taskSucceeded = this.async(); | ||
grunt.verbose.write('webdriver remote', JSON.stringify(config.webdriver.remote)); | ||
var browser = wd.promiseChainRemote(config.webdriver.remote); | ||
|
||
browser.on('status', function(info) { | ||
grunt.verbose.writeln(info); | ||
}); | ||
|
||
browser.on('command', function(meth, path, data) { | ||
grunt.verbose.writeln(' > ' + meth, path, data || ''); | ||
}); | ||
|
||
browser | ||
.init(config.browser || {}) | ||
.get(config.url) | ||
.then(function(){return browser;}) | ||
.then(getJSReport) | ||
.then(config.onComplete && config.onComplete.bind(browser), config.onError && config.onError.bind(browser)) | ||
.fail(grunt.verbose.writeln.bind(grunt.verbose)) | ||
.fin(function(){ | ||
if (grunt.option('webdriver-keep-open')) return; | ||
grunt.verbose.writeln('Closing the browser window. To keep it open, pass the --webdriver-keep-open flag to grunt.'); | ||
return browser.quit(); | ||
}) | ||
.done( | ||
taskSucceeded.bind(null,true), | ||
taskSucceeded.bind(null,false) | ||
) | ||
; | ||
} | ||
|
||
function getJSReport(browser){ | ||
return browser | ||
.waitForCondition("typeof window.jasmine != 'undefined'", 500) | ||
.waitForCondition("typeof window.jasmine.getJSReport != 'undefined'", 10e3) | ||
.waitForCondition("window.testImageURL.running <= 0", 5e3) | ||
.eval("jasmine.getJSReport()") | ||
; | ||
} |
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,37 @@ | ||
var grunt = require('grunt'); | ||
|
||
module.exports = function(){ | ||
var onReadyCallback = this.async(); | ||
|
||
var phantomjs = require("phantomjs").path; | ||
var child_process = require('child_process'); | ||
var config = this.data || {}; | ||
|
||
var args = ["--webdriver=" + (config.port || 9515)]; | ||
grunt.verbose.writeln('phantomjs START path:%s args:%s', phantomjs, args); | ||
|
||
var child = child_process.spawn(phantomjs, args); | ||
process.on('exit', function() { | ||
child.kill(); | ||
}); | ||
|
||
child.on('error', function(error) { | ||
grunt.verbose.writeln('phantomjs ERROR'); | ||
grunt.fatal(error); | ||
}); | ||
child.on('exit', function(code) { | ||
grunt.verbose.writeln('phantomjs END'); | ||
if (code) grunt.fatal('phantomjs FAIL'); | ||
}); | ||
|
||
function verboseWrite(chunk) { | ||
if (onReadyCallback && chunk.toString().indexOf('running on port') != -1) { | ||
grunt.verbose.writeln('phantomjs STARTED'); | ||
onReadyCallback(); | ||
onReadyCallback = null; | ||
} | ||
grunt.verbose.write(chunk); | ||
} | ||
child.stdout.on('data', verboseWrite); | ||
child.stderr.on('data', verboseWrite); | ||
} |
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
Oops, something went wrong.