mirror of
https://github.com/facebook/react.git
synced 2026-11-18 20:15:56 +00:00
commit
2a3f43184a
51 files changed
+829
-643
No files matched your search
@@ -7,3 +7,4 @@ src/vendor_deprecated
|
||||
src/**/__tests__/**
|
||||
# This should be enabled but that folder has too much in it that doesn't belong
|
||||
src/test
|
||||
test/the-files-to-test.generated.js
|
||||
@@ -10,6 +10,8 @@ globals:
|
||||
|
||||
rules:
|
||||
# ERRORS
|
||||
space-before-blocks: 2
|
||||
indent: [2, 2, indentSwitchCase: true]
|
||||
brace-style: 2
|
||||
space-after-keywords: 2
|
||||
strict: 2
|
||||
@@ -25,8 +27,6 @@ rules:
|
||||
consistent-return: 2
|
||||
no-unused-vars: [2, args: none]
|
||||
quotes: [2, 'single']
|
||||
space-before-blocks: 2
|
||||
indent: [2, 2, indentSwitchCase: true]
|
||||
|
||||
# WARNINGS
|
||||
# This is the only one that's hard to track since we don't lint just changes.
|
||||
@@ -1,18 +0,0 @@
|
||||
{
|
||||
"node": true,
|
||||
|
||||
"boss": true,
|
||||
"curly": true,
|
||||
"devel": true,
|
||||
"eqnull": true,
|
||||
"expr": true,
|
||||
"funcscope": true,
|
||||
"globalstrict": true,
|
||||
"loopfunc": true,
|
||||
"newcap": false,
|
||||
"noempty": true,
|
||||
"nonstandard": true,
|
||||
"sub": true,
|
||||
"undef": true,
|
||||
"unused": "vars"
|
||||
}
|
||||
+58
-35
@@ -12,6 +12,7 @@ var npmReactTasks = require('./grunt/tasks/npm-react');
|
||||
var npmReactToolsTasks = require('./grunt/tasks/npm-react-tools');
|
||||
var versionCheckTask = require('./grunt/tasks/version-check');
|
||||
var gemReactSourceTasks = require('./grunt/tasks/gem-react-source');
|
||||
var eslintTask = require('./grunt/tasks/eslint');
|
||||
|
||||
module.exports = function(grunt) {
|
||||
|
||||
@@ -22,45 +23,43 @@ module.exports = function(grunt) {
|
||||
browserify: require('./grunt/config/browserify'),
|
||||
populist: require('./grunt/config/populist')(grunt),
|
||||
connect: require('./grunt/config/server')(grunt),
|
||||
"webdriver-jasmine": require('./grunt/config/webdriver-jasmine'),
|
||||
"webdriver-perf": require('./grunt/config/webdriver-perf'),
|
||||
'webdriver-jasmine': require('./grunt/config/webdriver-jasmine'),
|
||||
'webdriver-perf': require('./grunt/config/webdriver-perf'),
|
||||
npm: require('./grunt/config/npm'),
|
||||
clean: ['./build', './*.gem', './docs/_site', './examples/shared/*.js', '.module-cache'],
|
||||
clean: [
|
||||
'./build',
|
||||
'./*.gem',
|
||||
'./docs/_site',
|
||||
'./examples/shared/*.js',
|
||||
'.module-cache'
|
||||
],
|
||||
jshint: require('./grunt/config/jshint'),
|
||||
/*eslint-disable camelcase */
|
||||
compare_size: require('./grunt/config/compare_size')
|
||||
/*eslint-enable camelcase */
|
||||
});
|
||||
|
||||
grunt.config.set('compress', require('./grunt/config/compress'));
|
||||
|
||||
Object.keys(grunt.file.readJSON('package.json').devDependencies)
|
||||
.filter(function(npmTaskName) { return npmTaskName.indexOf('grunt-') === 0; })
|
||||
.filter(function(npmTaskName) { return npmTaskName != 'grunt-cli'; })
|
||||
.forEach(function(npmTaskName) { grunt.loadNpmTasks(npmTaskName); });
|
||||
|
||||
// Super simplified eslint task that we can use to replace linting. This just
|
||||
// shells out to eslint.
|
||||
grunt.registerTask('eslint', function() {
|
||||
var done = this.async();
|
||||
grunt.util.spawn({
|
||||
cmd: 'node_modules/.bin/eslint',
|
||||
args: ['src']
|
||||
}, function(err, result, code) {
|
||||
if (code === 0) {
|
||||
grunt.log.ok('Lint passed (but may contain warnings)');
|
||||
} else {
|
||||
grunt.log.error('Lint failed');
|
||||
}
|
||||
if (result.stdout.length) {
|
||||
grunt.log.writeln(result.stdout);
|
||||
}
|
||||
|
||||
done(code === 0);
|
||||
.filter(function(npmTaskName) {
|
||||
return npmTaskName.indexOf('grunt-') === 0;
|
||||
})
|
||||
.filter(function(npmTaskName) {
|
||||
return npmTaskName !== 'grunt-cli';
|
||||
})
|
||||
.forEach(function(npmTaskName) {
|
||||
grunt.loadNpmTasks(npmTaskName);
|
||||
});
|
||||
});
|
||||
|
||||
grunt.registerTask('eslint', eslintTask);
|
||||
|
||||
grunt.registerTask('lint', ['eslint']);
|
||||
|
||||
grunt.registerTask('download-previous-version', require('./grunt/tasks/download-previous-version.js'));
|
||||
grunt.registerTask(
|
||||
'download-previous-version',
|
||||
require('./grunt/tasks/download-previous-version.js')
|
||||
);
|
||||
|
||||
grunt.registerTask('delete-build-modules', function() {
|
||||
if (grunt.file.exists('build/modules')) {
|
||||
@@ -93,11 +92,28 @@ module.exports = function(grunt) {
|
||||
|
||||
grunt.registerTask('version-check', versionCheckTask);
|
||||
|
||||
grunt.registerTask('build:basic', ['jsx:normal', 'version-check', 'browserify:basic']);
|
||||
grunt.registerTask('build:addons', ['jsx:normal', 'browserify:addons']);
|
||||
grunt.registerTask('build:transformer', ['jsx:normal', 'browserify:transformer']);
|
||||
grunt.registerTask('build:min', ['jsx:normal', 'version-check', 'browserify:min']);
|
||||
grunt.registerTask('build:addons-min', ['jsx:normal', 'browserify:addonsMin']);
|
||||
grunt.registerTask('build:basic', [
|
||||
'jsx:normal',
|
||||
'version-check',
|
||||
'browserify:basic'
|
||||
]);
|
||||
grunt.registerTask('build:addons', [
|
||||
'jsx:normal',
|
||||
'browserify:addons'
|
||||
]);
|
||||
grunt.registerTask('build:transformer', [
|
||||
'jsx:normal',
|
||||
'browserify:transformer'
|
||||
]);
|
||||
grunt.registerTask('build:min', [
|
||||
'jsx:normal',
|
||||
'version-check',
|
||||
'browserify:min'
|
||||
]);
|
||||
grunt.registerTask('build:addons-min', [
|
||||
'jsx:normal',
|
||||
'browserify:addonsMin'
|
||||
]);
|
||||
grunt.registerTask('build:withCodeCoverageLogging', [
|
||||
'jsx:normal',
|
||||
'version-check',
|
||||
@@ -117,8 +133,15 @@ module.exports = function(grunt) {
|
||||
'version-check',
|
||||
'populist:test'
|
||||
]);
|
||||
grunt.registerTask('build:npm-react', ['version-check', 'jsx:normal', 'npm-react:release']);
|
||||
grunt.registerTask('build:gem-react-source', ['build', 'gem-react-source:release']);
|
||||
grunt.registerTask('build:npm-react', [
|
||||
'version-check',
|
||||
'jsx:normal',
|
||||
'npm-react:release'
|
||||
]);
|
||||
grunt.registerTask('build:gem-react-source', [
|
||||
'build',
|
||||
'gem-react-source:release'
|
||||
]);
|
||||
|
||||
grunt.registerTask('webdriver-phantomjs', webdriverPhantomJSTask);
|
||||
|
||||
@@ -161,7 +184,7 @@ module.exports = function(grunt) {
|
||||
'webdriver-perf:saucelabs_firefox',
|
||||
'webdriver-perf:saucelabs_chrome',
|
||||
'webdriver-perf:saucelabs_ie11',
|
||||
'webdriver-perf:saucelabs_ie8',
|
||||
'webdriver-perf:saucelabs_ie8'
|
||||
]);
|
||||
|
||||
grunt.registerTask('test:webdriver:saucelabs', [
|
||||
|
||||
@@ -86,7 +86,7 @@ grunt test
|
||||
grunt test --debug
|
||||
# For speed, you can use fasttest and add --filter to only run one test
|
||||
grunt fasttest --filter=ReactIdentity
|
||||
# Lint the code with JSHint
|
||||
# Lint the code with ESLint
|
||||
grunt lint
|
||||
# Wipe out build directory
|
||||
grunt clean
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
/* jshint multistr:true */
|
||||
/* jshint -W040 */
|
||||
/*eslint-disable no-multi-str */
|
||||
|
||||
'use strict';
|
||||
|
||||
|
||||
@@ -12,6 +12,6 @@ module.exports = {
|
||||
return gzip.zip(contents, {}).length;
|
||||
}
|
||||
},
|
||||
cache: ".grunt/sizecache.json"
|
||||
cache: '.grunt/sizecache.json'
|
||||
}
|
||||
};
|
||||
@@ -1,5 +1,5 @@
|
||||
'use strict';
|
||||
|
||||
/*eslint-disable camelcase*/
|
||||
module.exports = {
|
||||
|
||||
react_docs: {
|
||||
|
||||
+11
-11
@@ -4,15 +4,15 @@ var grunt = require('grunt');
|
||||
var _ = require('lodash');
|
||||
|
||||
var rootIDs = [
|
||||
"React",
|
||||
"ReactWithAddons"
|
||||
'React',
|
||||
'ReactWithAddons'
|
||||
];
|
||||
|
||||
// TODO: stop packaging these libraries
|
||||
rootIDs = rootIDs.concat([
|
||||
"merge",
|
||||
"mergeInto",
|
||||
"copyProperties"
|
||||
'merge',
|
||||
'mergeInto',
|
||||
'copyProperties'
|
||||
]);
|
||||
|
||||
var normal = {
|
||||
@@ -23,23 +23,23 @@ var normal = {
|
||||
constants: {}
|
||||
};
|
||||
},
|
||||
sourceDir: "src",
|
||||
outputDir: "build/modules"
|
||||
sourceDir: 'src',
|
||||
outputDir: 'build/modules'
|
||||
};
|
||||
|
||||
|
||||
var test = {
|
||||
rootIDs: rootIDs.concat([
|
||||
"test/all.js",
|
||||
"**/__tests__/*.js"
|
||||
'test/all.js',
|
||||
'**/__tests__/*.js'
|
||||
]),
|
||||
getConfig: function() {
|
||||
return _.merge({}, normal.getConfig(), {
|
||||
mocking: true
|
||||
});
|
||||
},
|
||||
sourceDir: "src",
|
||||
outputDir: "build/modules"
|
||||
sourceDir: 'src',
|
||||
outputDir: 'build/modules'
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -2,12 +2,12 @@
|
||||
|
||||
module.exports = function(grunt) {
|
||||
var jasmine = {
|
||||
rootDirectory: "build/jasmine",
|
||||
// This syntax means to require and expose the "jasmine" module
|
||||
rootDirectory: 'build/jasmine',
|
||||
// This syntax means to require and expose the 'jasmine' module
|
||||
// (build/jasmine/jasmine.js) as global.jasmine, and to require the
|
||||
// "all" module (build/jasmine/all.js) but not expose it globally.
|
||||
args: ["jasmine:jasmine", "all:"],
|
||||
outfile: "./build/jasmine.js"
|
||||
// 'all' module (build/jasmine/all.js) but not expose it globally.
|
||||
args: ['jasmine:jasmine', 'all:'],
|
||||
outfile: './build/jasmine.js'
|
||||
};
|
||||
|
||||
var filterExpr = grunt.option('filter');
|
||||
@@ -19,8 +19,8 @@ module.exports = function(grunt) {
|
||||
}
|
||||
|
||||
var test = {
|
||||
rootDirectory: "build/modules",
|
||||
args: ["test/all:harness"],
|
||||
rootDirectory: 'build/modules',
|
||||
args: ['test/all:harness'],
|
||||
requires: [filterExpr],
|
||||
outfile: './build/react-test.js'
|
||||
};
|
||||
|
||||
+24
-17
@@ -1,9 +1,12 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = function(grunt){
|
||||
var fs = require('fs');
|
||||
var path = require('path');
|
||||
|
||||
module.exports = function(grunt) {
|
||||
var coverageWriteStream;
|
||||
|
||||
grunt.task.registerTask('finalize-coverage-stream', function(){
|
||||
grunt.task.registerTask('finalize-coverage-stream', function() {
|
||||
if (!coverageWriteStream) {
|
||||
return;
|
||||
}
|
||||
@@ -14,13 +17,13 @@ module.exports = function(grunt){
|
||||
});
|
||||
|
||||
function consoleLoggerMiddleware(req, res, next) {
|
||||
if (!(req.method == 'POST' && req._parsedUrl.pathname.replace(/\//g,'') == 'console' && Array.isArray(req.body))) {
|
||||
if (!(req.method === 'POST' && req._parsedUrl.pathname.replace(/\//g, '') === 'console' && Array.isArray(req.body))) {
|
||||
return next();
|
||||
}
|
||||
res.write('<!doctype html><meta charset=utf-8>');
|
||||
res.end('Got it, thanks!');
|
||||
|
||||
req.body.forEach(function(log){
|
||||
req.body.forEach(function(log) {
|
||||
if (log.message.indexOf('not ok ') === 0) {
|
||||
log.type = 'error';
|
||||
} else if (log.message.indexOf('ok ') === 0) {
|
||||
@@ -31,20 +34,20 @@ module.exports = function(grunt){
|
||||
log.type = 'coverage done';
|
||||
}
|
||||
|
||||
if (log.type == 'error') {
|
||||
if (log.type === 'error') {
|
||||
grunt.log.error(log.message);
|
||||
} else if (log.type == 'ok') {
|
||||
} else if (log.type === 'ok') {
|
||||
grunt.log.ok(log.message);
|
||||
} else if (log.type == 'log') {
|
||||
} else if (log.type === 'log') {
|
||||
grunt.log.writeln(log.message);
|
||||
} else if (log.type == 'coverage') {
|
||||
} else if (log.type === 'coverage') {
|
||||
if (!coverageWriteStream) {
|
||||
coverageWriteStream = require('fs').createWriteStream(__dirname + '/../../coverage.log');
|
||||
coverageWriteStream = fs.createWriteStream(path.join(__dirname, '/../../coverage.log'));
|
||||
}
|
||||
coverageWriteStream.write(log.message + '\n');
|
||||
} else if (log.type == 'coverage done') {
|
||||
} else if (log.type === 'coverage done') {
|
||||
grunt.task.run('finalize-coverage-stream');
|
||||
} else if (log.type == 'perf') {
|
||||
} else if (log.type === 'perf') {
|
||||
grunt.event.emit('perf results', log.message);
|
||||
} else {
|
||||
grunt.verbose.writeln(log);
|
||||
@@ -53,7 +56,7 @@ module.exports = function(grunt){
|
||||
}
|
||||
|
||||
function testResultLoggerMiddleware(req, res, next) {
|
||||
if (!(req.method == 'POST' && req._parsedUrl.pathname.indexOf('/reportTestResults') === 0)) {
|
||||
if (!(req.method === 'POST' && req._parsedUrl.pathname.indexOf('/reportTestResults') === 0)) {
|
||||
return next();
|
||||
}
|
||||
res.write('<!doctype html><meta charset=utf-8>');
|
||||
@@ -62,8 +65,8 @@ module.exports = function(grunt){
|
||||
var logType = 'writeln';
|
||||
var message = req.body;
|
||||
|
||||
if (req.body.type && req.body.message){
|
||||
if (req.body.type == 'error') {
|
||||
if (req.body.type && req.body.message) {
|
||||
if (req.body.type === 'error') {
|
||||
logType = 'error';
|
||||
} else if (req.body.message.indexOf('ok') === 0) {
|
||||
logType = 'ok';
|
||||
@@ -72,7 +75,7 @@ module.exports = function(grunt){
|
||||
}
|
||||
message = req.body.message;
|
||||
}
|
||||
if (typeof message != 'string') {
|
||||
if (typeof message !== 'string') {
|
||||
message = JSON.stringify(message, null, 2);
|
||||
}
|
||||
grunt.log[logType]('[%s][%s]', req.headers['user-agent'], Date.now(), message);
|
||||
@@ -86,8 +89,12 @@ module.exports = function(grunt){
|
||||
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(); });
|
||||
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.json(),
|
||||
|
||||
@@ -2,20 +2,20 @@
|
||||
|
||||
var grunt = require('grunt');
|
||||
|
||||
module.exports = function(props){
|
||||
if (typeof props.url != 'string') {
|
||||
module.exports = function(props) {
|
||||
if (typeof props.url !== 'string') {
|
||||
throw TypeError('expected url string');
|
||||
}
|
||||
if ('isDoneTimeout' in props && typeof props.isDoneTimeout != 'number') {
|
||||
if ('isDoneTimeout' in props && typeof props.isDoneTimeout !== 'number') {
|
||||
throw TypeError('expected isDoneTimeout to be a number');
|
||||
}
|
||||
if ('onStart' in props && typeof props.onStart != 'function') {
|
||||
if ('onStart' in props && typeof props.onStart !== 'function') {
|
||||
throw TypeError('expected onStart to be a function');
|
||||
}
|
||||
if ('onComplete' in props && typeof props.onComplete != 'function') {
|
||||
if ('onComplete' in props && typeof props.onComplete !== 'function') {
|
||||
throw TypeError('expected onComplete to be a function');
|
||||
}
|
||||
if ('onError' in props && typeof props.onError != 'function') {
|
||||
if ('onError' in props && typeof props.onError !== 'function') {
|
||||
throw TypeError('expected onError to be a function');
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ module.exports = function(props){
|
||||
};
|
||||
|
||||
if (grunt.option('debug')) {
|
||||
exports.local.url += (exports.local.url.indexOf('?') == -1 ? '?' : '&') + 'debug=' + grunt.option('debug');
|
||||
exports.local.url += (exports.local.url.indexOf('?') === -1 ? '?' : '&') + 'debug=' + grunt.option('debug');
|
||||
}
|
||||
|
||||
exports.saucelabs = {
|
||||
@@ -49,13 +49,13 @@ module.exports = function(props){
|
||||
}
|
||||
},
|
||||
desiredCapabilities: {
|
||||
"build": process.env.TRAVIS_BUILD_NUMBER || 'dev' + Date.now(),
|
||||
"tunnel-identifier": process.env.TRAVIS_JOB_NUMBER || 'my awesome tunnel',
|
||||
"browserName": "chrome"
|
||||
'build': process.env.TRAVIS_BUILD_NUMBER || 'dev' + Date.now(),
|
||||
'tunnel-identifier': process.env.TRAVIS_JOB_NUMBER || 'my awesome tunnel',
|
||||
'browserName': 'chrome'
|
||||
},
|
||||
url: exports.local.url,
|
||||
onStart: function(browser){
|
||||
grunt.log.writeln("Starting WebDriver Test. Watch results here: http://saucelabs.com/tests/" + browser.sessionID);
|
||||
onStart: function(browser) {
|
||||
grunt.log.writeln('Starting WebDriver Test. Watch results here: http://saucelabs.com/tests/' + browser.sessionID);
|
||||
if (props.onStart) {
|
||||
return props.onStart(browser);
|
||||
}
|
||||
@@ -65,6 +65,7 @@ module.exports = function(props){
|
||||
isDoneTimeout: exports.local.isDoneTimeout
|
||||
};
|
||||
|
||||
/*eslint-disable camelcase*/
|
||||
/* https://saucelabs.com/platforms */
|
||||
exports.saucelabs_ios =
|
||||
exports.saucelabs_ios7 = sauceItUp({ browserName: 'iphone', version: '7', platform:'OS X 10.9' });
|
||||
@@ -94,10 +95,11 @@ module.exports = function(props){
|
||||
exports.saucelabs_ie9 = sauceItUp({ browserName: 'internet explorer', version: 9 });
|
||||
exports.saucelabs_ie10 = sauceItUp({ browserName: 'internet explorer', version: 10 });
|
||||
exports.saucelabs_ie11 = sauceItUp({ browserName: 'internet explorer', version: 11, platform:'Windows 8.1' });
|
||||
/*eslint-enable camelcase*/
|
||||
|
||||
function sauceItUp(desiredCapabilities) {
|
||||
desiredCapabilities["build"] = exports.saucelabs.desiredCapabilities["build"];
|
||||
desiredCapabilities["tunnel-identifier"] = exports.saucelabs.desiredCapabilities["tunnel-identifier"];
|
||||
desiredCapabilities.build = exports.saucelabs.desiredCapabilities.build;
|
||||
desiredCapabilities['tunnel-identifier'] = exports.saucelabs.desiredCapabilities['tunnel-identifier'];
|
||||
return {
|
||||
webdriver: exports.saucelabs.webdriver,
|
||||
url: exports.saucelabs.url,
|
||||
@@ -105,7 +107,7 @@ module.exports = function(props){
|
||||
onComplete: exports.saucelabs.onComplete,
|
||||
onError: exports.saucelabs.onError,
|
||||
isDoneTimeout: exports.saucelabs.isDoneTimeout,
|
||||
desiredCapabilities: desiredCapabilities,
|
||||
desiredCapabilities: desiredCapabilities
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -3,13 +3,13 @@
|
||||
var grunt = require('grunt');
|
||||
|
||||
module.exports = require('./webdriver-all')({
|
||||
url: "http://127.0.0.1:9999/test/index.html",
|
||||
onComplete: function(passed){
|
||||
if (!passed){
|
||||
grunt.fatal("tests failed");
|
||||
url: 'http://127.0.0.1:9999/test/index.html',
|
||||
onComplete: function(passed) {
|
||||
if (!passed) {
|
||||
grunt.fatal('tests failed');
|
||||
}
|
||||
},
|
||||
onError: function(error){
|
||||
onError: function(error) {
|
||||
grunt.fatal(error);
|
||||
}
|
||||
});
|
||||
@@ -1,8 +1,9 @@
|
||||
'use strict';
|
||||
|
||||
var grunt = require('grunt');
|
||||
var path = require('path');
|
||||
|
||||
var tests = grunt.file.expand(__dirname + '/../../perf/tests/*');
|
||||
var tests = grunt.file.expand(path.join(__dirname, '/../../perf/tests/*'));
|
||||
|
||||
var maxTime = 5;
|
||||
|
||||
@@ -15,33 +16,39 @@ var params = []
|
||||
.concat('headless=false')
|
||||
.concat('maxTime=' + maxTime)
|
||||
.concat(tests
|
||||
.map(function(path){ return path.split(/tests./i).reverse()[0]; })
|
||||
.map(function(testPath) {
|
||||
return testPath.split(/tests./i).reverse()[0];
|
||||
})
|
||||
.map(encodeURIComponent)
|
||||
.map(function(filename){ return 'test=' + filename; })
|
||||
.map(function(filename) {
|
||||
return 'test=' + filename;
|
||||
})
|
||||
)
|
||||
.concat(reactVersions
|
||||
.map(encodeURIComponent)
|
||||
.map(function(version){ return 'react=' + version; }
|
||||
.map(function(version) {
|
||||
return 'react=' + version;
|
||||
}
|
||||
)
|
||||
);
|
||||
|
||||
module.exports = require('./webdriver-all')({
|
||||
|
||||
url: "http://127.0.0.1:9999/perf/index.html?" + params.join('&'),
|
||||
url: 'http://127.0.0.1:9999/perf/index.html?' + params.join('&'),
|
||||
|
||||
isDoneTimeout: 15 * 60 * 1000,
|
||||
|
||||
onStart: function(){
|
||||
grunt.event.on('perf results', function(results){
|
||||
onStart: function() {
|
||||
grunt.event.on('perf results', function(results) {
|
||||
console.log(results);
|
||||
});
|
||||
},
|
||||
|
||||
onComplete: function(completedTestKeys){
|
||||
onComplete: function(completedTestKeys) {
|
||||
grunt.verbose.writeln('onComplete ' + JSON.stringify(completedTestKeys));
|
||||
},
|
||||
|
||||
onError: function(error){
|
||||
onError: function(error) {
|
||||
grunt.fatal(error);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,47 +1,48 @@
|
||||
"use strict";
|
||||
'use strict';
|
||||
var grunt = require('grunt');
|
||||
var path = require('path');
|
||||
var fs = require('fs');
|
||||
|
||||
module.exports = function(){
|
||||
var ROOT = require('path').normalize(__dirname + '/../..');
|
||||
module.exports = function() {
|
||||
var ROOT = path.join(__dirname, '/../..');
|
||||
var done = this.async();
|
||||
var uncoveredExpressionCount = 0;
|
||||
var uncoveredLineCount = 0;
|
||||
|
||||
require('fs').createReadStream(ROOT + '/coverage.log')
|
||||
.pipe(require('coverify/parse')(function(error, results){
|
||||
fs.createReadStream(ROOT + '/coverage.log')
|
||||
.pipe(require('coverify/parse')(function(error, results) {
|
||||
if (error) {
|
||||
grunt.fatal(error);
|
||||
}
|
||||
|
||||
Object.keys(results)
|
||||
.sort(function(a, b){
|
||||
.sort(function(a, b) {
|
||||
return results[a].length - results[b].length;
|
||||
})
|
||||
.reverse()
|
||||
.forEach(function(path){
|
||||
if (results[path].length === 0) {
|
||||
.forEach(function(concretePath) {
|
||||
if (results[concretePath].length === 0) {
|
||||
return;
|
||||
}
|
||||
var relativePath = path.replace(ROOT, '');
|
||||
uncoveredExpressionCount += results[path].length;
|
||||
grunt.log.error(results[path].length + ' expressions not covered ' + relativePath);
|
||||
var relativePath = concretePath.replace(ROOT, '');
|
||||
uncoveredExpressionCount += results[concretePath].length;
|
||||
grunt.log.error(results[concretePath].length + ' expressions not covered ' + relativePath);
|
||||
|
||||
results[path].forEach(function(c){
|
||||
results[concretePath].forEach(function(c) {
|
||||
uncoveredLineCount += c.code.split('\n').length;
|
||||
console.log('txmt://open?url=' + encodeURIComponent('file://' + path) + '&line=' + (c.lineNum+1) + '&column=' + (c.column[0]+2));
|
||||
console.log('txmt://open?url=' + encodeURIComponent('file://' + concretePath) + '&line=' + (c.lineNum + 1) + '&column=' + (c.column[0] + 2));
|
||||
});
|
||||
console.log('');
|
||||
})
|
||||
;
|
||||
});
|
||||
|
||||
Object.keys(results).sort().forEach(function(path){
|
||||
if (results[path].length > 0) {
|
||||
Object.keys(results).sort().forEach(function(concretePath) {
|
||||
if (results[concretePath].length > 0) {
|
||||
return;
|
||||
}
|
||||
var relativePath = path.replace(ROOT, '');
|
||||
var relativePath = concretePath.replace(ROOT, '');
|
||||
grunt.log.ok('100% coverage ' + relativePath);
|
||||
});
|
||||
|
||||
|
||||
if (uncoveredExpressionCount > 0) {
|
||||
grunt.log.error(uncoveredExpressionCount + ' expressions not covered');
|
||||
}
|
||||
|
||||
@@ -1,47 +1,47 @@
|
||||
"use strict";
|
||||
'use strict';
|
||||
|
||||
var grunt = require('grunt');
|
||||
var http = require('http');
|
||||
var fs = require('fs');
|
||||
var path = require('path');
|
||||
|
||||
function get(url, targetFilePath, completedSuccessfully) {
|
||||
grunt.verbose.writeln('getting url \'' + url + '\'');
|
||||
http.get(url, function(response) {
|
||||
grunt.verbose.writeln('Received status code ' + response.statusCode + ' for \'' + url + '\'');
|
||||
|
||||
if (response.statusCode !== 200) {
|
||||
if (response.headers.location) {
|
||||
get(response.headers.location, targetFilePath);
|
||||
return;
|
||||
} else {
|
||||
grunt.fatal('Nothing else to do.');
|
||||
completedSuccessfully(false);
|
||||
return;
|
||||
}
|
||||
}
|
||||
grunt.verbose.writeln('Writing url to \'' + targetFilePath + '\'');
|
||||
response.pipe(fs.createWriteStream(targetFilePath))
|
||||
.on('close', function() {
|
||||
completedSuccessfully(true);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
module.exports = function() {
|
||||
var completedSuccessfully = this.async();
|
||||
get(
|
||||
"http://react.zpao.com/builds/master/latest/react.min.js",
|
||||
__dirname + '/../../build/react-previous.min.js',
|
||||
function(success){
|
||||
'http://react.zpao.com/builds/master/latest/react.min.js',
|
||||
path.join(__dirname, '/../../build/react-previous.min.js'),
|
||||
function(success) {
|
||||
if (!success) {
|
||||
return completedSuccessfully(success);
|
||||
}
|
||||
get(
|
||||
"http://react.zpao.com/builds/master/latest/JSXTransformer.js",
|
||||
__dirname + '/../../build/JSXTransformer-previous.js',
|
||||
'http://react.zpao.com/builds/master/latest/JSXTransformer.js',
|
||||
path.join(__dirname, '/../../build/JSXTransformer-previous.js'),
|
||||
completedSuccessfully
|
||||
);
|
||||
}
|
||||
);
|
||||
|
||||
function get(url, targetFilePath, completedSuccessfully) {
|
||||
grunt.verbose.writeln('getting url "' + url + '"');
|
||||
http.get(url, function(response) {
|
||||
grunt.verbose.writeln('Received status code ' + response.statusCode + ' for "' + url + '"');
|
||||
|
||||
if (response.statusCode != 200) {
|
||||
if (response.headers.location) {
|
||||
get(response.headers.location, targetFilePath);
|
||||
return;
|
||||
} else {
|
||||
grunt.fatal('Nothing else to do.');
|
||||
completedSuccessfully(false);
|
||||
return;
|
||||
}
|
||||
}
|
||||
grunt.verbose.writeln('Writing url to "' + targetFilePath + '"');
|
||||
response.pipe(fs.createWriteStream(targetFilePath))
|
||||
.on('close', function() {
|
||||
completedSuccessfully(true);
|
||||
})
|
||||
;
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,22 @@
|
||||
'use strict';
|
||||
|
||||
var grunt = require('grunt');
|
||||
|
||||
module.exports = function() {
|
||||
var done = this.async();
|
||||
grunt.util.spawn({
|
||||
cmd: 'node_modules/.bin/eslint',
|
||||
args: ['src/', 'Gruntfile.js', 'grunt/', 'main.js', 'perf/', 'test/']
|
||||
}, function(err, result, code) {
|
||||
if (err) {
|
||||
grunt.log.error('Lint failed');
|
||||
} else {
|
||||
grunt.log.ok('Lint passed (but may contain warnings)');
|
||||
}
|
||||
if (result.stdout.length) {
|
||||
grunt.log.writeln(result.stdout);
|
||||
}
|
||||
|
||||
done(code === 0);
|
||||
});
|
||||
};
|
||||
@@ -12,19 +12,21 @@ var buildFiles = [
|
||||
];
|
||||
|
||||
function buildRelease() {
|
||||
grunt.file.exists(dest) && grunt.file.delete(dest);
|
||||
if (grunt.file.exists(dest)) {
|
||||
grunt.file.delete(dest);
|
||||
}
|
||||
|
||||
// Copy gem-react-source/**/* to build/gem-react-source
|
||||
var mappings = [].concat(
|
||||
grunt.file.expandMapping('**/*', dest, {cwd: src})
|
||||
);
|
||||
mappings.forEach(function(mapping) {
|
||||
var src = mapping.src[0];
|
||||
var dest = mapping.dest;
|
||||
if (grunt.file.isDir(src)) {
|
||||
grunt.file.mkdir(dest);
|
||||
var mappingSrc = mapping.src[0];
|
||||
var mappingDest = mapping.dest;
|
||||
if (grunt.file.isDir(mappingSrc)) {
|
||||
grunt.file.mkdir(mappingDest);
|
||||
} else {
|
||||
grunt.file.copy(src, dest);
|
||||
grunt.file.copy(mappingSrc, mappingDest);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -36,7 +38,6 @@ function buildRelease() {
|
||||
}
|
||||
|
||||
function packRelease() {
|
||||
/*jshint validthis:true */
|
||||
var done = this.async();
|
||||
var spawnCmd = {
|
||||
cmd: 'gem',
|
||||
@@ -46,12 +47,15 @@ function packRelease() {
|
||||
}
|
||||
};
|
||||
grunt.util.spawn(spawnCmd, function(err, result) {
|
||||
if (err) {
|
||||
grunt.log.error(err);
|
||||
}
|
||||
// Gem packing does weird things to versions so 0.12.0-alpha becomes
|
||||
// 0.12.0.pre.alpha. We need to get the filename printed to stdout.
|
||||
var filename = result.stdout.match(/File: (.*)$/)[1];
|
||||
var src = 'build/gem-react-source/' + filename;
|
||||
var dest = 'build/react-source.tgz';
|
||||
fs.rename(src, dest, done);
|
||||
var buildSrc = 'build/gem-react-source/' + filename;
|
||||
var buildDest = 'build/react-source.tgz';
|
||||
fs.rename(buildSrc, buildDest, done);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
+11
-11
@@ -1,7 +1,7 @@
|
||||
'use strict';
|
||||
|
||||
var path = require("path");
|
||||
var grunt = require("grunt");
|
||||
var path = require('path');
|
||||
var grunt = require('grunt');
|
||||
var expand = grunt.file.expand;
|
||||
var spawn = grunt.util.spawn;
|
||||
|
||||
@@ -10,27 +10,27 @@ module.exports = function() {
|
||||
var config = this.data;
|
||||
|
||||
var args = [
|
||||
"--cache-dir", ".module-cache",
|
||||
"--relativize",
|
||||
"--follow-requires",
|
||||
"--use-provides-module",
|
||||
'--cache-dir', '.module-cache',
|
||||
'--relativize',
|
||||
'--follow-requires',
|
||||
'--use-provides-module',
|
||||
config.sourceDir,
|
||||
config.outputDir
|
||||
];
|
||||
|
||||
var rootIDs = expand({
|
||||
nonull: true, // Keep IDs that don't expand to anything.
|
||||
cwd: "src"
|
||||
cwd: 'src'
|
||||
}, config.rootIDs).map(function(id) {
|
||||
return id.replace(/\.js$/i, "");
|
||||
return id.replace(/\.js$/i, '');
|
||||
});
|
||||
|
||||
args.push.apply(args, rootIDs);
|
||||
args.push("--config" /* from stdin */);
|
||||
args.push('--config' /* from stdin */);
|
||||
|
||||
var child = spawn({
|
||||
cmd: "node",
|
||||
args: [path.join("bin", "jsx-internal")].concat(args)
|
||||
cmd: 'node',
|
||||
args: [path.join('bin', 'jsx-internal')].concat(args)
|
||||
}, function(error, result, code) {
|
||||
if (error) {
|
||||
grunt.log.error(error);
|
||||
|
||||
@@ -7,7 +7,9 @@ var src = 'npm-react-tools';
|
||||
var dest = 'build/npm-react-tools/';
|
||||
|
||||
function buildRelease() {
|
||||
grunt.file.exists(dest) && grunt.file.delete(dest);
|
||||
if (grunt.file.exists(dest)) {
|
||||
grunt.file.delete(dest);
|
||||
}
|
||||
|
||||
// read our required files from package.json
|
||||
var pkgFiles = grunt.config.data.pkg.files;
|
||||
@@ -27,18 +29,17 @@ function buildRelease() {
|
||||
});
|
||||
|
||||
mappings.forEach(function(mapping) {
|
||||
var src = mapping.src[0];
|
||||
var dest = mapping.dest;
|
||||
if (grunt.file.isDir(src)) {
|
||||
grunt.file.mkdir(dest);
|
||||
var mappingSrc = mapping.src[0];
|
||||
var mappingDest = mapping.dest;
|
||||
if (grunt.file.isDir(mappingSrc)) {
|
||||
grunt.file.mkdir(mappingDest);
|
||||
} else {
|
||||
grunt.file.copy(src, dest);
|
||||
grunt.file.copy(mappingSrc, mappingDest);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function packRelease() {
|
||||
/*jshint validthis:true */
|
||||
var done = this.async();
|
||||
var spawnCmd = {
|
||||
cmd: 'npm',
|
||||
@@ -48,9 +49,9 @@ function packRelease() {
|
||||
}
|
||||
};
|
||||
grunt.util.spawn(spawnCmd, function() {
|
||||
var src = 'build/react-tools-' + grunt.config.data.pkg.version + '.tgz';
|
||||
var dest = 'build/react-tools.tgz';
|
||||
fs.rename(src, dest, done);
|
||||
var buildSrc = 'build/react-tools-' + grunt.config.data.pkg.version + '.tgz';
|
||||
var buildDest = 'build/react-tools.tgz';
|
||||
fs.rename(buildSrc, buildDest, done);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
+11
-10
@@ -15,7 +15,9 @@ var distFiles = [
|
||||
|
||||
function buildRelease() {
|
||||
// delete build/react-core for fresh start
|
||||
grunt.file.exists(dest) && grunt.file.delete(dest);
|
||||
if (grunt.file.exists(dest)) {
|
||||
grunt.file.delete(dest);
|
||||
}
|
||||
|
||||
// mkdir -p build/react-core/lib
|
||||
grunt.file.mkdir(lib);
|
||||
@@ -27,12 +29,12 @@ function buildRelease() {
|
||||
grunt.file.expandMapping('**/*', lib, {cwd: modSrc})
|
||||
);
|
||||
mappings.forEach(function(mapping) {
|
||||
var src = mapping.src[0];
|
||||
var dest = mapping.dest;
|
||||
if (grunt.file.isDir(src)) {
|
||||
grunt.file.mkdir(dest);
|
||||
var mappingSrc = mapping.src[0];
|
||||
var mappingDest = mapping.dest;
|
||||
if (grunt.file.isDir(mappingSrc)) {
|
||||
grunt.file.mkdir(mappingDest);
|
||||
} else {
|
||||
grunt.file.copy(src, dest);
|
||||
grunt.file.copy(mappingSrc, mappingDest);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -49,7 +51,6 @@ function buildRelease() {
|
||||
}
|
||||
|
||||
function packRelease() {
|
||||
/*jshint validthis:true */
|
||||
var done = this.async();
|
||||
var spawnCmd = {
|
||||
cmd: 'npm',
|
||||
@@ -59,9 +60,9 @@ function packRelease() {
|
||||
}
|
||||
};
|
||||
grunt.util.spawn(spawnCmd, function() {
|
||||
var src = 'build/react-' + grunt.config.data.pkg.version + '.tgz';
|
||||
var dest = 'build/react.tgz';
|
||||
fs.rename(src, dest, done);
|
||||
var buildSrc = 'build/react-' + grunt.config.data.pkg.version + '.tgz';
|
||||
var buildDest = 'build/react.tgz';
|
||||
fs.rename(buildSrc, buildDest, done);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
+24
-24
@@ -1,26 +1,26 @@
|
||||
'use strict';
|
||||
|
||||
var assert = require("assert");
|
||||
var path = require("path");
|
||||
var grunt = require("grunt");
|
||||
var assert = require('assert');
|
||||
var path = require('path');
|
||||
var grunt = require('grunt');
|
||||
var spawn = grunt.util.spawn;
|
||||
|
||||
module.exports = function() {
|
||||
var done = this.async();
|
||||
|
||||
function run(cmd, args, opts, callback) {
|
||||
assert.strictEqual(typeof cmd, "string");
|
||||
assert.strictEqual(typeof cmd, 'string');
|
||||
assert.ok(args instanceof Array);
|
||||
|
||||
if (typeof opts === "function" && !callback) {
|
||||
if (typeof opts === 'function' && !callback) {
|
||||
callback = opts;
|
||||
opts = {};
|
||||
}
|
||||
|
||||
assert.strictEqual(typeof opts, "object");
|
||||
assert.strictEqual(typeof callback, "function");
|
||||
assert.strictEqual(typeof opts, 'object');
|
||||
assert.strictEqual(typeof callback, 'function');
|
||||
|
||||
grunt.log.writeln("> " + cmd + " " + args.join(" "));
|
||||
grunt.log.writeln('> ' + cmd + ' ' + args.join(' '));
|
||||
|
||||
// var proc =
|
||||
spawn({
|
||||
@@ -42,33 +42,33 @@ module.exports = function() {
|
||||
}
|
||||
|
||||
var pkg = grunt.config.data.pkg;
|
||||
var tgz = pkg.name + "-" + pkg.version + ".tgz";
|
||||
var tgz = pkg.name + '-' + pkg.version + '.tgz';
|
||||
|
||||
grunt.log.writeln("Packing " + tgz + " (this could take a while)...");
|
||||
grunt.log.writeln('Packing ' + tgz + ' (this could take a while)...');
|
||||
|
||||
run("npm", ["pack", "--verbose", "."], function() {
|
||||
require("tmp").dir(function(err, dir) {
|
||||
run('npm', ['pack', '--verbose', '.'], function() {
|
||||
require('tmp').dir(function(err, dir) {
|
||||
if (err) {
|
||||
grunt.log.error(err);
|
||||
done(false);
|
||||
return;
|
||||
}
|
||||
|
||||
run("cp", [tgz, dir], function() {
|
||||
run("npm", [
|
||||
"install",
|
||||
"--production",
|
||||
run('cp', [tgz, dir], function() {
|
||||
run('npm', [
|
||||
'install',
|
||||
'--production',
|
||||
tgz
|
||||
], { cwd: dir }, function() {
|
||||
var nodePath = path.join(dir, "node_modules");
|
||||
var nodePath = path.join(dir, 'node_modules');
|
||||
var pkgDir = path.join(nodePath, pkg.name);
|
||||
var doneCount = 2;
|
||||
|
||||
// Make sure that bin/jsx is runnable by echoing main.js.
|
||||
run("bin/jsx", ["main.js"], {
|
||||
run('bin/jsx', ['main.js'], {
|
||||
cwd: pkgDir
|
||||
}, function(result) {
|
||||
assert.ok(result.stdout.indexOf("transform") >= 0, result.stdout);
|
||||
assert.ok(result.stdout.indexOf('transform') >= 0, result.stdout);
|
||||
|
||||
if (--doneCount === 0) {
|
||||
done();
|
||||
@@ -76,17 +76,17 @@ module.exports = function() {
|
||||
});
|
||||
|
||||
// Make sure the .transform package method works.
|
||||
run("node", [
|
||||
"--print",
|
||||
'require("react-tools").transform(' +
|
||||
run('node', [
|
||||
'--print',
|
||||
'require(\'react-tools\').transform(' +
|
||||
JSON.stringify(
|
||||
"/** @jsx React.DOM */ <div>oyez</div>;"
|
||||
'/** @jsx React.DOM */ <div>oyez</div>;'
|
||||
) + ')'
|
||||
], {
|
||||
env: { NODE_PATH: nodePath }
|
||||
}, function(result, code) {
|
||||
assert.ok(result.stdout.indexOf(
|
||||
'React.DOM.div(null, "oyez");'
|
||||
'React.DOM.div(null, \'oyez\');'
|
||||
) >= 0, result.stdout);
|
||||
|
||||
if (--doneCount === 0) {
|
||||
|
||||
@@ -2,12 +2,13 @@
|
||||
|
||||
var grunt = require('grunt');
|
||||
var fs = require('fs');
|
||||
var path = require('path');
|
||||
|
||||
module.exports = function() {
|
||||
var config = this.data;
|
||||
var done = this.async();
|
||||
|
||||
var theFilesToTestScript = fs.createWriteStream(__dirname + '/../../test/the-files-to-test.generated.js');
|
||||
var theFilesToTestScript = fs.createWriteStream(path.join(__dirname, '/../../test/the-files-to-test.generated.js'));
|
||||
theFilesToTestScript.write('// Generated by ');
|
||||
theFilesToTestScript.write(JSON.stringify(__filename.split(/(?=grunt)/)[1]));
|
||||
theFilesToTestScript.write(' at ');
|
||||
@@ -23,12 +24,12 @@ module.exports = function() {
|
||||
nonull: true, // Keep IDs that don't expand to anything.
|
||||
cwd: config.rootDirectory
|
||||
}, requires).forEach(function(name) {
|
||||
name = name.replace(/\.js$/i, "");
|
||||
name = name.replace(/\.js$/i, '');
|
||||
args.push(name);
|
||||
theFilesToTestScript.write('harness.enableTest(' + JSON.stringify(name) + ');\n');
|
||||
});
|
||||
|
||||
require("populist").buildP({
|
||||
require('populist').buildP({
|
||||
rootDirectory: config.rootDirectory,
|
||||
args: args
|
||||
}).then(function(output) {
|
||||
|
||||
@@ -1,6 +1,3 @@
|
||||
// function calls get bound so "possible strict mode violations" aren't
|
||||
// jshint -W040
|
||||
|
||||
'use strict';
|
||||
|
||||
var grunt = require('grunt');
|
||||
@@ -59,8 +56,7 @@ function _gitCommitAndTag(cwd, commitMsg, tag, cb) {
|
||||
grunt.util.spawn(gitCommit, function() {
|
||||
if (tag) {
|
||||
grunt.util.spawn(gitTag, cb);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
cb();
|
||||
}
|
||||
});
|
||||
|
||||
@@ -22,7 +22,7 @@ module.exports = function() {
|
||||
var taskCompletedSuccessfully = task.async();
|
||||
|
||||
var stunnel = new SauceTunnel(SAUCE_USERNAME, SAUCE_ACCESS_KEY, IDENTIFIER, /*tunneled*/true, /*tunnelTimeout*/5);
|
||||
process.on('exit', stunnel.stop.bind(stunnel, function(){}));
|
||||
process.on('exit', stunnel.stop.bind(stunnel, function() {}));
|
||||
|
||||
stunnel.on('log:error', grunt.log.error.bind(grunt.log));
|
||||
stunnel.on('log:writeln', grunt.log.writeln.bind(grunt.log));
|
||||
@@ -32,7 +32,7 @@ module.exports = function() {
|
||||
stunnel.on('verbose:debug', grunt.verbose.debug.bind(grunt.verbose));
|
||||
stunnel.on('verbose:writeln', grunt.verbose.writeln.bind(grunt.verbose));
|
||||
|
||||
stunnel.openTunnel(function(isOpen){
|
||||
stunnel.openTunnel(function(isOpen) {
|
||||
if (shouldStayAliveForever && isOpen) {
|
||||
grunt.verbose.writeln('Keeping the sauce-tunnel open forever because you used the keepalive flag `' + task.nameArgs + '`');
|
||||
return;
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
/* jshint evil: true */
|
||||
|
||||
/*eslint-disable consistent-return*/
|
||||
'use strict';
|
||||
|
||||
var grunt = require("grunt");
|
||||
var grunt = require('grunt');
|
||||
var wd = require('wd');
|
||||
|
||||
module.exports = function task(getJSReport){
|
||||
module.exports = function task(getJSReport) {
|
||||
var config = this.data;
|
||||
var taskSucceeded = this.async();
|
||||
getJSReport = getJSReport.bind(this, config, wd);
|
||||
@@ -19,7 +18,7 @@ module.exports = function task(getJSReport){
|
||||
desiredCapabilities[key] = config.desiredCapabilities[key];
|
||||
});
|
||||
}
|
||||
grunt.verbose.writeln("desiredCapabilities", JSON.stringify(desiredCapabilities));
|
||||
grunt.verbose.writeln('desiredCapabilities', JSON.stringify(desiredCapabilities));
|
||||
|
||||
var browser = wd.promiseChainRemote(config.webdriver.remote);
|
||||
|
||||
@@ -38,18 +37,23 @@ module.exports = function task(getJSReport){
|
||||
.init(desiredCapabilities)
|
||||
.then(config.onStart && config.onStart.bind(config, browser))
|
||||
.get(config.url)
|
||||
.then(function(){return browser;})
|
||||
.then(function() {
|
||||
return browser;
|
||||
})
|
||||
.then(getJSReport)
|
||||
.then(function(data){ results = data; })
|
||||
.fail(function(error){
|
||||
.then(function(data) {
|
||||
results = data;
|
||||
})
|
||||
.fail(function(error) {
|
||||
grunt.log.error(error);
|
||||
return browser
|
||||
.eval('document.documentElement.innerText || document.documentElement.textContent')
|
||||
.then(grunt.verbose.writeln.bind(grunt.verbose))
|
||||
.then(function(){ throw error; })
|
||||
;
|
||||
.then(function() {
|
||||
throw error;
|
||||
});
|
||||
})
|
||||
.finally(function(){
|
||||
.finally(function() {
|
||||
if (grunt.option('webdriver-keep-open')) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1,17 +1,14 @@
|
||||
/* jshint evil: true */
|
||||
|
||||
'use strict';
|
||||
|
||||
module.exports = function(){
|
||||
return require('./webdriver-all').call(this, function(config, wd, browser){
|
||||
module.exports = function() {
|
||||
return require('./webdriver-all').call(this, function(config, wd, browser) {
|
||||
return browser
|
||||
.waitFor(wd.asserters.jsCondition("typeof window.jasmine != 'undefined'"), 5e3, 50)
|
||||
.fail(function(error){
|
||||
throw Error("The test page didn't load properly. " + error);
|
||||
.waitFor(wd.asserters.jsCondition('typeof window.jasmine != \'undefined\''), 5e3, 50)
|
||||
.fail(function(error) {
|
||||
throw Error('The test page didn\'t load properly. ' + error);
|
||||
})
|
||||
.waitFor(wd.asserters.jsCondition("typeof window.jasmine.getJSReport != 'undefined'"), 60e3, 100)
|
||||
.waitFor(wd.asserters.jsCondition("window.postDataToURL.running <= 0"), 30e3, 500)
|
||||
.eval("jasmine.getJSReport().passed")
|
||||
;
|
||||
.waitFor(wd.asserters.jsCondition('typeof window.jasmine.getJSReport != \'undefined\''), 60e3, 100)
|
||||
.waitFor(wd.asserters.jsCondition('window.postDataToURL.running <= 0'), 30e3, 500)
|
||||
.eval('jasmine.getJSReport().passed');
|
||||
});
|
||||
};
|
||||
@@ -1,23 +1,20 @@
|
||||
/* jshint evil: true */
|
||||
|
||||
'use strict';
|
||||
|
||||
var grunt = require('grunt');
|
||||
|
||||
module.exports = function(){
|
||||
return require('./webdriver-all').call(this, function(config, wd, browser){
|
||||
module.exports = function() {
|
||||
return require('./webdriver-all').call(this, function(config, wd, browser) {
|
||||
if (!config.isDoneTimeout) {
|
||||
grunt.verbose.writeln('Expected isDoneTimeout config, using default value');
|
||||
}
|
||||
grunt.verbose.writeln('isDoneTimeout:' + config.isDoneTimeout);
|
||||
return browser
|
||||
.waitFor(wd.asserters.jsCondition("window.isDone === false"), 5e3, 50)
|
||||
.fail(function(error){
|
||||
throw Error("The test page didn't load properly. " + error);
|
||||
.waitFor(wd.asserters.jsCondition('window.isDone === false'), 5e3, 50)
|
||||
.fail(function(error) {
|
||||
throw Error('The test page didn\'t load properly. ' + error);
|
||||
})
|
||||
.waitFor(wd.asserters.jsCondition("window.isDone === true"), config.isDoneTimeout || 30e3, 1e3)
|
||||
.waitFor(wd.asserters.jsCondition("window.postDataToURL.running <= 0"), 30e3, 500)
|
||||
.eval("window.completedTestKeys || window._unhandledError")
|
||||
;
|
||||
.waitFor(wd.asserters.jsCondition('window.isDone === true'), config.isDoneTimeout || 30e3, 1e3)
|
||||
.waitFor(wd.asserters.jsCondition('window.postDataToURL.running <= 0'), 30e3, 500)
|
||||
.eval('window.completedTestKeys || window._unhandledError');
|
||||
});
|
||||
};
|
||||
@@ -2,17 +2,17 @@
|
||||
|
||||
var grunt = require('grunt');
|
||||
|
||||
module.exports = function(){
|
||||
module.exports = function() {
|
||||
var onReadyCallback = this.async();
|
||||
|
||||
var phantomjs = require("phantomjs").path;
|
||||
var child_process = require('child_process');
|
||||
var phantomjs = require('phantomjs').path;
|
||||
var childProcess = require('child_process');
|
||||
var config = this.data || {};
|
||||
|
||||
var args = ["--webdriver=" + (config.port || 9515)];
|
||||
var args = ['--webdriver=' + (config.port || 9515)];
|
||||
grunt.verbose.writeln('phantomjs START path:%s args:%s', phantomjs, args);
|
||||
|
||||
var child = child_process.spawn(phantomjs, args);
|
||||
var child = childProcess.spawn(phantomjs, args);
|
||||
process.on('exit', function() {
|
||||
child.kill();
|
||||
});
|
||||
@@ -29,7 +29,7 @@ module.exports = function(){
|
||||
});
|
||||
|
||||
function verboseWrite(chunk) {
|
||||
if (onReadyCallback && chunk.toString().indexOf('running on port') != -1) {
|
||||
if (onReadyCallback && chunk.toString().indexOf('running on port') !== -1) {
|
||||
grunt.verbose.writeln('phantomjs STARTED');
|
||||
onReadyCallback();
|
||||
onReadyCallback = null;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
'use strict';
|
||||
|
||||
/*eslint-disable no-undef*/
|
||||
var visitors = require('./vendor/fbtransform/visitors');
|
||||
var transform = require('jstransform').transform;
|
||||
var typesSyntax = require('jstransform/visitors/type-syntax');
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
globals:
|
||||
document: true
|
||||
window: true
|
||||
Benchmark: true
|
||||
React: true
|
||||
_rootNode: true
|
||||
todolist: true
|
||||
_app: true
|
||||
_todo1: true
|
||||
_todo2: true
|
||||
_todo3: true
|
||||
_timesToRun: true
|
||||
setState: true
|
||||
|
||||
rules:
|
||||
strict: false
|
||||
no-undef: false
|
||||
no-unused-vars: false
|
||||
block-scoped-var: false
|
||||
consistent-return: false
|
||||
no-shadow: false
|
||||
@@ -10,56 +10,59 @@ var BrowserPerfRunnerApp = React.createClass({
|
||||
headless: React.PropTypes.bool
|
||||
},
|
||||
|
||||
getInitialState: function(){
|
||||
getInitialState: function() {
|
||||
var queue = [];
|
||||
this.props.tests.forEach(function(testName){
|
||||
this.props.react.forEach(function(version){
|
||||
this.props.tests.forEach(function(testName) {
|
||||
this.props.react.forEach(function(version) {
|
||||
queue.push({
|
||||
test: testName,
|
||||
react: version
|
||||
});
|
||||
},this);
|
||||
},this);
|
||||
}, this);
|
||||
}, this);
|
||||
return {
|
||||
queue: queue,
|
||||
results: {}
|
||||
};
|
||||
},
|
||||
|
||||
handleResults: function(results){
|
||||
handleResults: function(results) {
|
||||
this.state.results[results.test + '@' + results.react] = results;
|
||||
this.replaceState(this.state);
|
||||
},
|
||||
|
||||
handleComplete: function(queueItem){
|
||||
handleComplete: function(queueItem) {
|
||||
queueItem.completed = true;
|
||||
|
||||
|
||||
if (!this.props.onCompleteEach) {
|
||||
return;
|
||||
}
|
||||
// Can't get the resultsForAllVersions if there are still some queued
|
||||
var incompleteCount = 0;
|
||||
for (var index = this.state.queue.length; --index >= 0;){
|
||||
for (var index = this.state.queue.length; --index >= 0;) {
|
||||
if (this.state.queue[index].completed) {
|
||||
continue;
|
||||
}
|
||||
if (this.state.queue[index].test === queueItem.test) {
|
||||
return;
|
||||
}
|
||||
incompleteCount ++;
|
||||
incompleteCount++;
|
||||
}
|
||||
var resultsForAllVersions = Object.keys(this.state.results)
|
||||
.filter(function(key){return key.indexOf(queueItem.test) === 0;})
|
||||
.map(function(key){return this.state.results[key];}, this)
|
||||
;
|
||||
.filter(function(key) {
|
||||
return key.indexOf(queueItem.test) === 0;
|
||||
})
|
||||
.map(function(key) {
|
||||
return this.state.results[key];
|
||||
}, this);
|
||||
this.props.onCompleteEach(resultsForAllVersions);
|
||||
|
||||
|
||||
if (this.props.onComplete && incompleteCount === 0) {
|
||||
this.props.onComplete(this.state.results);
|
||||
}
|
||||
},
|
||||
|
||||
render: function(){
|
||||
render: function() {
|
||||
var grid = null;
|
||||
|
||||
if (!this.props.headless) {
|
||||
@@ -84,31 +87,38 @@ var BrowserPerfRunnerApp = React.createClass({
|
||||
}
|
||||
});
|
||||
|
||||
BrowserPerfRunnerApp.renderBenchmarkCell = function(props, row, col){
|
||||
if (col == null && row == null) return React.DOM.th(null);
|
||||
if (row == null) return React.DOM.th({style:{verticalAlign:'top', textAlign:'center'}}, col);
|
||||
BrowserPerfRunnerApp.renderBenchmarkCell = function(props, row, col) {
|
||||
if (col == null && row == null) {
|
||||
return React.DOM.th(null);
|
||||
}
|
||||
if (row == null) {
|
||||
return React.DOM.th({style:{verticalAlign:'top', textAlign:'center'}}, col);
|
||||
}
|
||||
|
||||
var benchmarks = Object.keys(props.value)
|
||||
.filter(function(key){
|
||||
.filter(function(key) {
|
||||
return key.indexOf(row) === 0;
|
||||
})
|
||||
.map(function(key){
|
||||
.map(function(key) {
|
||||
return props.value[key];
|
||||
})
|
||||
.filter(function(benchmark){
|
||||
.filter(function(benchmark) {
|
||||
return benchmark && !benchmark.isRunning && benchmark.stats;
|
||||
})
|
||||
;
|
||||
|
||||
if (col == null) return React.DOM.th({style:{verticalAlign:'top', textAlign:'right'}},
|
||||
React.DOM.a({href:'?test=' + row}, benchmarks[0] && benchmarks[0].name || row)
|
||||
);
|
||||
});
|
||||
|
||||
if (col == null) {
|
||||
return React.DOM.th({style:{verticalAlign:'top', textAlign:'right'}},
|
||||
React.DOM.a({href:'?test=' + row}, benchmarks[0] && benchmarks[0].name || row)
|
||||
);
|
||||
}
|
||||
|
||||
var key = row + '@' + col;
|
||||
var benchmark = props.value[key];
|
||||
if (!(benchmark && benchmark.stats)) return React.DOM.td({key:key});
|
||||
|
||||
|
||||
if (!(benchmark && benchmark.stats)) {
|
||||
return React.DOM.td({key:key});
|
||||
}
|
||||
|
||||
|
||||
var colors = [
|
||||
'000000',
|
||||
'AA0000',
|
||||
@@ -129,21 +139,25 @@ BrowserPerfRunnerApp.renderBenchmarkCell = function(props, row, col){
|
||||
'FFFFFF'
|
||||
];
|
||||
|
||||
function chartValue(value){
|
||||
function chartValue(value) {
|
||||
return Math.round(valueFromRangeToRange(value, chartValue.min, chartValue.max, 0, 100));
|
||||
}
|
||||
chartValue.min = Math.min.apply(Math, benchmarks.map(function(benchmark){return Math.min.apply(Math, benchmark.stats.sample);}));
|
||||
chartValue.max = Math.max.apply(Math, benchmarks.map(function(benchmark){return Math.max.apply(Math, benchmark.stats.sample);}));
|
||||
chartValue.min = Math.min.apply(Math, benchmarks.map(function(benchmark) {
|
||||
return Math.min.apply(Math, benchmark.stats.sample);
|
||||
}));
|
||||
chartValue.max = Math.max.apply(Math, benchmarks.map(function(benchmark) {
|
||||
return Math.max.apply(Math, benchmark.stats.sample);
|
||||
}));
|
||||
|
||||
var means = benchmarks.map(function(benchmark){
|
||||
var means = benchmarks.map(function(benchmark) {
|
||||
return benchmark.stats.mean;
|
||||
});
|
||||
benchmarks.forEach(function(benchmark){
|
||||
benchmarks.forEach(function(benchmark) {
|
||||
benchmark.isTheWinner = benchmark.stats.mean <= Math.min.apply(Math, means);
|
||||
});
|
||||
|
||||
var chartValues = benchmarks.map(function(benchmark){
|
||||
// benchmark.stats.sample.sort(function(a,b){return b - a;});
|
||||
var chartValues = benchmarks.map(function(benchmark) {
|
||||
// benchmark.stats.sample.sort(function(a,b) {return b - a;});
|
||||
return benchmark.stats.sample.map(chartValue).join(',');
|
||||
}).join('|');
|
||||
|
||||
@@ -151,9 +165,9 @@ BrowserPerfRunnerApp.renderBenchmarkCell = function(props, row, col){
|
||||
React.DOM.td({key:key, style:{textAlign:'center', width:234, verticalAlign:'top'}},
|
||||
benchmark.error && benchmark.error.message || '',
|
||||
React.DOM.div({style: benchmark.isTheWinner ? { backgroundColor:'#0A5', color:'#AFA' } : {backgroundColor:'transparent', color:'inherit'}},
|
||||
Math.round(1 / benchmark.stats.mean * 100) / 100, " op/s ",
|
||||
React.DOM.strong(null, Math.round(benchmark.stats.mean * 1000 * 100) / 100, " ms/op "),
|
||||
React.DOM.small(null, "(±" + (Math.round(benchmark.stats.rme * 10) / 10) + "%)")
|
||||
Math.round(1 / benchmark.stats.mean * 100) / 100, ' op/s ',
|
||||
React.DOM.strong(null, Math.round(benchmark.stats.mean * 1000 * 100) / 100, ' ms/op '),
|
||||
React.DOM.small(null, '(±' + (Math.round(benchmark.stats.rme * 10) / 10) + '%)')
|
||||
),
|
||||
benchmark.isRunning && 'Running' || React.DOM.img({
|
||||
style: {
|
||||
@@ -167,9 +181,9 @@ BrowserPerfRunnerApp.renderBenchmarkCell = function(props, row, col){
|
||||
})
|
||||
)
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
function valueFromRangeToRange(value, fromMin, fromMax, toMin, toMax){
|
||||
function valueFromRangeToRange(value, fromMin, fromMax, toMin, toMax) {
|
||||
var fromRange = fromMax - fromMin;
|
||||
var toRange = toMax - toMin;
|
||||
return (((value - fromMin) * toRange) / fromRange) + toMin;
|
||||
@@ -183,11 +197,11 @@ var GridViewTable = React.createClass({
|
||||
renderCell: React.PropTypes.func.isRequired
|
||||
},
|
||||
|
||||
_renderCell: function(col){
|
||||
_renderCell: function(col) {
|
||||
return this.props.renderCell({ value:this.props.value }, this._row, col);
|
||||
},
|
||||
|
||||
_renderRow: function(row){
|
||||
_renderRow: function(row) {
|
||||
this._row = row;
|
||||
return React.DOM.tr({key:row},
|
||||
this._renderCell(null, 0),
|
||||
@@ -195,7 +209,7 @@ var GridViewTable = React.createClass({
|
||||
);
|
||||
},
|
||||
|
||||
render: function(){
|
||||
render: function() {
|
||||
return React.DOM.table(null,
|
||||
this._renderRow(null, 0),
|
||||
this.props.rows.map(this._renderRow, this)
|
||||
|
||||
@@ -8,25 +8,25 @@ var BenchmarkQueue = React.createClass({
|
||||
onError: React.PropTypes.func
|
||||
},
|
||||
|
||||
getDefaultProps: function(){
|
||||
getDefaultProps: function() {
|
||||
return {
|
||||
maxTime: 5
|
||||
};
|
||||
},
|
||||
|
||||
getInitialState: function(){
|
||||
getInitialState: function() {
|
||||
return {
|
||||
queue: this.props.initialQueue.slice()
|
||||
};
|
||||
},
|
||||
|
||||
setItemState: function(state){
|
||||
setItemState: function(state) {
|
||||
state.test = this.state.queue[0].test;
|
||||
state.react = this.state.queue[0].react;
|
||||
this.props.onChange(state);
|
||||
},
|
||||
|
||||
handleContextReady: function(window){
|
||||
handleContextReady: function(window) {
|
||||
var benchmark = window.Benchmark(window.exports);
|
||||
benchmark.options.maxTime = this.props.maxTime; //DEBUG
|
||||
|
||||
@@ -37,7 +37,7 @@ var BenchmarkQueue = React.createClass({
|
||||
platform: window.Benchmark.platform.description,
|
||||
reactVersion: window.React.version,
|
||||
|
||||
isMinified: (function(){
|
||||
isMinified: (function() {
|
||||
var code = window.React.render.toString();
|
||||
return code.indexOf(',') - code.indexOf('(') <= 2;
|
||||
}())
|
||||
@@ -46,7 +46,7 @@ var BenchmarkQueue = React.createClass({
|
||||
this.setItemState(itemState);
|
||||
|
||||
var self = this;
|
||||
benchmark.on('start error cycle complete', function(){
|
||||
benchmark.on('start error cycle complete', function() {
|
||||
var stats = JSON.parse(JSON.stringify(benchmark.stats));
|
||||
itemState.stats = stats;
|
||||
itemState.isRunning = benchmark.running;
|
||||
@@ -56,7 +56,7 @@ var BenchmarkQueue = React.createClass({
|
||||
if (this.props.onError) {
|
||||
benchmark.on('error', this.props.onError);
|
||||
}
|
||||
benchmark.on('complete', function(){
|
||||
benchmark.on('complete', function() {
|
||||
var queue = self.state.queue.slice();
|
||||
var queueItem = queue.shift();
|
||||
if (self.props.onCompleteEach) {
|
||||
@@ -67,12 +67,12 @@ var BenchmarkQueue = React.createClass({
|
||||
benchmark.run({async:true});
|
||||
},
|
||||
|
||||
shouldComponentUpdate: function(nextProps, nextState){
|
||||
shouldComponentUpdate: function(nextProps, nextState) {
|
||||
return nextState.queue.length < this.state.queue.length;
|
||||
},
|
||||
|
||||
render: function(){
|
||||
if (!(this.state.queue && this.state.queue.length > 0)){
|
||||
render: function() {
|
||||
if (!(this.state.queue && this.state.queue.length > 0)) {
|
||||
return React.DOM.div({style:{display:'none'}});
|
||||
}
|
||||
return BrowserPerfRunnerContext({
|
||||
@@ -88,61 +88,67 @@ var BrowserPerfRunnerContext = React.createClass({
|
||||
|
||||
propTypes: {
|
||||
debug: React.PropTypes.bool,
|
||||
test: function(object, key){
|
||||
test: function(object, key) {
|
||||
React.PropTypes.string.isRequired(object, key);
|
||||
if (/\.jsx?$/i.test(object[key])) return;
|
||||
if (/\.jsx?$/i.test(object[key])) {
|
||||
return;
|
||||
}
|
||||
throw Error('Expected `' + key + '` to be a test file name with extension `.js` or `.jsx`');
|
||||
},
|
||||
react: function(object, key){
|
||||
react: function(object, key) {
|
||||
React.PropTypes.string.isRequired(object, key);
|
||||
if (/^(?:builds\/.+|edge|previous|(?:\d+\.){2}\d+)$/.test(object[key])) return;
|
||||
throw Error('Expected `' + key + '` prop to be a valid react version string, build string or "edge" or "previous"');
|
||||
if (/^(?:builds\/.+|edge|previous|(?:\d+\.){2}\d+)$/.test(object[key])) {
|
||||
return;
|
||||
}
|
||||
throw Error('Expected `' + key + '` prop to be a valid react version string, build string or \'edge\' or \'previous\'');
|
||||
},
|
||||
onReady: React.PropTypes.func.isRequired
|
||||
},
|
||||
|
||||
getInitialState: function(){
|
||||
getInitialState: function() {
|
||||
return {
|
||||
testRunnerURL:'about:blank'
|
||||
};
|
||||
},
|
||||
|
||||
// _handleFrameError: function(error){
|
||||
// _handleFrameError: function(error) {
|
||||
// console.error('BrowserPerfRunnerContext', error);
|
||||
// },
|
||||
//
|
||||
// _handleFrameLoad: function(event){
|
||||
// _handleFrameLoad: function(event) {
|
||||
// console.log('BrowserPerfRunnerContext', event);
|
||||
// },
|
||||
//
|
||||
_handleMessage: function(event){
|
||||
if (location.href.indexOf(event.origin) !== 0)
|
||||
_handleMessage: function(event) {
|
||||
if (location.href.indexOf(event.origin) !== 0) {
|
||||
return console.debug('BrowserPerfRunnerContext#_handleMessage ignored message from ' + event.origin);
|
||||
if (event.source.location.href.indexOf(this.state.testRunnerURL) === -1)
|
||||
}
|
||||
if (event.source.location.href.indexOf(this.state.testRunnerURL) === -1) {
|
||||
return console.debug('BrowserPerfRunnerContext#_handleMessage ignored message from ' + event.source.location.href);
|
||||
if (event.data !== 'Ready!')
|
||||
}
|
||||
if (event.data !== 'Ready!') {
|
||||
return console.debug('BrowserPerfRunnerContext#_handleMessage ignored message ' + JSON.stringify(event.data));
|
||||
|
||||
}
|
||||
this.props.onReady(event.source);
|
||||
},
|
||||
|
||||
_getTestRunnerURL: function(props){
|
||||
_getTestRunnerURL: function(props) {
|
||||
return 'runner.html' +
|
||||
'?' +
|
||||
'debug=' + (props.debug ? 1 : 0) +
|
||||
'&' +
|
||||
'react=' + encodeURIComponent(props.react) +
|
||||
'&' +
|
||||
'test=' + encodeURIComponent(props.test)
|
||||
'test=' + encodeURIComponent(props.test);
|
||||
},
|
||||
|
||||
_renderState: function(props){
|
||||
_renderState: function(props) {
|
||||
return {
|
||||
testRunnerURL: this._getTestRunnerURL(props)
|
||||
};
|
||||
},
|
||||
|
||||
componentDidMount: function(){
|
||||
componentDidMount: function() {
|
||||
var node = this.refs.iframe.getDOMNode();
|
||||
// node.onload = this._handleFrameLoad;
|
||||
// node.onerror = this._handleFrameError;
|
||||
@@ -156,7 +162,7 @@ var BrowserPerfRunnerContext = React.createClass({
|
||||
this.setState(this._renderState(this.props));
|
||||
},
|
||||
|
||||
componentWillUnmount: function(){
|
||||
componentWillUnmount: function() {
|
||||
if (window.removeEventListener) {
|
||||
window.removeEventListener('message', this._handleMessage);
|
||||
} else if (window.detachEvent) {
|
||||
@@ -167,19 +173,19 @@ var BrowserPerfRunnerContext = React.createClass({
|
||||
this.refs.iframe.getDOMNode().src = '';
|
||||
},
|
||||
|
||||
componentWillReceiveProps: function(nextProps){
|
||||
componentWillReceiveProps: function(nextProps) {
|
||||
this.setState(this._renderState(nextProps));
|
||||
},
|
||||
|
||||
shouldComponentUpdate: function(nextProps, nextState){
|
||||
return nextState.testRunnerURL != this.state.testRunnerURL;
|
||||
shouldComponentUpdate: function(nextProps, nextState) {
|
||||
return nextState.testRunnerURL !== this.state.testRunnerURL;
|
||||
},
|
||||
|
||||
render: function(){
|
||||
render: function() {
|
||||
return (
|
||||
React.DOM.iframe({
|
||||
ref: 'iframe',
|
||||
name: "BrowserPerfRunnerContextFrame",
|
||||
name: 'BrowserPerfRunnerContextFrame',
|
||||
style: this.style,
|
||||
src: this.state.testRunnerURL
|
||||
})
|
||||
|
||||
@@ -1,38 +1,44 @@
|
||||
if (typeof console == 'undefined') console = {
|
||||
log: function(){},
|
||||
warn: function(){},
|
||||
error: function(){},
|
||||
debug: function(){}
|
||||
};
|
||||
if (typeof console === 'undefined') {
|
||||
console = {
|
||||
log: function() {},
|
||||
warn: function() {},
|
||||
error: function() {},
|
||||
debug: function() {}
|
||||
};
|
||||
}
|
||||
|
||||
var perfRunner;
|
||||
if (typeof exports == 'object') {
|
||||
if (typeof exports === 'object') {
|
||||
perfRunner = exports;
|
||||
} else {
|
||||
perfRunner = {};
|
||||
}
|
||||
|
||||
perfRunner.assert = function(test, message){
|
||||
if (typeof test == 'function') test = test();
|
||||
if (test) return;
|
||||
perfRunner.assert = function(test, message) {
|
||||
if (typeof test === 'function') {
|
||||
test = test();
|
||||
}
|
||||
if (test) {
|
||||
return;
|
||||
}
|
||||
throw Error(message);
|
||||
}
|
||||
};
|
||||
|
||||
perfRunner.WriteScript = function(props){
|
||||
perfRunner.WriteScript = function(props) {
|
||||
var type = '';
|
||||
if (props.jsx) {
|
||||
type = ' type="text/jsx"';
|
||||
type = ' type=\'text/jsx\'';
|
||||
}
|
||||
var src = props.src;
|
||||
if (!props.cache) {
|
||||
src += src.indexOf('?') === -1 ? '?_' : '&_';
|
||||
src += perfRunner.WriteScript.cacheBust;
|
||||
}
|
||||
document.write('<script' + type + ' src="' + src + '"><\/script>');
|
||||
}
|
||||
perfRunner.WriteScript.cacheBust = (+new Date).toString(36);
|
||||
document.write('<script' + type + ' src=\'' + src + '\'><\/script>');
|
||||
};
|
||||
perfRunner.WriteScript.cacheBust = (+new Date()).toString(36);
|
||||
|
||||
perfRunner.WriteReactLibScript = function(params){
|
||||
perfRunner.WriteReactLibScript = function(params) {
|
||||
var src;
|
||||
var minSuffix;
|
||||
if (params.debug) {
|
||||
@@ -40,14 +46,16 @@ perfRunner.WriteReactLibScript = function(params){
|
||||
} else {
|
||||
minSuffix = '.min';
|
||||
}
|
||||
|
||||
if (params.version && typeof params.version != 'string') throw TypeError("Expected 'version' to be a string");
|
||||
|
||||
if (params.version == 'edge' || !params.version) {
|
||||
|
||||
if (params.version && typeof params.version !== 'string') {
|
||||
throw TypeError('Expected \'version\' to be a string');
|
||||
}
|
||||
|
||||
if (params.version === 'edge' || !params.version) {
|
||||
console.log('React edge (local)');
|
||||
perfRunner.WriteScript({src:'../build/react' + minSuffix + '.js'});
|
||||
perfRunner.WriteScript({src:'../build/JSXTransformer.js'});
|
||||
} else if (params.version == 'previous') {
|
||||
} else if (params.version === 'previous') {
|
||||
console.log('React previous (local)');
|
||||
perfRunner.WriteScript({cache:true, src:'../build/react-previous' + minSuffix + '.js'});
|
||||
perfRunner.WriteScript({cache:true, src:'../build/JSXTransformer-previous.js'});
|
||||
@@ -61,113 +69,123 @@ perfRunner.WriteReactLibScript = function(params){
|
||||
}
|
||||
if (params.debug) {
|
||||
console.warn('Loading the unminified build of React, performance may suffer.');
|
||||
console.warn('Load "' + location.href.replace(/\bdebug=\w+&?|&\bdebug=\w+/ig, '') + '" for better perf.');
|
||||
console.warn('Load \'' + location.href.replace(/\bdebug=\w+&?|&\bdebug=\w+/ig, '') + '\' for better perf.');
|
||||
} else {
|
||||
console.warn('Loading the minified build of React, debugging may be harder.');
|
||||
console.warn('Load "' + location.href.replace(/\bdebug=\w+&?|&\bdebug=\w+/ig, '') + '&debug=1' + '" for easier debugging.');
|
||||
console.warn('Load \'' + location.href.replace(/\bdebug=\w+&?|&\bdebug=\w+/ig, '') + '&debug=1' + '\' for easier debugging.');
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
perfRunner.WriteTestScript = function(params){
|
||||
perfRunner.WriteTestScript = function(params) {
|
||||
if (Array.isArray(params.test)) {
|
||||
return params.test
|
||||
.map(function(test){return {test:test};})
|
||||
.map(perfRunner.WriteTestScript)
|
||||
;
|
||||
.map(function(test) {
|
||||
return {
|
||||
test:test
|
||||
};
|
||||
})
|
||||
.map(perfRunner.WriteTestScript);
|
||||
}
|
||||
perfRunner.assert(params.test.indexOf('..') === -1, 'no relative paths allowed');
|
||||
return perfRunner.WriteScript({jsx:true, src: './tests/' + params.test});
|
||||
}
|
||||
};
|
||||
|
||||
perfRunner.getQueryParamArray = function(key){
|
||||
perfRunner.getQueryParamArray = function(key) {
|
||||
var values;
|
||||
var queryString = location.search.substr(1);
|
||||
var _key = encodeURIComponent(key) + '=';
|
||||
|
||||
|
||||
if (queryString.indexOf(_key) > -1) {
|
||||
values = queryString
|
||||
.split(_key)
|
||||
.slice(1)
|
||||
.map(function(part){return part.split('&')[0];})
|
||||
.map(function(part) {
|
||||
return part.split('&')[0];
|
||||
})
|
||||
.map(decodeURIComponent)
|
||||
.map(function(string){
|
||||
.map(function(string) {
|
||||
try {
|
||||
return JSON.parse(string);
|
||||
} catch(e){}
|
||||
} catch(e) {}
|
||||
return string;
|
||||
})
|
||||
;
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
perfRunner.assert(values && values.length && values[0], 'expected ' + key + ' query param');
|
||||
return values;
|
||||
}
|
||||
};
|
||||
|
||||
perfRunner.getQueryParamArrayOrDefault = function(key, defaultValue){
|
||||
perfRunner.getQueryParamArrayOrDefault = function(key, defaultValue) {
|
||||
try {
|
||||
return perfRunner.getQueryParamArray(key);
|
||||
} catch (e) {}
|
||||
return defaultValue;
|
||||
}
|
||||
};
|
||||
|
||||
perfRunner.Polyfill = function(){
|
||||
if (typeof Function.prototype.bind != 'undefined') return;
|
||||
perfRunner.Polyfill = function() {
|
||||
if (typeof Function.prototype.bind !== 'undefined') {
|
||||
return;
|
||||
}
|
||||
perfRunner.WriteScript({src:'/node_modules/es5-shim/es5-shim.js', cache:true});
|
||||
perfRunner.WriteScript({src:'/node_modules/es5-shim/es5-sham.js', cache:true});
|
||||
}
|
||||
};
|
||||
|
||||
perfRunner.BenchmarkResults = function(props){
|
||||
return perfRunner.roundNumberWithPrecision(props.stats.mean * 1000) + 'ms/op'
|
||||
}
|
||||
perfRunner.BenchmarkResults = function(props) {
|
||||
return perfRunner.roundNumberWithPrecision(props.stats.mean * 1000) + 'ms/op';
|
||||
};
|
||||
|
||||
perfRunner.roundNumberWithPrecision = function(number, precision){
|
||||
if (!precision) precision = 1000;
|
||||
perfRunner.roundNumberWithPrecision = function(number, precision) {
|
||||
if (!precision) {
|
||||
precision = 1000;
|
||||
}
|
||||
return Math.round(number * precision) / precision;
|
||||
}
|
||||
};
|
||||
|
||||
perfRunner.quickBench = function(benchmarkOptions, onComplete, onBeforeStart){
|
||||
perfRunner.quickBench = function(benchmarkOptions, onComplete, onBeforeStart) {
|
||||
var bench = new Benchmark(benchmarkOptions);
|
||||
if (onBeforeStart) onBeforeStart(null, bench);
|
||||
if (onBeforeStart) {
|
||||
onBeforeStart(null, bench);
|
||||
}
|
||||
|
||||
bench.on('error', function(event){
|
||||
bench.on('error', function(event) {
|
||||
console.error(event.message);
|
||||
console.log(event.target.compiled.toString());
|
||||
onComplete(Error(event.error));
|
||||
});
|
||||
|
||||
bench.on('start', function(){
|
||||
bench.on('start', function() {
|
||||
console.log('starting', bench.name);
|
||||
});
|
||||
|
||||
bench.on('cycle', function(){
|
||||
var bench = this,
|
||||
size = bench.stats.size;
|
||||
|
||||
if (!bench.aborted) {
|
||||
console.warn(bench.name + ' × ' + bench.count +
|
||||
' (' + bench.stats.sample.length + ' samples)' +
|
||||
' (' + Math.round(1 / bench.stats.mean) + ' ops/sec' + ')' +
|
||||
' (' + (bench.stats.mean * 1000) + ' ms/op' + ')' +
|
||||
' (±' + bench.stats.rme.toFixed(2) + '%)' +
|
||||
bench.on('cycle', function() {
|
||||
var benchmark = this,
|
||||
size = benchmark.stats.size;
|
||||
|
||||
if (!benchmark.aborted) {
|
||||
console.warn(benchmark.name + ' × ' + benchmark.count +
|
||||
' (' + benchmark.stats.sample.length + ' samples)' +
|
||||
' (' + Math.round(1 / benchmark.stats.mean) + ' ops/sec' + ')' +
|
||||
' (' + (benchmark.stats.mean * 1000) + ' ms/op' + ')' +
|
||||
' (±' + benchmark.stats.rme.toFixed(2) + '%)' +
|
||||
' with ' + React.version
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
bench.on('complete', function(){
|
||||
bench.on('complete', function() {
|
||||
var results = {
|
||||
platform: Benchmark.platform.description,
|
||||
react: React.version,
|
||||
name: bench.name,
|
||||
name: bench.name
|
||||
// times: bench.times,
|
||||
// stats: bench.stats
|
||||
};
|
||||
|
||||
results['s/op'] = bench.stats.mean
|
||||
results['ms/op'] = results['s/op'] * 1000
|
||||
results['op/s'] = 1 / results['s/op']
|
||||
results["% frame 60"] = results['ms/op'] / (1000 / 60) * 100
|
||||
|
||||
|
||||
results['s/op'] = bench.stats.mean;
|
||||
results['ms/op'] = results['s/op'] * 1000;
|
||||
results['op/s'] = 1 / results['s/op'];
|
||||
results['% frame 60'] = results['ms/op'] / (1000 / 60) * 100;
|
||||
|
||||
console.log(results);
|
||||
onComplete(null, results);
|
||||
});
|
||||
@@ -175,9 +193,9 @@ perfRunner.quickBench = function(benchmarkOptions, onComplete, onBeforeStart){
|
||||
bench.run();
|
||||
};
|
||||
|
||||
perfRunner.singleTest = function(benchmarkOptions, onComplete){
|
||||
perfRunner.singleTest = function(benchmarkOptions, onComplete) {
|
||||
var bench = Benchmark(exports);
|
||||
bench.on('complete', function(){
|
||||
bench.on('complete', function() {
|
||||
var results = {
|
||||
platform: Benchmark.platform.description,
|
||||
react: React.version,
|
||||
@@ -187,18 +205,20 @@ perfRunner.singleTest = function(benchmarkOptions, onComplete){
|
||||
onComplete(results);
|
||||
});
|
||||
bench.run();
|
||||
}
|
||||
};
|
||||
|
||||
perfRunner.ViewObject = function(props){
|
||||
perfRunner.ViewObject = function(props) {
|
||||
var value = props.value;
|
||||
delete props.value;
|
||||
|
||||
if (typeof value != 'object') return React.DOM.span(props, [JSON.stringify(value), " ", typeof value]);
|
||||
|
||||
return React.DOM.table(props, Object.keys(value).map(function(key){
|
||||
|
||||
if (typeof value !== 'object') {
|
||||
return React.DOM.span(props, [JSON.stringify(value), ' ', typeof value]);
|
||||
}
|
||||
|
||||
return React.DOM.table(props, Object.keys(value).map(function(key) {
|
||||
return React.DOM.tr(null,
|
||||
React.DOM.th(null, key),
|
||||
React.DOM.td(null, perfRunner.ViewObject({key:key, value:value[key]}))
|
||||
);
|
||||
}));
|
||||
}
|
||||
};
|
||||
@@ -1,4 +1,4 @@
|
||||
/*global*/todolist = {};
|
||||
todolist = {};
|
||||
|
||||
todolist.ID = Date.now();
|
||||
|
||||
@@ -9,11 +9,15 @@ todolist.App = React.createClass({
|
||||
fakeDataCount: React.PropTypes.number
|
||||
},
|
||||
|
||||
getInitialState: function(){
|
||||
getInitialState: function() {
|
||||
var todos;
|
||||
if (this.props.fakeDataCount) {
|
||||
todos = Array(this.props.fakeDataCount + 1).join(',').split(',').map(function(ignore, index){
|
||||
return {id:index, title:"Title " + index + " " + Math.random().toString(36).substring(2,16), completed:!!(index % 2)};
|
||||
todos = Array(this.props.fakeDataCount + 1).join(',').split(',').map(function(ignore, index) {
|
||||
return {
|
||||
id: index,
|
||||
title: 'Title ' + index + ' ' + Math.random().toString(36).substring(2, 16),
|
||||
completed: !!(index % 2)
|
||||
};
|
||||
});
|
||||
}
|
||||
return {
|
||||
@@ -23,15 +27,17 @@ todolist.App = React.createClass({
|
||||
todos: todos || this.props.initialData || []
|
||||
};
|
||||
},
|
||||
componentWillUpdate: function(props, state){
|
||||
state.todos = state.todos.filter(function(todo){
|
||||
componentWillUpdate: function(props, state) {
|
||||
state.todos = state.todos.filter(function(todo) {
|
||||
return !todo.deleted;
|
||||
});
|
||||
},
|
||||
addItem: function(title, callback){
|
||||
addItem: function(title, callback) {
|
||||
if (title == null || title === '') {
|
||||
var error = Error('invalid title');
|
||||
if (!callback) throw error;
|
||||
if (!callback) {
|
||||
throw error;
|
||||
}
|
||||
return callback(error);
|
||||
}
|
||||
var todos = this.state.todos.slice();
|
||||
@@ -41,82 +47,98 @@ todolist.App = React.createClass({
|
||||
completed: false
|
||||
};
|
||||
todos.push(todo);
|
||||
if (callback) callback = callback.bind(this, todo);
|
||||
if (callback) {
|
||||
callback = callback.bind(this, todo);
|
||||
}
|
||||
this.setState({ timerEvent:'addItem', timerStart:todolist.now(), timerEnd:null, todos:todos }, callback);
|
||||
return todo;
|
||||
},
|
||||
deleteItemById: function(id, callback){
|
||||
deleteItemById: function(id, callback) {
|
||||
var todo = this._getById(id);
|
||||
if (!todo) return callback && callback(Error('todo with id ' + id + ' not found'));
|
||||
if (!todo) {
|
||||
return callback && callback(Error('todo with id ' + id + ' not found'));
|
||||
}
|
||||
todo.deleted = true;
|
||||
this.setState({ timerEvent:'deleteItemById', timerStart:todolist.now(), timerEnd:null, todos:this.state.todos }, callback);
|
||||
},
|
||||
setItemCompleted: function(id, completed, callback){
|
||||
setItemCompleted: function(id, completed, callback) {
|
||||
var todo = this._getById(id);
|
||||
if (!todo) return callback && callback(Error('todo with id ' + id + ' not found'));
|
||||
if (!todo) {
|
||||
return callback && callback(Error('todo with id ' + id + ' not found'));
|
||||
}
|
||||
todo.completed = completed;
|
||||
this.setState({ timerEvent:'setItemCompleted', timerStart:todolist.now(), timerEnd:null, todos:this.state.todos }, callback);
|
||||
},
|
||||
_getById: function(id){
|
||||
_getById: function(id) {
|
||||
id = +id;
|
||||
var todos = this.state.todos;
|
||||
for (var index = todos.length; --index >= 0;){
|
||||
if (todos[index].id === id) return todos[index];
|
||||
for (var index = todos.length; --index >= 0;) {
|
||||
if (todos[index].id === id) {
|
||||
return todos[index];
|
||||
}
|
||||
}
|
||||
return null;
|
||||
},
|
||||
_handleItemCompletedCheckboxChange: function(event){
|
||||
_handleItemCompletedCheckboxChange: function(event) {
|
||||
var node = event.target;
|
||||
this.setItemCompleted(node.value, node.checked);
|
||||
},
|
||||
_handleItemDeletedButton: function(event){
|
||||
_handleItemDeletedButton: function(event) {
|
||||
var node = event.target;
|
||||
this.deleteItemById(node.value);
|
||||
},
|
||||
_renderTodoItem: function(todo, index){
|
||||
_renderTodoItem: function(todo, index) {
|
||||
return (
|
||||
React.DOM.li({key:todo.id},
|
||||
React.DOM.button({value:todo.id, onClick:this._handleItemDeletedButton}, 'x'),
|
||||
React.DOM.input({type:"checkbox", value:todo.id, checked:todo.completed, onChange:this._handleItemCompletedCheckboxChange}),
|
||||
" ",
|
||||
React.DOM.span({style:{"text-decoration":todo.completed ? "line-through" : ""}}, todo.title)
|
||||
React.DOM.input({type:'checkbox', value:todo.id, checked:todo.completed, onChange:this._handleItemCompletedCheckboxChange}),
|
||||
' ',
|
||||
React.DOM.span({style:{'text-decoration':todo.completed ? 'line-through' : ''}}, todo.title)
|
||||
)
|
||||
);
|
||||
},
|
||||
render: function(){
|
||||
if (!this.state.timerEnd) this.state.timerEnd = todolist.now();
|
||||
if (this.props.onRender) this.props.onRender();
|
||||
render: function() {
|
||||
if (!this.state.timerEnd) {
|
||||
this.state.timerEnd = todolist.now();
|
||||
}
|
||||
if (this.props.onRender) {
|
||||
this.props.onRender();
|
||||
}
|
||||
return (
|
||||
React.DOM.div(null,
|
||||
React.DOM.h1(null, "TODO"),
|
||||
React.DOM.h3(null, this.state.timerEvent, " ", this.state.timerEnd - this.state.timerStart, 'ms'),
|
||||
React.DOM.h1(null, 'TODO'),
|
||||
React.DOM.h3(null, this.state.timerEvent, ' ', this.state.timerEnd - this.state.timerStart, 'ms'),
|
||||
todolist.NewItemForm({onEnter:this.addItem, autoFocus:true}),
|
||||
React.DOM.ol(null, this.state.todos.map(this._renderTodoItem))
|
||||
)
|
||||
);
|
||||
},
|
||||
componentDidMount: function(rootNode){
|
||||
if (this.props.onDidMount) this.props.onDidMount(rootNode);
|
||||
componentDidMount: function(rootNode) {
|
||||
if (this.props.onDidMount) {
|
||||
this.props.onDidMount(rootNode);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
todolist.NewItemForm = React.createClass({
|
||||
_handleNewItemKeyDown: function(event){
|
||||
if (event.which !== 13/*enter key*/) return;
|
||||
_handleNewItemKeyDown: function(event) {
|
||||
if (event.which !== 13/*enter key*/) {
|
||||
return;
|
||||
}
|
||||
var node = this.refs.text.getDOMNode();
|
||||
var value = node.value;
|
||||
node.value = '';
|
||||
this.props.onEnter(value);
|
||||
return false;
|
||||
},
|
||||
render: function(){
|
||||
render: function() {
|
||||
var props = {};
|
||||
for (var key in this.props) {
|
||||
if (key !== "onEnter") {
|
||||
if (key !== 'onEnter') {
|
||||
props[key] = this.props[key];
|
||||
}
|
||||
}
|
||||
props.ref = "text";
|
||||
props.ref = 'text';
|
||||
props.onKeyDown = this.props.onEnter && this._handleNewItemKeyDown;
|
||||
return React.DOM.input(props);
|
||||
}
|
||||
|
||||
@@ -1,16 +1,11 @@
|
||||
/* jshint undef: true, unused: true */
|
||||
|
||||
/* global document */
|
||||
/* global window */
|
||||
/* global Benchmark */
|
||||
/* global React */
|
||||
|
||||
if (typeof exports == 'undefined') exports = {};
|
||||
if (typeof exports === 'undefined') {
|
||||
exports = {};
|
||||
}
|
||||
|
||||
/*http://benchmarkjs.com/docs#options*/
|
||||
|
||||
exports.name = 'React.DOM.div, no props';
|
||||
|
||||
exports.fn = function(){
|
||||
exports.fn = function() {
|
||||
React.DOM.div(null, 'lol, perf testing ', this.count);
|
||||
};
|
||||
+11
-13
@@ -1,23 +1,21 @@
|
||||
/* jshint undef: true, unused: true */
|
||||
|
||||
/* global document */
|
||||
/* global window */
|
||||
/* global Benchmark */
|
||||
/* global React */
|
||||
|
||||
if (typeof exports == 'undefined') exports = {};
|
||||
if (typeof exports === 'undefined') {
|
||||
exports = {};
|
||||
}
|
||||
|
||||
/*http://benchmarkjs.com/docs#options*/
|
||||
|
||||
exports.name = 'unmountComponentAtNode';
|
||||
|
||||
exports.setup = function(){
|
||||
/*global*/_rootNode = document.createElement('div');
|
||||
exports.setup = function() {
|
||||
_rootNode = document.createElement('div');
|
||||
document.body.appendChild(_rootNode);
|
||||
var _firstChild = React.DOM.div(null, 'lol, perf testing ', this.count);
|
||||
React.render(_firstChild, _rootNode);
|
||||
};
|
||||
exports.fn = function(){
|
||||
if (React.unmountAndReleaseReactRootNode) React.unmountAndReleaseReactRootNode(_rootNode);
|
||||
else React.unmountComponentAtNode(_rootNode);
|
||||
exports.fn = function() {
|
||||
if (React.unmountAndReleaseReactRootNode) {
|
||||
React.unmountAndReleaseReactRootNode(_rootNode);
|
||||
} else {
|
||||
React.unmountComponentAtNode(_rootNode);
|
||||
}
|
||||
};
|
||||
+16
-10
@@ -1,4 +1,6 @@
|
||||
if (typeof exports == 'undefined') exports = {};
|
||||
if (typeof exports === 'undefined') {
|
||||
exports = {};
|
||||
}
|
||||
|
||||
/*http://benchmarkjs.com/docs#options*/
|
||||
|
||||
@@ -10,7 +12,11 @@ var ListItem;
|
||||
var MyReactComponent;
|
||||
var _rootNode;
|
||||
|
||||
exports.setup = function(){
|
||||
function func() {
|
||||
return 'this is a function';
|
||||
}
|
||||
|
||||
exports.setup = function() {
|
||||
List = React.createClass({
|
||||
propTypes: {
|
||||
array: React.PropTypes.array,
|
||||
@@ -38,7 +44,7 @@ exports.setup = function(){
|
||||
instanceOf: React.PropTypes.instanceOf(Thing).isRequired,
|
||||
element: React.PropTypes.element.isRequired
|
||||
},
|
||||
render: function(){
|
||||
render: function() {
|
||||
return React.DOM.li(null,
|
||||
this.props.number + this.props.string + this.props.node
|
||||
);
|
||||
@@ -54,7 +60,7 @@ exports.setup = function(){
|
||||
_rootNode = document.createElement('div');
|
||||
document.body.appendChild(_rootNode);
|
||||
};
|
||||
exports.fn = function(){
|
||||
exports.fn = function() {
|
||||
var items = [];
|
||||
for (var i = 0; i < 1000; i++) {
|
||||
items.push(ListItem({
|
||||
@@ -62,24 +68,24 @@ exports.fn = function(){
|
||||
bool: false,
|
||||
number: Math.random(),
|
||||
string: 'banana banana banana',
|
||||
func: function() { return 'this is a function'; },
|
||||
func: func,
|
||||
node: 'renderable string',
|
||||
node2: [MyReactComponent(), 'a string'],
|
||||
instanceOf: new Thing,
|
||||
instanceOf: new Thing(),
|
||||
element: MyReactComponent()
|
||||
}));
|
||||
};
|
||||
}
|
||||
|
||||
React.render(List({
|
||||
array: [11, 12, 13, 14, 15, 16, 17, 18, 19, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
|
||||
bool: false,
|
||||
number: Math.random(),
|
||||
string: 'banana banana banana',
|
||||
func: function() { return 'this is a function'; },
|
||||
func: func,
|
||||
renderable: 'renderable string',
|
||||
instanceOf: new Thing
|
||||
instanceOf: new Thing()
|
||||
}, items), _rootNode);
|
||||
};
|
||||
exports.teardown = function(){
|
||||
exports.teardown = function() {
|
||||
React.unmountComponentAtNode(_rootNode);
|
||||
};
|
||||
@@ -1,24 +1,22 @@
|
||||
/* jshint undef: true, unused: true */
|
||||
|
||||
/* global document */
|
||||
/* global window */
|
||||
/* global Benchmark */
|
||||
/* global React */
|
||||
|
||||
if (typeof exports == 'undefined') exports = {};
|
||||
if (typeof exports === 'undefined') {
|
||||
exports = {};
|
||||
}
|
||||
|
||||
/*http://benchmarkjs.com/docs#options*/
|
||||
|
||||
exports.name = 'React.render single div';
|
||||
|
||||
exports.setup = function(){
|
||||
/*global*/_rootNode = document.createElement('div');
|
||||
exports.setup = function() {
|
||||
_rootNode = document.createElement('div');
|
||||
document.body.appendChild(_rootNode);
|
||||
};
|
||||
exports.fn = function(){
|
||||
exports.fn = function() {
|
||||
React.render(React.DOM.div(null, 'lol, perf testing ', this.count), _rootNode);
|
||||
};
|
||||
exports.teardown = function(){
|
||||
if (React.unmountAndReleaseReactRootNode) React.unmountAndReleaseReactRootNode(_rootNode);
|
||||
else React.unmountComponentAtNode(_rootNode);
|
||||
exports.teardown = function() {
|
||||
if (React.unmountAndReleaseReactRootNode) {
|
||||
React.unmountAndReleaseReactRootNode(_rootNode);
|
||||
} else {
|
||||
React.unmountComponentAtNode(_rootNode);
|
||||
}
|
||||
};
|
||||
@@ -1,15 +1,17 @@
|
||||
if (typeof exports == 'undefined') exports = {};
|
||||
if (typeof exports === 'undefined') {
|
||||
exports = {};
|
||||
}
|
||||
|
||||
/*http://benchmarkjs.com/docs#options*/
|
||||
|
||||
exports.name = 'Trivial benchmark to verify that everything works';
|
||||
|
||||
exports.setup = function(){
|
||||
exports.setup = function() {
|
||||
var foo;
|
||||
};
|
||||
exports.fn = function(){
|
||||
exports.fn = function() {
|
||||
foo = Array(999).join('Howdy!\n');
|
||||
};
|
||||
exports.teardown = function(){
|
||||
exports.teardown = function() {
|
||||
foo = null;
|
||||
};
|
||||
@@ -1,4 +1,6 @@
|
||||
if (typeof exports == 'undefined') exports = {};
|
||||
if (typeof exports === 'undefined') {
|
||||
exports = {};
|
||||
}
|
||||
|
||||
/*http://benchmarkjs.com/docs#options*/
|
||||
|
||||
@@ -6,29 +8,31 @@ exports.name = 'From setState to callback (x5)';
|
||||
|
||||
exports.defer = true;
|
||||
|
||||
exports.setup = function(){
|
||||
/*global*/_rootNode = document.createElement('div');
|
||||
exports.setup = function() {
|
||||
_rootNode = document.createElement('div');
|
||||
document.body.appendChild(_rootNode);
|
||||
/*global*/setState = null;
|
||||
setState = null;
|
||||
|
||||
var AwesomeComponent = React.createClass({
|
||||
getInitialState: function(){
|
||||
getInitialState: function() {
|
||||
return { random:null };
|
||||
},
|
||||
render: function(){
|
||||
if (!setState) setState = this.setState.bind(this);
|
||||
render: function() {
|
||||
if (!setState) {
|
||||
setState = this.setState.bind(this);
|
||||
}
|
||||
return React.DOM.div(null, this.state.random);
|
||||
}
|
||||
});
|
||||
|
||||
React.render(AwesomeComponent(null), _rootNode);
|
||||
};
|
||||
exports.fn = function(deferred){
|
||||
setState({random: Date.now() + Math.random()}, function(){
|
||||
setState({random: Date.now() + Math.random()}, function(){
|
||||
setState({random: Date.now() + Math.random()}, function(){
|
||||
setState({random: Date.now() + Math.random()}, function(){
|
||||
setState({random: Date.now() + Math.random()}, function(){
|
||||
exports.fn = function(deferred) {
|
||||
setState({random: Date.now() + Math.random()}, function() {
|
||||
setState({random: Date.now() + Math.random()}, function() {
|
||||
setState({random: Date.now() + Math.random()}, function() {
|
||||
setState({random: Date.now() + Math.random()}, function() {
|
||||
setState({random: Date.now() + Math.random()}, function() {
|
||||
deferred.resolve();
|
||||
});
|
||||
});
|
||||
@@ -36,6 +40,6 @@ exports.fn = function(deferred){
|
||||
});
|
||||
});
|
||||
};
|
||||
exports.teardown = function(){
|
||||
exports.teardown = function() {
|
||||
React.unmountComponentAtNode(_rootNode);
|
||||
};
|
||||
@@ -1,4 +1,6 @@
|
||||
if (typeof exports == 'undefined') exports = {};
|
||||
if (typeof exports === 'undefined') {
|
||||
exports = {};
|
||||
}
|
||||
|
||||
/*http://benchmarkjs.com/docs#options*/
|
||||
|
||||
@@ -6,28 +8,30 @@ exports.name = 'From setState to callback';
|
||||
|
||||
exports.defer = true;
|
||||
|
||||
exports.setup = function(){
|
||||
/*global*/_rootNode = document.createElement('div');
|
||||
exports.setup = function() {
|
||||
_rootNode = document.createElement('div');
|
||||
document.body.appendChild(_rootNode);
|
||||
/*global*/setState = null;
|
||||
setState = null;
|
||||
|
||||
var AwesomeComponent = React.createClass({
|
||||
getInitialState: function(){
|
||||
getInitialState: function() {
|
||||
return { random:null };
|
||||
},
|
||||
render: function(){
|
||||
if (!setState) setState = this.setState.bind(this);
|
||||
render: function() {
|
||||
if (!setState) {
|
||||
setState = this.setState.bind(this);
|
||||
}
|
||||
return React.DOM.div(null, this.state.random);
|
||||
}
|
||||
});
|
||||
|
||||
React.render(AwesomeComponent(null), _rootNode);
|
||||
};
|
||||
exports.fn = function(deferred){
|
||||
setState({random: Date.now() + Math.random()}, function(){
|
||||
exports.fn = function(deferred) {
|
||||
setState({random: Date.now() + Math.random()}, function() {
|
||||
deferred.resolve();
|
||||
});
|
||||
};
|
||||
exports.teardown = function(){
|
||||
exports.teardown = function() {
|
||||
React.unmountComponentAtNode(_rootNode);
|
||||
};
|
||||
@@ -1,15 +1,17 @@
|
||||
if (typeof exports == 'undefined') exports = {};
|
||||
if (typeof exports === 'undefined') {
|
||||
exports = {};
|
||||
}
|
||||
|
||||
/*http://benchmarkjs.com/docs#options*/
|
||||
|
||||
exports.name = 'shouldComponentUpdate';
|
||||
|
||||
exports.setup = function(){
|
||||
exports.setup = function() {
|
||||
var AwesomeComponent = React.createClass({
|
||||
shouldComponentUpdate: function(){
|
||||
shouldComponentUpdate: function() {
|
||||
return false;
|
||||
},
|
||||
render: function(){
|
||||
render: function() {
|
||||
return React.DOM.div({});
|
||||
}
|
||||
});
|
||||
@@ -17,9 +19,9 @@ exports.setup = function(){
|
||||
var _rootNode = document.createElement('div');
|
||||
document.body.appendChild(_rootNode);
|
||||
};
|
||||
exports.fn = function(){
|
||||
exports.fn = function() {
|
||||
React.render(AwesomeComponent(null), _rootNode);
|
||||
};
|
||||
exports.teardown = function(){
|
||||
exports.teardown = function() {
|
||||
React.unmountComponentAtNode(_rootNode);
|
||||
};
|
||||
@@ -1,4 +1,6 @@
|
||||
if (typeof exports == 'undefined') exports = {};
|
||||
if (typeof exports === 'undefined') {
|
||||
exports = {};
|
||||
}
|
||||
|
||||
/*http://benchmarkjs.com/docs#options*/
|
||||
|
||||
@@ -6,20 +8,22 @@ exports.name = 'todolist from addItem to callback';
|
||||
|
||||
exports.defer = true;
|
||||
|
||||
exports.setup = function(){
|
||||
/*global*/_rootNode = document.createElement('div');
|
||||
exports.setup = function() {
|
||||
_rootNode = document.createElement('div');
|
||||
document.body.appendChild(_rootNode);
|
||||
var appDescriptor = todolist.App({ fakeDataCount: 333 });
|
||||
/*global*/_app = React.render(appDescriptor, _rootNode);
|
||||
_app = React.render(appDescriptor, _rootNode);
|
||||
};
|
||||
exports.fn = function(deferred){
|
||||
exports.fn = function(deferred) {
|
||||
var liCount = document.getElementsByTagName('li').length;
|
||||
_app.addItem(Math.random(), function(){
|
||||
if (document.getElementsByTagName('li').length <= liCount) throw Error('expected a list item to be added to the dom');
|
||||
_app.addItem(Math.random(), function() {
|
||||
if (document.getElementsByTagName('li').length <= liCount) {
|
||||
throw Error('expected a list item to be added to the dom');
|
||||
}
|
||||
deferred.resolve();
|
||||
});
|
||||
};
|
||||
exports.teardown = function(){
|
||||
exports.teardown = function() {
|
||||
React.unmountComponentAtNode(_rootNode);
|
||||
_rootNode.parentNode.removeChild(_rootNode);
|
||||
_rootNode = null;
|
||||
|
||||
@@ -1,52 +1,56 @@
|
||||
if (typeof exports == 'undefined') exports = {};
|
||||
if (typeof exports === 'undefined') {
|
||||
exports = {};
|
||||
}
|
||||
|
||||
/*http://benchmarkjs.com/docs#options*/
|
||||
|
||||
/*global*/_timesToRun = 2;
|
||||
_timesToRun = 2;
|
||||
|
||||
exports.name = 'todolist add, complete, remove (x' + _timesToRun + ')';
|
||||
|
||||
exports.defer = true;
|
||||
|
||||
exports.setup = function(){
|
||||
/*global*/_rootNode = document.createElement('div');
|
||||
exports.setup = function() {
|
||||
_rootNode = document.createElement('div');
|
||||
document.body.appendChild(_rootNode);
|
||||
var appDescriptor = todolist.App({ fakeDataCount: 333 });
|
||||
/*global*/_app = React.render(appDescriptor, _rootNode);
|
||||
_app = React.render(appDescriptor, _rootNode);
|
||||
};
|
||||
|
||||
exports.fn = function(deferred){
|
||||
exports.fn = function(deferred) {
|
||||
var originalLiCount = document.getElementsByTagName('li').length;
|
||||
|
||||
var todos = [];
|
||||
var times = _timesToRun;
|
||||
while (times-- >= 0){
|
||||
todos.push(_app.addItem(times+1));
|
||||
while (times-- >= 0) {
|
||||
todos.push(_app.addItem(times + 1));
|
||||
}
|
||||
|
||||
todos.forEach(function(todo){
|
||||
todos.forEach(function(todo) {
|
||||
_app.setItemCompleted(todo.id);
|
||||
});
|
||||
|
||||
todos.forEach(function(todo){
|
||||
todos.forEach(function(todo) {
|
||||
_app.deleteItemById(todo.id);
|
||||
});
|
||||
|
||||
todos = null;
|
||||
|
||||
_app.addItem(Math.random(), function(todo){
|
||||
if (document.getElementsByTagName('li').length <= originalLiCount)
|
||||
_app.addItem(Math.random(), function(todo) {
|
||||
if (document.getElementsByTagName('li').length <= originalLiCount) {
|
||||
throw Error('expected a list item to be added to the dom');
|
||||
}
|
||||
|
||||
_app.deleteItemById(todo.id, function(){
|
||||
if (document.getElementsByTagName('li').length != originalLiCount)
|
||||
_app.deleteItemById(todo.id, function() {
|
||||
if (document.getElementsByTagName('li').length !== originalLiCount) {
|
||||
throw Error('expected everything to be done by now');
|
||||
}
|
||||
deferred.resolve();
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
exports.teardown = function(){
|
||||
exports.teardown = function() {
|
||||
React.unmountComponentAtNode(_rootNode);
|
||||
_rootNode.parentNode.removeChild(_rootNode);
|
||||
_rootNode = null;
|
||||
|
||||
+12
-10
@@ -1,4 +1,6 @@
|
||||
if (typeof exports == 'undefined') exports = {};
|
||||
if (typeof exports === 'undefined') {
|
||||
exports = {};
|
||||
}
|
||||
|
||||
/*http://benchmarkjs.com/docs#options*/
|
||||
|
||||
@@ -6,25 +8,25 @@ exports.name = 'todolist setItemCompleted';
|
||||
|
||||
exports.defer = true;
|
||||
|
||||
exports.setup = function(){
|
||||
/*global*/_rootNode = document.createElement('div');
|
||||
exports.setup = function() {
|
||||
_rootNode = document.createElement('div');
|
||||
document.body.appendChild(_rootNode);
|
||||
var appDescriptor = todolist.App({ fakeDataCount: 333 });
|
||||
/*global*/_app = React.render(appDescriptor, _rootNode);
|
||||
/*global*/_todo1 = _app.addItem("Howdy 1!");
|
||||
/*global*/_todo2 = _app.addItem("Howdy 2!");
|
||||
/*global*/_todo3 = _app.addItem("Howdy 3!");
|
||||
_app = React.render(appDescriptor, _rootNode);
|
||||
_todo1 = _app.addItem('Howdy 1!');
|
||||
_todo2 = _app.addItem('Howdy 2!');
|
||||
_todo3 = _app.addItem('Howdy 3!');
|
||||
};
|
||||
|
||||
exports.fn = function(deferred){
|
||||
exports.fn = function(deferred) {
|
||||
_app.setItemCompleted(_todo1.id, !_todo1.completed);
|
||||
_app.setItemCompleted(_todo2.id, !_todo2.completed);
|
||||
_app.setItemCompleted(_todo3.id, !_todo3.completed, function(){
|
||||
_app.setItemCompleted(_todo3.id, !_todo3.completed, function() {
|
||||
deferred.resolve();
|
||||
});
|
||||
};
|
||||
|
||||
exports.teardown = function(){
|
||||
exports.teardown = function() {
|
||||
React.unmountComponentAtNode(_rootNode);
|
||||
_rootNode.parentNode.removeChild(_rootNode);
|
||||
_rootNode = null;
|
||||
|
||||
@@ -1,22 +1,29 @@
|
||||
if (typeof exports == 'undefined') exports = {};
|
||||
if (typeof exports === 'undefined') {
|
||||
exports = {};
|
||||
}
|
||||
|
||||
/*http://benchmarkjs.com/docs#options*/
|
||||
|
||||
exports.name = 'todolist from renderComponent to renderComponent callback (333 rows)';
|
||||
exports.name =
|
||||
'todolist from renderComponent to renderComponent callback (333 rows)';
|
||||
|
||||
exports.defer = true;
|
||||
|
||||
exports.setup = function(){
|
||||
if (typeof _rootNode != 'undefined') throw Error("should teardown before running setup again");
|
||||
/*global*/_rootNode = document.createElement('div');
|
||||
exports.setup = function() {
|
||||
if (typeof _rootNode !== 'undefined') {
|
||||
throw Error('should teardown before running setup again');
|
||||
}
|
||||
_rootNode = document.createElement('div');
|
||||
document.body.appendChild(_rootNode);
|
||||
};
|
||||
|
||||
exports.fn = function(deferred){
|
||||
React.render(todolist.App({ fakeDataCount: 333 }), _rootNode, function(){ deferred.resolve(); });
|
||||
exports.fn = function(deferred) {
|
||||
React.render(todolist.App({ fakeDataCount: 333 }), _rootNode, function() {
|
||||
deferred.resolve();
|
||||
});
|
||||
};
|
||||
|
||||
exports.teardown = function(){
|
||||
exports.teardown = function() {
|
||||
React.unmountComponentAtNode(_rootNode);
|
||||
_rootNode.parentNode.removeChild(_rootNode);
|
||||
_rootNode = undefined;
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
globals:
|
||||
harness: true
|
||||
|
||||
rules:
|
||||
strict: false
|
||||
no-undef: false
|
||||
no-unused-vars: false
|
||||
block-scoped-var: false
|
||||
@@ -1,6 +1,6 @@
|
||||
document.write('<style> @import "../vendor/jasmine/jasmine.css?_=' + (+new Date).toString(36) + '"; </style>');
|
||||
document.write('<style> @import \'../vendor/jasmine/jasmine.css?_=' + (+new Date()).toString(36) + '\'; </style>');
|
||||
|
||||
;(function(env){
|
||||
(function(env) {
|
||||
var htmlReporter = new jasmine.HtmlReporter();
|
||||
env.addReporter(htmlReporter);
|
||||
env.specFilter = function(spec) {
|
||||
@@ -10,10 +10,10 @@ document.write('<style> @import "../vendor/jasmine/jasmine.css?_=' + (+new Date)
|
||||
// Clean up any nodes the previous test might have added.
|
||||
env.afterEach(function() {
|
||||
harness.removeNextSiblings(document.body);
|
||||
harness.removeNextSiblings(document.getElementById("HTMLReporter"));
|
||||
harness.removeNextSiblings(document.getElementById('HTMLReporter'));
|
||||
});
|
||||
|
||||
window.onload = function(){
|
||||
window.onload = function() {
|
||||
env.execute();
|
||||
}
|
||||
};
|
||||
})(jasmine.getEnv());
|
||||
@@ -1,34 +1,48 @@
|
||||
function createXMLHttpRequest(){
|
||||
try{return new XMLHttpRequest();}
|
||||
catch(e){}
|
||||
try {return new ActiveXObject("Msxml2.XMLHTTP");}
|
||||
/*eslint-disable brace-style*/
|
||||
function createXMLHttpRequest() {
|
||||
try {
|
||||
return new XMLHttpRequest();
|
||||
}
|
||||
catch(e) {}
|
||||
try {
|
||||
return new ActiveXObject('Msxml2.XMLHTTP');
|
||||
}
|
||||
catch (e) {}
|
||||
try {return new ActiveXObject("Microsoft.XMLHTTP");}
|
||||
try {
|
||||
return new ActiveXObject('Microsoft.XMLHTTP');
|
||||
}
|
||||
catch (e) {}
|
||||
}
|
||||
/*eslint-enable brace-style*/
|
||||
|
||||
function getURLSync(url){
|
||||
function getURLSync(url) {
|
||||
var request = createXMLHttpRequest();
|
||||
request.open('GET', url, /*asynchronous?*/false);
|
||||
return request.responseText;
|
||||
}
|
||||
|
||||
function postDataToURL(data, url, callback) {
|
||||
if (!callback) callback = postDataToURL.defaultCallback;
|
||||
if (!callback) {
|
||||
callback = postDataToURL.defaultCallback;
|
||||
}
|
||||
var request = createXMLHttpRequest();
|
||||
if (!request) return callback(Error('XMLHttpRequest is unsupported'));
|
||||
postDataToURL.running = (postDataToURL.running||0) + 1;
|
||||
request.onreadystatechange = function(){
|
||||
if (request.readyState != 4) return;
|
||||
if (!request) {
|
||||
return callback(Error('XMLHttpRequest is unsupported'));
|
||||
}
|
||||
postDataToURL.running = (postDataToURL.running || 0) + 1;
|
||||
request.onreadystatechange = function() {
|
||||
if (request.readyState !== 4) {
|
||||
return;
|
||||
}
|
||||
request.onreadystatechange = null;
|
||||
postDataToURL.running = (postDataToURL.running||0) - 1;
|
||||
callback(request.status == 200 ? null : request.status, request.responseText);
|
||||
postDataToURL.running = (postDataToURL.running || 0) - 1;
|
||||
callback(request.status === 200 ? null : request.status, request.responseText);
|
||||
};
|
||||
request.open('POST', url);
|
||||
request.setRequestHeader('Content-Type', 'application/json');
|
||||
request.send(JSON.stringify(data));
|
||||
}
|
||||
|
||||
postDataToURL.defaultCallback = function(error){
|
||||
postDataToURL.defaultCallback = function(error) {
|
||||
// console.log('postDataToURL.defaultCallback', arguments)
|
||||
}
|
||||
};
|
||||
@@ -1,38 +1,46 @@
|
||||
var __DEBUG__ = location.search.substring(1).indexOf('debug') != -1;
|
||||
var __DEBUG__ = location.search.substring(1).indexOf('debug') !== -1;
|
||||
|
||||
if (typeof console == 'undefined') console = {
|
||||
log: function(){},
|
||||
warn: function(){},
|
||||
error: function(){}
|
||||
};
|
||||
if (typeof console === 'undefined') {
|
||||
console = {
|
||||
log: function() {},
|
||||
warn: function() {},
|
||||
error: function() {}
|
||||
};
|
||||
}
|
||||
|
||||
var __consoleReport__ = [];
|
||||
|
||||
console._log = console.log;
|
||||
console.log = function(message){
|
||||
console.log = function(message) {
|
||||
console._log(message);
|
||||
if (__DEBUG__) postDataToURL({type:'log', message:message}, '/reportTestResults');
|
||||
else __consoleReport__.push({type:'log', message:message});
|
||||
}
|
||||
if (__DEBUG__) {
|
||||
postDataToURL({type:'log', message:message}, '/reportTestResults');
|
||||
} else {
|
||||
__consoleReport__.push({type:'log', message:message});
|
||||
}
|
||||
};
|
||||
|
||||
console._error = console.error;
|
||||
console.error = function(message){
|
||||
console.error = function(message) {
|
||||
console._error(message);
|
||||
if (__DEBUG__) postDataToURL({type:'error', message:message}, '/reportTestResults');
|
||||
else __consoleReport__.push({type:'error', message:message});
|
||||
}
|
||||
if (__DEBUG__) {
|
||||
postDataToURL({type:'error', message:message}, '/reportTestResults');
|
||||
} else {
|
||||
__consoleReport__.push({type:'error', message:message});
|
||||
}
|
||||
};
|
||||
|
||||
console._flush = function(){
|
||||
console._flush = function() {
|
||||
postDataToURL(__consoleReport__, '/console');
|
||||
__consoleReport__.length = 0;
|
||||
}
|
||||
};
|
||||
|
||||
;(function(env){
|
||||
(function(env) {
|
||||
env.addReporter(new jasmine.JSReporter());
|
||||
env.addReporter(new TAPReporter(console.log.bind(console)));
|
||||
|
||||
function report(){
|
||||
if (typeof jasmine.getJSReport != 'function') {
|
||||
function report() {
|
||||
if (typeof jasmine.getJSReport !== 'function') {
|
||||
return setTimeout(report, 100);
|
||||
}
|
||||
if (!__DEBUG__) {
|
||||
@@ -42,8 +50,10 @@ console._flush = function(){
|
||||
}
|
||||
|
||||
var oldCallback = env.currentRunner().finishCallback;
|
||||
env.currentRunner().finishCallback = function(){
|
||||
if (oldCallback) oldCallback.apply(this, arguments);
|
||||
env.currentRunner().finishCallback = function() {
|
||||
if (oldCallback) {
|
||||
oldCallback.apply(this, arguments);
|
||||
}
|
||||
report();
|
||||
};
|
||||
|
||||
|
||||
Reference in new issue
Block a user