mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
Add build process to all addons (#9946)
* Build createFragment addon * Tack the addon onto React.addons object * Generalize build process for all addons * Fix lint * Fix lint again
This commit is contained in:
@@ -15,8 +15,8 @@ var factory = require('./factory');
|
||||
|
||||
if (typeof React === 'undefined') {
|
||||
throw Error(
|
||||
'createReactClass could not find the React object. If you are using script tags, ' +
|
||||
'make sure that React is being loaded before createReactClass.'
|
||||
'create-react-class could not find the React object. If you are using script tags, ' +
|
||||
'make sure that React is being loaded before create-react-class.'
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,73 @@
|
||||
/**
|
||||
* Copyright 2015-present, Facebook, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This source code is licensed under the BSD-style license found in the
|
||||
* LICENSE file in the root directory of this source tree. An additional grant
|
||||
* of patent rights can be found in the PATENTS file in the same directory.
|
||||
*
|
||||
* @emails react-core
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
var fs = require('fs');
|
||||
var path = require('path');
|
||||
|
||||
// This lets us import Webpack config without crashing
|
||||
process.env.NODE_ENV = 'development';
|
||||
|
||||
// This script runs from the addon folder
|
||||
var exportName = require(path.resolve(process.cwd(), './webpack.config')).output
|
||||
.library;
|
||||
var packageName = path.basename(process.cwd());
|
||||
|
||||
if (packageName.indexOf('react-addons') !== 0) {
|
||||
throw new Error(
|
||||
'Only run this script for packages that used to be published as addons.'
|
||||
);
|
||||
}
|
||||
|
||||
// Inputs
|
||||
// DEV: root["exportName"] = factory(root["React"])
|
||||
// PROD: e.exportName=t(e.React)
|
||||
var find = new RegExp(
|
||||
'((?!exports)\\b\\w+)(\\["' +
|
||||
exportName +
|
||||
'"\\]|\\.' +
|
||||
exportName +
|
||||
')\\s*=\\s*(\\w+)\\((.*)\\)'
|
||||
);
|
||||
// Outputs
|
||||
// DEV: (root.React ? (root.React.addons = root.React.addons || {}) : /* throw */).exportName = factory(/* ... */);
|
||||
// PROD: (e.React ? (e.React.addons = e.React.addons || {}) : /* throw */).exportName = t(/* ... */)
|
||||
var throwIIFE = [
|
||||
'(function(){',
|
||||
'throw new Error("' +
|
||||
packageName +
|
||||
' could not find the React object. If you are using script tags, make sure that React is being loaded before ' +
|
||||
packageName +
|
||||
'.")',
|
||||
'})()',
|
||||
].join('');
|
||||
var replace =
|
||||
'($1.React?($1.React.addons=$1.React.addons||{}):' +
|
||||
throwIIFE +
|
||||
').' +
|
||||
exportName +
|
||||
'=$3($4)';
|
||||
|
||||
console.log('Tweaking the development UMD...');
|
||||
var devUMD = fs.readFileSync('./' + packageName + '.js', 'utf8').toString();
|
||||
devUMD = devUMD.replace(find, replace);
|
||||
fs.writeFileSync('./' + packageName + '.js', devUMD);
|
||||
|
||||
console.log('Tweaking the production UMD...');
|
||||
var prodUMD = fs
|
||||
.readFileSync('./' + packageName + '.min.js', 'utf8')
|
||||
.toString();
|
||||
prodUMD = prodUMD.replace(find, replace);
|
||||
fs.writeFileSync('./' + packageName + '.min.js', prodUMD);
|
||||
|
||||
console.log('Done.');
|
||||
console.log('Note that you need to manually test the UMD builds.');
|
||||
@@ -0,0 +1,2 @@
|
||||
react-addons-create-fragment.js
|
||||
react-addons-create-fragment.min.js
|
||||
@@ -22,8 +22,11 @@
|
||||
"react-addons-create-fragment.min.js"
|
||||
],
|
||||
"scripts": {
|
||||
"test": "jest",
|
||||
"prepublish": "npm test"
|
||||
"test": "TEST_ENTRY=./index.js jest",
|
||||
"build:dev": "NODE_ENV=development webpack && TEST_ENTRY=./react-addons-create-fragment.js jest",
|
||||
"build:prod": "NODE_ENV=production webpack && NODE_ENV=production TEST_ENTRY=./react-addons-create-fragment.min.js jest",
|
||||
"build": "npm run build:dev && npm run build:prod && node ../postbuild.js",
|
||||
"prepublish": "npm test && npm run build"
|
||||
},
|
||||
"devDependencies": {
|
||||
"jest": "^19.0.2",
|
||||
|
||||
+61
-15
@@ -14,32 +14,78 @@
|
||||
var React;
|
||||
var createReactFragment;
|
||||
|
||||
// For testing DOM Fiber.
|
||||
global.requestAnimationFrame = function(callback) {
|
||||
setTimeout(callback);
|
||||
// Catch stray warnings
|
||||
var env = jasmine.getEnv();
|
||||
var callCount = 0;
|
||||
var oldError = console.error;
|
||||
var newError = function() {
|
||||
callCount++;
|
||||
oldError.apply(this, arguments);
|
||||
};
|
||||
|
||||
global.requestIdleCallback = function(callback) {
|
||||
setTimeout(() => {
|
||||
callback({
|
||||
timeRemaining() {
|
||||
return Infinity;
|
||||
},
|
||||
});
|
||||
console.error = newError;
|
||||
env.beforeEach(() => {
|
||||
callCount = 0;
|
||||
jasmine.addMatchers({
|
||||
toBeReset() {
|
||||
return {
|
||||
compare(actual) {
|
||||
if (actual !== newError && !jasmine.isSpy(actual)) {
|
||||
return {
|
||||
pass: false,
|
||||
message: 'Test did not tear down console.error mock properly.',
|
||||
};
|
||||
}
|
||||
return {pass: true};
|
||||
},
|
||||
};
|
||||
},
|
||||
toNotHaveBeenCalled() {
|
||||
return {
|
||||
compare(actual) {
|
||||
return {
|
||||
pass: callCount === 0,
|
||||
message: 'Expected test not to warn. If the warning is expected, mock ' +
|
||||
"it out using spyOn(console, 'error'); and test that the " +
|
||||
'warning occurs.',
|
||||
};
|
||||
},
|
||||
};
|
||||
},
|
||||
});
|
||||
};
|
||||
});
|
||||
env.afterEach(() => {
|
||||
expect(console.error).toBeReset();
|
||||
expect(console.error).toNotHaveBeenCalled();
|
||||
});
|
||||
|
||||
const expectDev = function expectDev(actual) {
|
||||
// Suppress warning expectations for prod builds
|
||||
function suppressDevMatcher(obj, name) {
|
||||
const original = obj[name];
|
||||
obj[name] = function devMatcher() {
|
||||
try {
|
||||
original.apply(this, arguments);
|
||||
} catch (e) {
|
||||
// skip
|
||||
}
|
||||
};
|
||||
}
|
||||
function expectDev(actual) {
|
||||
const expectation = expect(actual);
|
||||
if (process.env.NODE_ENV === 'production') {
|
||||
Object.keys(expectation).forEach(name => {
|
||||
suppressDevMatcher(expectation, name);
|
||||
suppressDevMatcher(expectation.not, name);
|
||||
});
|
||||
}
|
||||
return expectation;
|
||||
};
|
||||
}
|
||||
|
||||
describe('createReactFragment', () => {
|
||||
beforeEach(() => {
|
||||
jest.resetModules();
|
||||
|
||||
React = require('react');
|
||||
createReactFragment = require('./index');
|
||||
createReactFragment = require(process.env.TEST_ENTRY);
|
||||
});
|
||||
|
||||
it('warns for numeric keys on objects as children', () => {
|
||||
|
||||
@@ -0,0 +1,63 @@
|
||||
/**
|
||||
* Copyright 2013-present, Facebook, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This source code is licensed under the BSD-style license found in the
|
||||
* LICENSE file in the root directory of this source tree. An additional grant
|
||||
* of patent rights can be found in the PATENTS file in the same directory.
|
||||
*
|
||||
* @emails react-core
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
const webpack = require('webpack');
|
||||
|
||||
let __DEV__;
|
||||
switch (process.env.NODE_ENV) {
|
||||
case 'development':
|
||||
__DEV__ = true;
|
||||
break;
|
||||
case 'production':
|
||||
__DEV__ = false;
|
||||
break;
|
||||
default:
|
||||
throw new Error('Unknown environment.');
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
entry: './index',
|
||||
output: {
|
||||
library: 'createFragment',
|
||||
libraryTarget: 'umd',
|
||||
filename: __DEV__
|
||||
? 'react-addons-create-fragment.js'
|
||||
: 'react-addons-create-fragment.min.js',
|
||||
},
|
||||
externals: {
|
||||
react: {
|
||||
root: 'React',
|
||||
commonjs2: 'react',
|
||||
commonjs: 'react',
|
||||
amd: 'react',
|
||||
},
|
||||
},
|
||||
plugins: [
|
||||
new webpack.DefinePlugin({
|
||||
'process.env.NODE_ENV': __DEV__ ? '"development"' : '"production"',
|
||||
}),
|
||||
].concat(
|
||||
__DEV__
|
||||
? []
|
||||
: [
|
||||
new webpack.optimize.UglifyJsPlugin({
|
||||
compress: {
|
||||
warnings: false,
|
||||
},
|
||||
output: {
|
||||
comments: false,
|
||||
},
|
||||
}),
|
||||
]
|
||||
),
|
||||
};
|
||||
@@ -0,0 +1,2 @@
|
||||
react-addons-linked-state-mixin.js
|
||||
react-addons-linked-state-mixin.min.js
|
||||
@@ -13,8 +13,11 @@
|
||||
"object-assign": "^4.1.0"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "jest",
|
||||
"prepublish": "npm test"
|
||||
"test": "TEST_ENTRY=./index.js jest",
|
||||
"build:dev": "NODE_ENV=development webpack && TEST_ENTRY=./react-addons-linked-state-mixin.js jest",
|
||||
"build:prod": "NODE_ENV=production webpack && NODE_ENV=production TEST_ENTRY=./react-addons-linked-state-mixin.min.js jest",
|
||||
"build": "npm run build:dev && npm run build:prod && node ../postbuild.js",
|
||||
"prepublish": "npm test && npm run build"
|
||||
},
|
||||
"files": [
|
||||
"LICENSE",
|
||||
@@ -25,9 +28,10 @@
|
||||
"react-addons-linked-state-mixin.min.js"
|
||||
],
|
||||
"devDependencies": {
|
||||
"create-react-class": "^15.5.4",
|
||||
"jest": "^19.0.2",
|
||||
"react": "^15.4.2",
|
||||
"react-addons-test-utils": "15.4.2",
|
||||
"react-dom": "^15.4.2"
|
||||
"react": "^15.5.4",
|
||||
"react-dom": "^15.5.4",
|
||||
"webpack": "^2.6.1"
|
||||
}
|
||||
}
|
||||
|
||||
+47
-16
@@ -12,40 +12,71 @@
|
||||
'use strict';
|
||||
|
||||
let LinkedStateMixin;
|
||||
let createReactClass;
|
||||
let React;
|
||||
let ReactDOM;
|
||||
let ReactTestUtils;
|
||||
|
||||
// For testing DOM Fiber.
|
||||
global.requestAnimationFrame = function(callback) {
|
||||
setTimeout(callback);
|
||||
// Catch stray warnings
|
||||
var env = jasmine.getEnv();
|
||||
var callCount = 0;
|
||||
var oldError = console.error;
|
||||
var newError = function() {
|
||||
callCount++;
|
||||
oldError.apply(this, arguments);
|
||||
};
|
||||
|
||||
global.requestIdleCallback = function(callback) {
|
||||
setTimeout(() => {
|
||||
callback({
|
||||
timeRemaining() {
|
||||
return Infinity;
|
||||
},
|
||||
});
|
||||
console.error = newError;
|
||||
env.beforeEach(() => {
|
||||
callCount = 0;
|
||||
jasmine.addMatchers({
|
||||
toBeReset() {
|
||||
return {
|
||||
compare(actual) {
|
||||
if (actual !== newError && !jasmine.isSpy(actual)) {
|
||||
return {
|
||||
pass: false,
|
||||
message: 'Test did not tear down console.error mock properly.',
|
||||
};
|
||||
}
|
||||
return {pass: true};
|
||||
},
|
||||
};
|
||||
},
|
||||
toNotHaveBeenCalled() {
|
||||
return {
|
||||
compare(actual) {
|
||||
return {
|
||||
pass: callCount === 0,
|
||||
message: 'Expected test not to warn. If the warning is expected, mock ' +
|
||||
"it out using spyOn(console, 'error'); and test that the " +
|
||||
'warning occurs.',
|
||||
};
|
||||
},
|
||||
};
|
||||
},
|
||||
});
|
||||
};
|
||||
});
|
||||
env.afterEach(() => {
|
||||
expect(console.error).toBeReset();
|
||||
expect(console.error).toNotHaveBeenCalled();
|
||||
});
|
||||
|
||||
describe('LinkedStateMixin', () => {
|
||||
beforeEach(() => {
|
||||
jest.resetModules();
|
||||
|
||||
createReactClass = require('create-react-class');
|
||||
React = require('react');
|
||||
ReactDOM = require('react-dom');
|
||||
ReactTestUtils = require('react-addons-test-utils');
|
||||
LinkedStateMixin = require('./index');
|
||||
ReactTestUtils = require('react-dom/test-utils');
|
||||
LinkedStateMixin = require(process.env.TEST_ENTRY);
|
||||
});
|
||||
|
||||
// https://facebook.github.io/react/docs/two-way-binding-helpers.html#linkedstatemixin-before-and-after
|
||||
it('should work with valueLink', () => {
|
||||
spyOn(console, 'error'); // Ignore deprecated valueLink message for now
|
||||
|
||||
const WithLink = React.createClass({
|
||||
const WithLink = createReactClass({
|
||||
mixins: [LinkedStateMixin],
|
||||
getInitialState: function() {
|
||||
return {message: 'Hello!'};
|
||||
@@ -70,7 +101,7 @@ describe('LinkedStateMixin', () => {
|
||||
|
||||
// https://facebook.github.io/react/docs/two-way-binding-helpers.html#linkedstatemixin-without-valuelink
|
||||
it('should work without valueLink', () => {
|
||||
const WithoutLink = React.createClass({
|
||||
const WithoutLink = createReactClass({
|
||||
mixins: [LinkedStateMixin],
|
||||
getInitialState: function() {
|
||||
return {message: 'Hello!'};
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
/**
|
||||
* Copyright 2013-present, Facebook, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This source code is licensed under the BSD-style license found in the
|
||||
* LICENSE file in the root directory of this source tree. An additional grant
|
||||
* of patent rights can be found in the PATENTS file in the same directory.
|
||||
*
|
||||
* @emails react-core
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
const webpack = require('webpack');
|
||||
|
||||
let __DEV__;
|
||||
switch (process.env.NODE_ENV) {
|
||||
case 'development':
|
||||
__DEV__ = true;
|
||||
break;
|
||||
case 'production':
|
||||
__DEV__ = false;
|
||||
break;
|
||||
default:
|
||||
throw new Error('Unknown environment.');
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
entry: './index',
|
||||
output: {
|
||||
library: 'LinkedStateMixin',
|
||||
libraryTarget: 'umd',
|
||||
filename: __DEV__
|
||||
? 'react-addons-linked-state-mixin.js'
|
||||
: 'react-addons-linked-state-mixin.min.js',
|
||||
},
|
||||
plugins: [
|
||||
new webpack.DefinePlugin({
|
||||
'process.env.NODE_ENV': __DEV__ ? '"development"' : '"production"',
|
||||
}),
|
||||
].concat(
|
||||
__DEV__
|
||||
? []
|
||||
: [
|
||||
new webpack.optimize.UglifyJsPlugin({
|
||||
compress: {
|
||||
warnings: false,
|
||||
},
|
||||
output: {
|
||||
comments: false,
|
||||
},
|
||||
}),
|
||||
]
|
||||
),
|
||||
};
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,2 @@
|
||||
react-addons-pure-render-mixin.js
|
||||
react-addons-pure-render-mixin.min.js
|
||||
@@ -21,13 +21,16 @@
|
||||
"react-addons-pure-render-mixin.min.js"
|
||||
],
|
||||
"scripts": {
|
||||
"test": "jest",
|
||||
"prepublish": "npm test"
|
||||
"test": "TEST_ENTRY=./index.js jest",
|
||||
"build:dev": "NODE_ENV=development webpack && TEST_ENTRY=./react-addons-pure-render-mixin.js jest",
|
||||
"build:prod": "NODE_ENV=production webpack && NODE_ENV=production TEST_ENTRY=./react-addons-pure-render-mixin.min.js jest",
|
||||
"build": "npm run build:dev && npm run build:prod && node ../postbuild.js",
|
||||
"prepublish": "npm test && npm run build"
|
||||
},
|
||||
"devDependencies": {
|
||||
"jest": "^19.0.2",
|
||||
"react": "^15.4.2",
|
||||
"react-addons-test-utils": "15.4.2",
|
||||
"react-dom": "^15.4.2"
|
||||
"react-dom": "^15.4.2",
|
||||
"webpack": "^2.6.1"
|
||||
}
|
||||
}
|
||||
|
||||
+52
-22
@@ -12,29 +12,63 @@
|
||||
'use strict';
|
||||
|
||||
var React;
|
||||
var ReactDOM;
|
||||
var ReactComponentWithPureRenderMixin;
|
||||
var ReactTestUtils;
|
||||
|
||||
// For testing DOM Fiber.
|
||||
global.requestAnimationFrame = function(callback) {
|
||||
setTimeout(callback);
|
||||
// Catch stray warnings
|
||||
var env = jasmine.getEnv();
|
||||
var callCount = 0;
|
||||
var oldError = console.error;
|
||||
var newError = function() {
|
||||
callCount++;
|
||||
oldError.apply(this, arguments);
|
||||
};
|
||||
|
||||
global.requestIdleCallback = function(callback) {
|
||||
setTimeout(() => {
|
||||
callback({
|
||||
timeRemaining() {
|
||||
return Infinity;
|
||||
},
|
||||
});
|
||||
console.error = newError;
|
||||
env.beforeEach(() => {
|
||||
callCount = 0;
|
||||
jasmine.addMatchers({
|
||||
toBeReset() {
|
||||
return {
|
||||
compare(actual) {
|
||||
if (actual !== newError && !jasmine.isSpy(actual)) {
|
||||
return {
|
||||
pass: false,
|
||||
message: 'Test did not tear down console.error mock properly.',
|
||||
};
|
||||
}
|
||||
return {pass: true};
|
||||
},
|
||||
};
|
||||
},
|
||||
toNotHaveBeenCalled() {
|
||||
return {
|
||||
compare(actual) {
|
||||
return {
|
||||
pass: callCount === 0,
|
||||
message: 'Expected test not to warn. If the warning is expected, mock ' +
|
||||
"it out using spyOn(console, 'error'); and test that the " +
|
||||
'warning occurs.',
|
||||
};
|
||||
},
|
||||
};
|
||||
},
|
||||
});
|
||||
};
|
||||
});
|
||||
env.afterEach(() => {
|
||||
expect(console.error).toBeReset();
|
||||
expect(console.error).toNotHaveBeenCalled();
|
||||
});
|
||||
|
||||
describe('createReactFragment', () => {
|
||||
function renderIntoDocument(element) {
|
||||
var node = document.createElement('div');
|
||||
return ReactDOM.render(element, node);
|
||||
}
|
||||
|
||||
describe('PureRenderMixin', () => {
|
||||
beforeEach(() => {
|
||||
React = require('react');
|
||||
ReactComponentWithPureRenderMixin = require('./index');
|
||||
ReactTestUtils = require('react-addons-test-utils');
|
||||
ReactDOM = require('react-dom');
|
||||
ReactComponentWithPureRenderMixin = require(process.env.TEST_ENTRY);
|
||||
});
|
||||
|
||||
it('provides a default shouldComponentUpdate implementation', () => {
|
||||
@@ -84,9 +118,7 @@ describe('createReactFragment', () => {
|
||||
},
|
||||
});
|
||||
|
||||
var instance = ReactTestUtils.renderIntoDocument(
|
||||
React.createElement(PlasticWrap)
|
||||
);
|
||||
var instance = renderIntoDocument(React.createElement(PlasticWrap));
|
||||
expect(renderCalls).toBe(1);
|
||||
|
||||
// Do not re-render based on props
|
||||
@@ -134,9 +166,7 @@ describe('createReactFragment', () => {
|
||||
},
|
||||
});
|
||||
|
||||
var instance = ReactTestUtils.renderIntoDocument(
|
||||
React.createElement(Component)
|
||||
);
|
||||
var instance = renderIntoDocument(React.createElement(Component));
|
||||
expect(renderCalls).toBe(1);
|
||||
|
||||
// Do not re-render if state is equal
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
/**
|
||||
* Copyright 2013-present, Facebook, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This source code is licensed under the BSD-style license found in the
|
||||
* LICENSE file in the root directory of this source tree. An additional grant
|
||||
* of patent rights can be found in the PATENTS file in the same directory.
|
||||
*
|
||||
* @emails react-core
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
const webpack = require('webpack');
|
||||
|
||||
let __DEV__;
|
||||
switch (process.env.NODE_ENV) {
|
||||
case 'development':
|
||||
__DEV__ = true;
|
||||
break;
|
||||
case 'production':
|
||||
__DEV__ = false;
|
||||
break;
|
||||
default:
|
||||
throw new Error('Unknown environment.');
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
entry: './index',
|
||||
output: {
|
||||
library: 'PureRenderMixin',
|
||||
libraryTarget: 'umd',
|
||||
filename: __DEV__
|
||||
? 'react-addons-pure-render-mixin.js'
|
||||
: 'react-addons-pure-render-mixin.min.js',
|
||||
},
|
||||
plugins: [
|
||||
new webpack.DefinePlugin({
|
||||
'process.env.NODE_ENV': __DEV__ ? '"development"' : '"production"',
|
||||
}),
|
||||
].concat(
|
||||
__DEV__
|
||||
? []
|
||||
: [
|
||||
new webpack.optimize.UglifyJsPlugin({
|
||||
compress: {
|
||||
warnings: false,
|
||||
},
|
||||
output: {
|
||||
comments: false,
|
||||
},
|
||||
}),
|
||||
]
|
||||
),
|
||||
};
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,2 @@
|
||||
react-addons-shallow-compare.js
|
||||
react-addons-shallow-compare.min.js
|
||||
@@ -21,13 +21,16 @@
|
||||
"react-addons-shallow-compare.min.js"
|
||||
],
|
||||
"scripts": {
|
||||
"test": "jest",
|
||||
"prepublish": "npm test"
|
||||
"test": "TEST_ENTRY=./index.js jest",
|
||||
"build:dev": "NODE_ENV=development webpack && TEST_ENTRY=./react-addons-shallow-compare.js jest",
|
||||
"build:prod": "NODE_ENV=production webpack && NODE_ENV=production TEST_ENTRY=./react-addons-shallow-compare.min.js jest",
|
||||
"build": "npm run build:dev && npm run build:prod && node ../postbuild.js",
|
||||
"prepublish": "npm test && npm run build"
|
||||
},
|
||||
"devDependencies": {
|
||||
"jest": "^19.0.2",
|
||||
"react": "^15.4.2",
|
||||
"react-addons-test-utils": "^15.4.2",
|
||||
"react-dom": "^15.4.2"
|
||||
"react-dom": "^15.4.2",
|
||||
"webpack": "^2.6.1"
|
||||
}
|
||||
}
|
||||
|
||||
+49
-21
@@ -13,31 +13,63 @@
|
||||
|
||||
var React;
|
||||
var ReactDOM;
|
||||
var ReactTestUtils;
|
||||
var shallowCompare;
|
||||
|
||||
// Polyfill for testing DOM Fiber.
|
||||
global.requestAnimationFrame = function(callback) {
|
||||
setTimeout(callback);
|
||||
// Catch stray warnings
|
||||
var env = jasmine.getEnv();
|
||||
var callCount = 0;
|
||||
var oldError = console.error;
|
||||
var newError = function() {
|
||||
callCount++;
|
||||
oldError.apply(this, arguments);
|
||||
};
|
||||
|
||||
global.requestIdleCallback = function(callback) {
|
||||
setTimeout(() => {
|
||||
callback({
|
||||
timeRemaining() {
|
||||
return Infinity;
|
||||
},
|
||||
});
|
||||
console.error = newError;
|
||||
env.beforeEach(() => {
|
||||
callCount = 0;
|
||||
jasmine.addMatchers({
|
||||
toBeReset() {
|
||||
return {
|
||||
compare(actual) {
|
||||
if (actual !== newError && !jasmine.isSpy(actual)) {
|
||||
return {
|
||||
pass: false,
|
||||
message: 'Test did not tear down console.error mock properly.',
|
||||
};
|
||||
}
|
||||
return {pass: true};
|
||||
},
|
||||
};
|
||||
},
|
||||
toNotHaveBeenCalled() {
|
||||
return {
|
||||
compare(actual) {
|
||||
return {
|
||||
pass: callCount === 0,
|
||||
message: 'Expected test not to warn. If the warning is expected, mock ' +
|
||||
"it out using spyOn(console, 'error'); and test that the " +
|
||||
'warning occurs.',
|
||||
};
|
||||
},
|
||||
};
|
||||
},
|
||||
});
|
||||
};
|
||||
});
|
||||
env.afterEach(() => {
|
||||
expect(console.error).toBeReset();
|
||||
expect(console.error).toNotHaveBeenCalled();
|
||||
});
|
||||
|
||||
function renderIntoDocument(element) {
|
||||
var node = document.createElement('div');
|
||||
return ReactDOM.render(element, node);
|
||||
}
|
||||
|
||||
// Tests adapted from ReactComponentWithPureRendererMixin and ReactPureComponent tests
|
||||
describe('shallowCompare', () => {
|
||||
beforeEach(() => {
|
||||
React = require('react');
|
||||
ReactDOM = require('react-dom');
|
||||
ReactTestUtils = require('react-addons-test-utils');
|
||||
shallowCompare = require('./index');
|
||||
shallowCompare = require(process.env.TEST_ENTRY);
|
||||
});
|
||||
|
||||
it('should render', () => {
|
||||
@@ -165,9 +197,7 @@ describe('shallowCompare', () => {
|
||||
},
|
||||
});
|
||||
|
||||
var instance = ReactTestUtils.renderIntoDocument(
|
||||
React.createElement(PlasticWrap)
|
||||
);
|
||||
var instance = renderIntoDocument(React.createElement(PlasticWrap));
|
||||
expect(renderCalls).toBe(1);
|
||||
|
||||
// Do not re-render based on props
|
||||
@@ -217,9 +247,7 @@ describe('shallowCompare', () => {
|
||||
},
|
||||
});
|
||||
|
||||
var instance = ReactTestUtils.renderIntoDocument(
|
||||
React.createElement(Component)
|
||||
);
|
||||
var instance = renderIntoDocument(React.createElement(Component));
|
||||
expect(renderCalls).toBe(1);
|
||||
|
||||
// Do not re-render if state is equal
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
/**
|
||||
* Copyright 2013-present, Facebook, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This source code is licensed under the BSD-style license found in the
|
||||
* LICENSE file in the root directory of this source tree. An additional grant
|
||||
* of patent rights can be found in the PATENTS file in the same directory.
|
||||
*
|
||||
* @emails react-core
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
const webpack = require('webpack');
|
||||
|
||||
let __DEV__;
|
||||
switch (process.env.NODE_ENV) {
|
||||
case 'development':
|
||||
__DEV__ = true;
|
||||
break;
|
||||
case 'production':
|
||||
__DEV__ = false;
|
||||
break;
|
||||
default:
|
||||
throw new Error('Unknown environment.');
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
entry: './index',
|
||||
output: {
|
||||
library: 'shallowCompare',
|
||||
libraryTarget: 'umd',
|
||||
filename: __DEV__
|
||||
? 'react-addons-shallow-compare.js'
|
||||
: 'react-addons-shallow-compare.min.js',
|
||||
},
|
||||
plugins: [
|
||||
new webpack.DefinePlugin({
|
||||
'process.env.NODE_ENV': __DEV__ ? '"development"' : '"production"',
|
||||
}),
|
||||
].concat(
|
||||
__DEV__
|
||||
? []
|
||||
: [
|
||||
new webpack.optimize.UglifyJsPlugin({
|
||||
compress: {
|
||||
warnings: false,
|
||||
},
|
||||
output: {
|
||||
comments: false,
|
||||
},
|
||||
}),
|
||||
]
|
||||
),
|
||||
};
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,2 @@
|
||||
react-addons-update.js
|
||||
react-addons-update.min.js
|
||||
@@ -13,11 +13,15 @@
|
||||
"object-assign": "^4.1.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"jest": "^19.0.2"
|
||||
"jest": "^19.0.2",
|
||||
"webpack": "^2.6.1"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "jest",
|
||||
"prepublish": "npm test"
|
||||
"test": "TEST_ENTRY=./index.js jest",
|
||||
"build:dev": "NODE_ENV=development webpack && TEST_ENTRY=./react-addons-update.js jest",
|
||||
"build:prod": "NODE_ENV=production webpack && NODE_ENV=production TEST_ENTRY=./react-addons-update.min.js jest",
|
||||
"build": "npm run build:dev && npm run build:prod && node ../postbuild.js",
|
||||
"prepublish": "npm test && npm run build"
|
||||
},
|
||||
"files": [
|
||||
"LICENSE",
|
||||
|
||||
Vendored
+45
-1
@@ -11,7 +11,51 @@
|
||||
|
||||
'use strict';
|
||||
|
||||
const update = require('./index');
|
||||
// Catch stray warnings
|
||||
var env = jasmine.getEnv();
|
||||
var callCount = 0;
|
||||
var oldError = console.error;
|
||||
var newError = function() {
|
||||
callCount++;
|
||||
oldError.apply(this, arguments);
|
||||
};
|
||||
console.error = newError;
|
||||
env.beforeEach(() => {
|
||||
callCount = 0;
|
||||
jasmine.addMatchers({
|
||||
toBeReset() {
|
||||
return {
|
||||
compare(actual) {
|
||||
if (actual !== newError && !jasmine.isSpy(actual)) {
|
||||
return {
|
||||
pass: false,
|
||||
message: 'Test did not tear down console.error mock properly.',
|
||||
};
|
||||
}
|
||||
return {pass: true};
|
||||
},
|
||||
};
|
||||
},
|
||||
toNotHaveBeenCalled() {
|
||||
return {
|
||||
compare(actual) {
|
||||
return {
|
||||
pass: callCount === 0,
|
||||
message: 'Expected test not to warn. If the warning is expected, mock ' +
|
||||
"it out using spyOn(console, 'error'); and test that the " +
|
||||
'warning occurs.',
|
||||
};
|
||||
},
|
||||
};
|
||||
},
|
||||
});
|
||||
});
|
||||
env.afterEach(() => {
|
||||
expect(console.error).toBeReset();
|
||||
expect(console.error).toNotHaveBeenCalled();
|
||||
});
|
||||
|
||||
const update = require(process.env.TEST_ENTRY);
|
||||
|
||||
describe('update', () => {
|
||||
// https://facebook.github.io/react/docs/update.html#simple-push
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
/**
|
||||
* Copyright 2013-present, Facebook, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This source code is licensed under the BSD-style license found in the
|
||||
* LICENSE file in the root directory of this source tree. An additional grant
|
||||
* of patent rights can be found in the PATENTS file in the same directory.
|
||||
*
|
||||
* @emails react-core
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
const webpack = require('webpack');
|
||||
|
||||
let __DEV__;
|
||||
switch (process.env.NODE_ENV) {
|
||||
case 'development':
|
||||
__DEV__ = true;
|
||||
break;
|
||||
case 'production':
|
||||
__DEV__ = false;
|
||||
break;
|
||||
default:
|
||||
throw new Error('Unknown environment.');
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
entry: './index',
|
||||
output: {
|
||||
library: 'update',
|
||||
libraryTarget: 'umd',
|
||||
filename: __DEV__ ? 'react-addons-update.js' : 'react-addons-update.min.js',
|
||||
},
|
||||
plugins: [
|
||||
new webpack.DefinePlugin({
|
||||
'process.env.NODE_ENV': __DEV__ ? '"development"' : '"production"',
|
||||
}),
|
||||
].concat(
|
||||
__DEV__
|
||||
? []
|
||||
: [
|
||||
new webpack.optimize.UglifyJsPlugin({
|
||||
compress: {
|
||||
warnings: false,
|
||||
},
|
||||
output: {
|
||||
comments: false,
|
||||
},
|
||||
}),
|
||||
]
|
||||
),
|
||||
};
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,2 @@
|
||||
react-linked-input.js
|
||||
react-linked-input.min.js
|
||||
Vendored
+7
@@ -11,6 +11,13 @@
|
||||
|
||||
var React = require('react');
|
||||
|
||||
if (typeof React === 'undefined') {
|
||||
throw Error(
|
||||
'react-linked-input could not find the React object. If you are using script tags, ' +
|
||||
'make sure that React is being loaded before react-linked-input.'
|
||||
);
|
||||
}
|
||||
|
||||
var invariant = require('fbjs/lib/invariant');
|
||||
|
||||
function _assertSingleLink(inputProps) {
|
||||
|
||||
@@ -4,8 +4,11 @@
|
||||
"description": "LinkedInput supports the ReactLink semantics",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"test": "jest",
|
||||
"prepublish": "npm test"
|
||||
"test": "TEST_ENTRY=./index.js jest",
|
||||
"build:dev": "NODE_ENV=development webpack && TEST_ENTRY=./react-linked-input.js jest",
|
||||
"build:prod": "NODE_ENV=production webpack && NODE_ENV=production TEST_ENTRY=./react-linked-input.min.js jest",
|
||||
"build": "npm run build:dev && npm run build:prod",
|
||||
"prepublish": "npm test && npm run build"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
@@ -31,7 +34,8 @@
|
||||
"babel-preset-es2015": "^6.24.0",
|
||||
"jest": "^19.0.2",
|
||||
"react": "^15.4.2",
|
||||
"react-dom": "^15.4.2"
|
||||
"react-dom": "^15.4.2",
|
||||
"webpack": "^2.6.1"
|
||||
},
|
||||
"dependencies": {
|
||||
"fbjs": "^0.8.9"
|
||||
|
||||
Vendored
+43
-14
@@ -11,25 +11,54 @@
|
||||
|
||||
'use strict';
|
||||
|
||||
// Polyfill for testing DOM Fiber.
|
||||
global.requestAnimationFrame = function(callback) {
|
||||
setTimeout(callback);
|
||||
// Catch stray warnings
|
||||
var env = jasmine.getEnv();
|
||||
var callCount = 0;
|
||||
var oldError = console.error;
|
||||
var newError = function() {
|
||||
callCount++;
|
||||
oldError.apply(this, arguments);
|
||||
};
|
||||
|
||||
global.requestIdleCallback = function(callback) {
|
||||
setTimeout(() => {
|
||||
callback({
|
||||
timeRemaining() {
|
||||
return Infinity;
|
||||
},
|
||||
});
|
||||
console.error = newError;
|
||||
env.beforeEach(() => {
|
||||
callCount = 0;
|
||||
jasmine.addMatchers({
|
||||
toBeReset() {
|
||||
return {
|
||||
compare(actual) {
|
||||
if (actual !== newError && !jasmine.isSpy(actual)) {
|
||||
return {
|
||||
pass: false,
|
||||
message: 'Test did not tear down console.error mock properly.',
|
||||
};
|
||||
}
|
||||
return {pass: true};
|
||||
},
|
||||
};
|
||||
},
|
||||
toNotHaveBeenCalled() {
|
||||
return {
|
||||
compare(actual) {
|
||||
return {
|
||||
pass: callCount === 0,
|
||||
message: 'Expected test not to warn. If the warning is expected, mock ' +
|
||||
"it out using spyOn(console, 'error'); and test that the " +
|
||||
'warning occurs.',
|
||||
};
|
||||
},
|
||||
};
|
||||
},
|
||||
});
|
||||
};
|
||||
});
|
||||
env.afterEach(() => {
|
||||
expect(console.error).toBeReset();
|
||||
expect(console.error).toNotHaveBeenCalled();
|
||||
});
|
||||
|
||||
function noop() {}
|
||||
|
||||
// Tests adapted from ReactComponentWithPureRendererMixin and ReactPureComponent tests
|
||||
describe('LinkedStateMixin', function() {
|
||||
describe('LinkedInput', function() {
|
||||
let LinkedInput;
|
||||
let React;
|
||||
let ReactDOM;
|
||||
@@ -37,7 +66,7 @@ describe('LinkedStateMixin', function() {
|
||||
beforeEach(function() {
|
||||
React = require('react');
|
||||
ReactDOM = require('react-dom');
|
||||
LinkedInput = require('./index');
|
||||
LinkedInput = require(process.env.TEST_ENTRY);
|
||||
});
|
||||
|
||||
it('should basically work', function() {
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
/**
|
||||
* Copyright 2013-present, Facebook, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This source code is licensed under the BSD-style license found in the
|
||||
* LICENSE file in the root directory of this source tree. An additional grant
|
||||
* of patent rights can be found in the PATENTS file in the same directory.
|
||||
*
|
||||
* @emails react-core
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
const webpack = require('webpack');
|
||||
|
||||
let __DEV__;
|
||||
switch (process.env.NODE_ENV) {
|
||||
case 'development':
|
||||
__DEV__ = true;
|
||||
break;
|
||||
case 'production':
|
||||
__DEV__ = false;
|
||||
break;
|
||||
default:
|
||||
throw new Error('Unknown environment.');
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
entry: './index',
|
||||
output: {
|
||||
library: 'LinkedInput',
|
||||
libraryTarget: 'umd',
|
||||
filename: __DEV__ ? 'react-linked-input.js' : 'react-linked-input.min.js',
|
||||
},
|
||||
externals: {
|
||||
react: {
|
||||
root: 'React',
|
||||
commonjs2: 'react',
|
||||
commonjs: 'react',
|
||||
amd: 'react',
|
||||
},
|
||||
},
|
||||
plugins: [
|
||||
new webpack.DefinePlugin({
|
||||
'process.env.NODE_ENV': __DEV__ ? '"development"' : '"production"',
|
||||
}),
|
||||
].concat(
|
||||
__DEV__
|
||||
? []
|
||||
: [
|
||||
new webpack.optimize.UglifyJsPlugin({
|
||||
compress: {
|
||||
warnings: false,
|
||||
},
|
||||
output: {
|
||||
comments: false,
|
||||
},
|
||||
}),
|
||||
]
|
||||
),
|
||||
};
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user