-
Notifications
You must be signed in to change notification settings - Fork 46.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Browser testing #451
Browser testing #451
Changes from all commits
001bda2
c4ba8f8
8205c68
b867aa0
ecd847c
5640d64
1393e55
24ec78f
a447f53
46c0aee
fc57283
3df6942
6a7a15c
b111521
284d8d6
465b8dc
694cd6e
c472794
f65f7b3
d64f34b
46e86df
7bbf6cb
2cd6639
93c0a46
e086cbb
0f274e5
db299ed
772af52
b725097
2b273d8
2d979a9
71772e7
c780985
1368b29
159d64d
dfb4dde
3e2d3e4
be7ee1e
f4d487f
2d6a839
b922d8d
c9401be
19a5505
0a120bb
5fa7075
f289e98
241d57a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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 was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
var pxlgif = Buffer('R0lGODlhAQABAIAAAP///wAAACH5BAAAAAAALAAAAAABAAEAAAICRAEAOw==', 'base64'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Comment this? Looks interesting! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a 1pxl gif. Instead of loading it from the filesystem I just embedded it. |
||
|
||
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) | ||
]; | ||
}, | ||
} | ||
} | ||
} | ||
} |
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.
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()") | ||
; | ||
} |
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); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,11 +22,11 @@ | |
"use strict"; | ||
|
||
describe('ReactWebWorker', function() { | ||
it('can run React in a web worker', function() { | ||
;(typeof Worker == 'undefined' ? xit : it)('can run React in a web worker', function() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You must never begin a line with |
||
var done = false; | ||
var error; | ||
|
||
var worker = new Worker('/worker.js'); | ||
var worker = new Worker(window.ReactWebWorker_URL || '/src/test/worker.js?_=' + Date.now().toString(36)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. cc @spicyj who last worked with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No strong feelings, I was expecting someone to want to change the generic path earlier than now. Can we not just use a relative path here though? I think I'm actually just missing context on the purpose of this PR. |
||
worker.addEventListener('message', function(e) { | ||
var data = JSON.parse(e.data); | ||
if (data.type == 'error') { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ var global = {}; | |
importScripts("phantomjs-shims.js"); | ||
|
||
try { | ||
importScripts("react.js"); | ||
importScripts("../../build/react.js"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this requires us to run There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, I'm not 100% sure about this change. I did it so that I could get the tests running in a browser normally without having to rely on the phantomjs web server contortions. |
||
} catch (e) { | ||
postMessage(JSON.stringify({ | ||
type: 'error', | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove related bits from
grunt/config/populist.js
.