Skip to content
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

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
001bda2
Generate the browser test list at built time
subtleGradient Oct 28, 2013
c4ba8f8
Browser test runner
subtleGradient Oct 28, 2013
8205c68
serve worker.js from its actual relative path
subtleGradient Oct 28, 2013
b867aa0
Format test results as TAP
subtleGradient Oct 28, 2013
ecd847c
enable testling-ci browser testing
subtleGradient Oct 28, 2013
5640d64
skip Worker test unless the browser supports them
subtleGradient Oct 28, 2013
1393e55
include the built files for testling
subtleGradient Oct 28, 2013
24ec78f
Testing-ci can't handle spaces in filenames?
subtleGradient Oct 29, 2013
a447f53
Make it easier to repro tests in the wild
subtleGradient Oct 29, 2013
46c0aee
Fixed paths for phantomjs
subtleGradient Oct 29, 2013
fc57283
Absolute urls for less flakiness
subtleGradient Oct 29, 2013
3df6942
SauceLabs Browser testing via Travis
subtleGradient Oct 29, 2013
6a7a15c
disable testling
subtleGradient Oct 29, 2013
b111521
Correct SauceLabs tokens
subtleGradient Oct 29, 2013
284d8d6
Upgrade to the latest version of jasmine
subtleGradient Oct 31, 2013
465b8dc
test server middleware for receiving test results
subtleGradient Oct 31, 2013
694cd6e
test runner requires es5-shim
subtleGradient Oct 31, 2013
c472794
Simple test result logger
subtleGradient Oct 31, 2013
f65f7b3
IE8 support in jasmine-support
subtleGradient Oct 31, 2013
d64f34b
inserted iframes can be targeted after a delay
subtleGradient Oct 31, 2013
46e86df
move html reporter and its requirements
subtleGradient Oct 31, 2013
7bbf6cb
browser support for jasmine-support
subtleGradient Oct 31, 2013
2cd6639
don't double-log test results
subtleGradient Oct 31, 2013
93c0a46
upgraded sauce harness
subtleGradient Oct 31, 2013
e086cbb
separate grunt task for saucelabs browser testing
subtleGradient Oct 31, 2013
0f274e5
new webdriver-jasmine task and config
subtleGradient Oct 31, 2013
db299ed
remove sauce labs stuff for now
subtleGradient Oct 31, 2013
772af52
safer bind
subtleGradient Oct 31, 2013
b725097
log using grunt
subtleGradient Oct 31, 2013
2b273d8
remove saucelabs for now
subtleGradient Oct 31, 2013
2d979a9
cleanup
subtleGradient Nov 6, 2013
71772e7
grunt task launch phantomjs as a webdriver server
subtleGradient Nov 6, 2013
c780985
wait for all results to finish sending
subtleGradient Nov 6, 2013
1368b29
cleanup webdriver jasmine task
subtleGradient Nov 6, 2013
159d64d
cleanup
subtleGradient Nov 6, 2013
dfb4dde
keep track of incomplete
subtleGradient Nov 6, 2013
3e2d3e4
add logging to webdriver config
subtleGradient Nov 6, 2013
be7ee1e
start a local webdriver server before using it
subtleGradient Nov 6, 2013
f4d487f
removed compiled build files
subtleGradient Nov 6, 2013
2d6a839
Not necessary anymore
subtleGradient Nov 6, 2013
b922d8d
move browser test libs to lib folder
subtleGradient Nov 6, 2013
c9401be
replace phantom-harness runner with webdriver
subtleGradient Nov 6, 2013
19a5505
making phantomjs version less specific
subtleGradient Nov 6, 2013
0a120bb
cleanup loadNpmTasks
subtleGradient Nov 6, 2013
5fa7075
ignore generated file
subtleGradient Nov 6, 2013
f289e98
rename sauce-harness to index
subtleGradient Nov 6, 2013
241d57a
allow directory browsing
subtleGradient Nov 7, 2013
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ docs/js/live_editor.js
docs/js/examples
docs/downloads
examples/shared/*.js

test/the-files-to-test.generated.js
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,5 @@ env:
- secure: qPvsJ46XzGrdIuPA70b55xQNGF8jcK7N1LN5CCQYYocXLa+fBrl+fTE77QvehOPhqwJXcj6kOxI+sY0KrVwV7gmq2XY2HZGWUSCxTN0SZlNIzqPA80Y7G/yOjA4PUt8LKgP+8tptyhTAY56qf+hgW8BoLiKOdztYF2p+3zXOLuA=
# SECRET_TOKEN
- secure: dkpPW+VnoqC/okhRdV90m36NcyBFhcwEKL3bNFExAwi0dXnFao8RoFlvnwiPlA23h2faROkMIetXlti6Aju08BgUFV+f9aL6vLyU7gUent4Nd3413zf2fwDtXIWIETg6uLnOpSykGKgCAT/hY3Q2oPLqOoY0OxfgnbqwxkxljrE=
- secure: eHMg4yQWJ+5zFxNcjVwpdpcbZCQMaSByqJy0wwQ2XOOMItdCvSfO/fa+mYoVND/9Orsi5kvXC9tx4sYHyth5hLrvO+bghYjiayrbxYYrxso6G/aU8Pttc7s/qk3I4zadLlua1kGy2TauByxS6nt9nUDe0FDaJKA9k1QXVlpq5Ac=
- secure: v65jUPPNBvJg1xhj4cY7wMKinCESUseHsW1d2gp68SluFHHyjWZOvXYXZdABqB/1uNmQxjbUkwkdSNAOn5k7ppjRcRnlAH2uu1xDqXrGp6cW4MfNPchrAe+FcUMtse/3THGJj8SZ9IQWIl+BHv4XASQ7FwqCR8cwlOfhsqdfch8=
29 changes: 19 additions & 10 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ var exec = require('child_process').exec;
var jsxTask = require('./grunt/tasks/jsx');
var browserifyTask = require('./grunt/tasks/browserify');
var populistTask = require('./grunt/tasks/populist');
var phantomTask = require('./grunt/tasks/phantom');
var webdriverPhantomJSTask = require('./grunt/tasks/webdriver-phantomjs');
var webdriverJasmineTasks = require('./grunt/tasks/webdriver-jasmine');
var npmTask = require('./grunt/tasks/npm');
var releaseTasks = require('./grunt/tasks/release');

Expand All @@ -16,7 +17,8 @@ module.exports = function(grunt) {
jsx: require('./grunt/config/jsx/jsx'),
browserify: require('./grunt/config/browserify'),
populist: require('./grunt/config/populist'),
phantom: require('./grunt/config/phantom'),
connect: require('./grunt/config/server')(grunt),
"webdriver-jasmine": require('./grunt/config/webdriver-jasmine.js'),
npm: require('./grunt/config/npm'),
clean: ['./build', './*.gem', './docs/_site', './examples/shared/*.js'],
jshint: require('./grunt/config/jshint'),
Expand All @@ -25,11 +27,12 @@ module.exports = function(grunt) {

grunt.config.set('compress', require('./grunt/config/compress'));

grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-contrib-copy');
grunt.loadNpmTasks('grunt-contrib-clean');
grunt.loadNpmTasks('grunt-compare-size');
grunt.loadNpmTasks('grunt-contrib-compress');
Object.keys(grunt.file.readJSON('package.json').devDependencies)
.filter(function(npmTaskName){ return npmTaskName.indexOf('grunt-') === 0;})
.forEach(function(npmTaskName){
grunt.loadNpmTasks(npmTaskName);
})
;

// Alias 'jshint' to 'lint' to better match the workflow we know
grunt.registerTask('lint', ['jshint']);
Expand All @@ -42,7 +45,7 @@ module.exports = function(grunt) {

grunt.registerMultiTask('populist', populistTask);

grunt.registerMultiTask('phantom', phantomTask);
grunt.registerMultiTask('webdriver-jasmine', webdriverJasmineTasks);

grunt.registerMultiTask('npm', npmTask);

Expand Down Expand Up @@ -70,11 +73,17 @@ module.exports = function(grunt) {
'jsx:jasmine',
Copy link
Contributor

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.

'jsx:test',
'version-check',
'populist:jasmine',
'populist:test'
]);

grunt.registerTask('test', ['build:test', 'build:basic', 'phantom:run']);
grunt.registerTask('webdriver-phantomjs', webdriverPhantomJSTask);

grunt.registerTask('test:webdriver:phantomjs', [
'connect',
'webdriver-phantomjs',
'webdriver-jasmine:local'
]);
grunt.registerTask('test', ['build:test', 'build:basic', 'test:webdriver:phantomjs']);
grunt.registerTask('npm:test', ['build', 'npm:pack']);

// Optimized build task that does all of our builds. The subtasks will be run
Expand Down
11 changes: 0 additions & 11 deletions grunt/config/phantom.js

This file was deleted.

47 changes: 47 additions & 0 deletions grunt/config/server.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
var pxlgif = Buffer('R0lGODlhAQABAIAAAP///wAAACH5BAAAAAAALAAAAAABAAEAAAICRAEAOw==', 'base64');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment this? Looks interesting!

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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)
];
},
}
}
}
}
18 changes: 18 additions & 0 deletions grunt/config/webdriver-jasmine.js
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);
}
}
68 changes: 0 additions & 68 deletions grunt/tasks/phantom.js

This file was deleted.

13 changes: 12 additions & 1 deletion grunt/tasks/populist.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
'use strict';

var grunt = require('grunt');
var fs = require('fs')

module.exports = function() {
var config = this.data;
var done = this.async();

var theFilesToTestScript = fs.createWriteStream(__dirname + '/../../test/the-files-to-test.generated.js');
theFilesToTestScript.write('// Generated by ');
theFilesToTestScript.write(JSON.stringify(__filename.split(/(?=grunt)/)[1]));
theFilesToTestScript.write(' at ');
theFilesToTestScript.write(JSON.stringify(new Date()));
theFilesToTestScript.write('\n\n');

// create the bundle we'll work with
var args = config.args;

Expand All @@ -15,14 +23,17 @@ module.exports = function() {
nonull: true, // Keep IDs that don't expand to anything.
cwd: config.rootDirectory
}, requires).forEach(function(name) {
args.push(name.replace(/\.js$/i, ""));
name = name.replace(/\.js$/i, "");
args.push(name);
theFilesToTestScript.write('harness.enableTest(' + JSON.stringify(name) + ');\n');
});

require("populist").buildP({
rootDirectory: config.rootDirectory,
args: args
}).then(function(output) {
grunt.file.write(config.outfile, output);
theFilesToTestScript.end();
done();
});
};
44 changes: 44 additions & 0 deletions grunt/tasks/webdriver-jasmine.js
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()")
;
}
37 changes: 37 additions & 0 deletions grunt/tasks/webdriver-phantomjs.js
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);
}
8 changes: 6 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,19 @@
"grunt-contrib-copy": "~0.4.1",
"grunt-contrib-jshint": "~0.6.0",
"optimist": "~0.6.0",
"phantomjs": "~1.9.1-4",
"phantomjs": "~1.9",
"recast": "~0.4.16",
"semver": "~2.1.0",
"uglify-js": "~2.4.0",
"grunt-contrib-clean": "~0.5.0",
"grunt-compare-size": "~0.4.0",
"gzip-js": "~0.3.2",
"tmp": "~0.0.18",
"grunt-contrib-compress": "~0.5.1"
"grunt-contrib-compress": "~0.5.1",
"jasmine-tapreporter": "~0.2.2",
"grunt-contrib-connect": "~0.5.0",
"es5-shim": "~2.1.0",
"wd": "~0.2.2"
},
"engines": {
"node": ">=0.10.0"
Expand Down
4 changes: 2 additions & 2 deletions src/environment/__tests__/ReactWebWorker-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this ; needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You must never begin a line with ( or [. It's the law.

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));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cc @spicyj who last worked with ReactWebWorker-test: thoughts?

Copy link
Collaborator

Choose a reason for hiding this comment

The 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') {
Expand Down
2 changes: 1 addition & 1 deletion src/test/worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ var global = {};
importScripts("phantomjs-shims.js");

try {
importScripts("react.js");
importScripts("../../build/react.js");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this requires us to run grunt build before grunt test, so that build/react.js will be built. Wondering if we should make grunt test depend on grunt build.

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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',
Expand Down
Loading