react-test-renderer 15.5.0 → 15.5.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (168) hide show
  1. package/lib/ReactShallowRenderer.js +6 -0
  2. package/lib/shallow/ARIADOMPropertyConfig.js +73 -0
  3. package/lib/shallow/AutoFocusUtils.js +23 -0
  4. package/lib/shallow/BeforeInputEventPlugin.js +384 -0
  5. package/lib/shallow/CSSProperty.js +147 -0
  6. package/lib/shallow/CSSPropertyOperations.js +208 -0
  7. package/lib/shallow/CallbackQueue.js +118 -0
  8. package/lib/shallow/ChangeEventPlugin.js +345 -0
  9. package/lib/shallow/DOMChildrenOperations.js +224 -0
  10. package/lib/shallow/DOMLazyTree.js +117 -0
  11. package/lib/shallow/DOMNamespaces.js +19 -0
  12. package/lib/shallow/DOMProperty.js +209 -0
  13. package/lib/shallow/DOMPropertyOperations.js +236 -0
  14. package/lib/shallow/Danger.js +47 -0
  15. package/lib/shallow/DefaultEventPluginOrder.js +25 -0
  16. package/lib/shallow/EnterLeaveEventPlugin.js +99 -0
  17. package/lib/shallow/EventConstants.js +91 -0
  18. package/lib/shallow/EventPluginHub.js +277 -0
  19. package/lib/shallow/EventPluginRegistry.js +254 -0
  20. package/lib/shallow/EventPluginUtils.js +225 -0
  21. package/lib/shallow/EventPropagators.js +133 -0
  22. package/lib/shallow/FallbackCompositionState.js +94 -0
  23. package/lib/shallow/HTMLDOMPropertyConfig.js +235 -0
  24. package/lib/shallow/KeyEscapeUtils.js +58 -0
  25. package/lib/shallow/LinkedValueUtils.js +137 -0
  26. package/lib/shallow/PluginModuleType.js +12 -0
  27. package/lib/shallow/PooledClass.js +111 -0
  28. package/lib/shallow/ReactBrowserEventEmitter.js +327 -0
  29. package/lib/shallow/ReactChildFiber.js +243 -0
  30. package/lib/shallow/ReactChildReconciler.js +153 -0
  31. package/lib/shallow/ReactComponentBrowserEnvironment.js +29 -0
  32. package/lib/shallow/ReactComponentEnvironment.js +45 -0
  33. package/lib/shallow/ReactCompositeComponent.js +901 -0
  34. package/lib/shallow/ReactCoroutine.js +80 -0
  35. package/lib/shallow/ReactDOM.js +110 -0
  36. package/lib/shallow/ReactDOMComponent.js +1000 -0
  37. package/lib/shallow/ReactDOMComponentFlags.js +17 -0
  38. package/lib/shallow/ReactDOMComponentTree.js +194 -0
  39. package/lib/shallow/ReactDOMContainerInfo.js +32 -0
  40. package/lib/shallow/ReactDOMEmptyComponent.js +59 -0
  41. package/lib/shallow/ReactDOMFeatureFlags.js +18 -0
  42. package/lib/shallow/ReactDOMFiber.js +97 -0
  43. package/lib/shallow/ReactDOMIDOperations.js +33 -0
  44. package/lib/shallow/ReactDOMInput.js +284 -0
  45. package/lib/shallow/ReactDOMInvalidARIAHook.js +92 -0
  46. package/lib/shallow/ReactDOMNullInputValuePropHook.js +42 -0
  47. package/lib/shallow/ReactDOMOption.js +122 -0
  48. package/lib/shallow/ReactDOMSelect.js +199 -0
  49. package/lib/shallow/ReactDOMSelection.js +211 -0
  50. package/lib/shallow/ReactDOMServer.js +25 -0
  51. package/lib/shallow/ReactDOMTextComponent.js +163 -0
  52. package/lib/shallow/ReactDOMTextarea.js +159 -0
  53. package/lib/shallow/ReactDOMTreeTraversal.js +135 -0
  54. package/lib/shallow/ReactDOMUnknownPropertyHook.js +111 -0
  55. package/lib/shallow/ReactDebugTool.js +358 -0
  56. package/lib/shallow/ReactDefaultBatchingStrategy.js +67 -0
  57. package/lib/shallow/ReactDefaultInjection.js +85 -0
  58. package/lib/shallow/ReactElementSymbol.js +19 -0
  59. package/lib/shallow/ReactEmptyComponent.js +29 -0
  60. package/lib/shallow/ReactErrorUtils.js +75 -0
  61. package/lib/shallow/ReactEventEmitterMixin.js +32 -0
  62. package/lib/shallow/ReactEventListener.js +154 -0
  63. package/lib/shallow/ReactFeatureFlags.js +21 -0
  64. package/lib/shallow/ReactFiber.js +190 -0
  65. package/lib/shallow/ReactFiberBeginWork.js +380 -0
  66. package/lib/shallow/ReactFiberCommitWork.js +78 -0
  67. package/lib/shallow/ReactFiberCompleteWork.js +208 -0
  68. package/lib/shallow/ReactFiberReconciler.js +64 -0
  69. package/lib/shallow/ReactFiberRoot.js +29 -0
  70. package/lib/shallow/ReactFiberScheduler.js +331 -0
  71. package/lib/shallow/ReactFiberUpdateQueue.js +77 -0
  72. package/lib/shallow/ReactHostComponent.js +67 -0
  73. package/lib/shallow/ReactHostOperationHistoryHook.js +33 -0
  74. package/lib/shallow/ReactInjection.js +33 -0
  75. package/lib/shallow/ReactInputSelection.js +123 -0
  76. package/lib/shallow/ReactInstanceMap.js +47 -0
  77. package/lib/shallow/ReactInstanceType.js +12 -0
  78. package/lib/shallow/ReactInstrumentation.js +23 -0
  79. package/lib/shallow/ReactInvalidSetStateWarningHook.js +36 -0
  80. package/lib/shallow/ReactMarkupChecksum.js +49 -0
  81. package/lib/shallow/ReactMount.js +537 -0
  82. package/lib/shallow/ReactMultiChild.js +449 -0
  83. package/lib/shallow/ReactMultiChildUpdateTypes.js +18 -0
  84. package/lib/shallow/ReactNodeTypes.js +39 -0
  85. package/lib/shallow/ReactOwner.js +93 -0
  86. package/lib/shallow/ReactPerf.js +500 -0
  87. package/lib/shallow/ReactPriorityLevel.js +20 -0
  88. package/lib/shallow/ReactPropTypeLocationNames.js +24 -0
  89. package/lib/shallow/ReactPropTypeLocations.js +12 -0
  90. package/lib/shallow/ReactPropTypesSecret.js +16 -0
  91. package/lib/shallow/ReactReconcileTransaction.js +177 -0
  92. package/lib/shallow/ReactReconciler.js +167 -0
  93. package/lib/shallow/ReactRef.js +88 -0
  94. package/lib/shallow/ReactReifiedYield.js +30 -0
  95. package/lib/shallow/ReactServerBatchingStrategy.js +21 -0
  96. package/lib/shallow/ReactServerRendering.js +89 -0
  97. package/lib/shallow/ReactServerRenderingTransaction.js +89 -0
  98. package/lib/shallow/ReactServerUpdateQueue.js +138 -0
  99. package/lib/shallow/ReactShallowRenderer.js +150 -0
  100. package/lib/shallow/ReactSimpleEmptyComponent.js +36 -0
  101. package/lib/shallow/ReactSyntheticEventType.js +14 -0
  102. package/lib/shallow/ReactTestEmptyComponent.js +36 -0
  103. package/lib/shallow/ReactTestMount.js +131 -0
  104. package/lib/shallow/ReactTestReconcileTransaction.js +128 -0
  105. package/lib/shallow/ReactTestRenderer.js +139 -0
  106. package/lib/shallow/ReactTestTextComponent.js +40 -0
  107. package/lib/shallow/ReactTypeOfWork.js +23 -0
  108. package/lib/shallow/ReactTypes.js +12 -0
  109. package/lib/shallow/ReactUpdateQueue.js +235 -0
  110. package/lib/shallow/ReactUpdates.js +250 -0
  111. package/lib/shallow/ReactVersion.js +13 -0
  112. package/lib/shallow/ResponderEventPlugin.js +507 -0
  113. package/lib/shallow/ResponderSyntheticEvent.js +38 -0
  114. package/lib/shallow/ResponderTouchHistoryStore.js +183 -0
  115. package/lib/shallow/SVGDOMPropertyConfig.js +301 -0
  116. package/lib/shallow/SelectEventPlugin.js +190 -0
  117. package/lib/shallow/SimpleEventPlugin.js +227 -0
  118. package/lib/shallow/SyntheticAnimationEvent.js +38 -0
  119. package/lib/shallow/SyntheticClipboardEvent.js +37 -0
  120. package/lib/shallow/SyntheticCompositionEvent.js +35 -0
  121. package/lib/shallow/SyntheticDragEvent.js +35 -0
  122. package/lib/shallow/SyntheticEvent.js +267 -0
  123. package/lib/shallow/SyntheticFocusEvent.js +35 -0
  124. package/lib/shallow/SyntheticInputEvent.js +36 -0
  125. package/lib/shallow/SyntheticKeyboardEvent.js +83 -0
  126. package/lib/shallow/SyntheticMouseEvent.js +71 -0
  127. package/lib/shallow/SyntheticTouchEvent.js +44 -0
  128. package/lib/shallow/SyntheticTransitionEvent.js +38 -0
  129. package/lib/shallow/SyntheticUIEvent.js +58 -0
  130. package/lib/shallow/SyntheticWheelEvent.js +53 -0
  131. package/lib/shallow/TapEventPlugin.js +115 -0
  132. package/lib/shallow/TouchHistoryMath.js +98 -0
  133. package/lib/shallow/Transaction.js +224 -0
  134. package/lib/shallow/ViewportMetrics.js +26 -0
  135. package/lib/shallow/accumulate.js +45 -0
  136. package/lib/shallow/accumulateInto.js +57 -0
  137. package/lib/shallow/adler32.js +43 -0
  138. package/lib/shallow/canDefineProperty.js +25 -0
  139. package/lib/shallow/checkReactTypeSpec.js +86 -0
  140. package/lib/shallow/createMicrosoftUnsafeLocalFunction.js +31 -0
  141. package/lib/shallow/dangerousStyleValue.js +78 -0
  142. package/lib/shallow/deprecated.js +56 -0
  143. package/lib/shallow/escapeTextContentForBrowser.js +122 -0
  144. package/lib/shallow/findDOMNode.js +59 -0
  145. package/lib/shallow/flattenChildren.js +75 -0
  146. package/lib/shallow/forEachAccumulated.js +30 -0
  147. package/lib/shallow/getEventCharCode.js +49 -0
  148. package/lib/shallow/getEventKey.js +101 -0
  149. package/lib/shallow/getEventModifierState.js +42 -0
  150. package/lib/shallow/getEventTarget.js +34 -0
  151. package/lib/shallow/getHostComponentFromComposite.js +29 -0
  152. package/lib/shallow/getIteratorFn.js +40 -0
  153. package/lib/shallow/getNodeForCharacterOffset.js +73 -0
  154. package/lib/shallow/getTextContentAccessor.js +32 -0
  155. package/lib/shallow/getVendorPrefixedEventName.js +100 -0
  156. package/lib/shallow/instantiateReactComponent.js +128 -0
  157. package/lib/shallow/isEventSupported.js +59 -0
  158. package/lib/shallow/isTextInputElement.js +50 -0
  159. package/lib/shallow/quoteAttributeValueForBrowser.js +25 -0
  160. package/lib/shallow/reactProdInvariant.js +38 -0
  161. package/lib/shallow/renderSubtreeIntoContainer.js +15 -0
  162. package/lib/shallow/setInnerHTML.js +97 -0
  163. package/lib/shallow/setTextContent.js +51 -0
  164. package/lib/shallow/shouldUpdateReactComponent.js +41 -0
  165. package/lib/shallow/traverseAllChildren.js +175 -0
  166. package/lib/shallow/validateDOMNesting.js +376 -0
  167. package/package.json +1 -1
  168. package/shallow.js +1 -1
@@ -0,0 +1,138 @@
1
+ /**
2
+ * Copyright 2015-present, Facebook, Inc.
3
+ * All rights reserved.
4
+ *
5
+ * This source code is licensed under the BSD-style license found in the
6
+ * LICENSE file in the root directory of this source tree. An additional grant
7
+ * of patent rights can be found in the PATENTS file in the same directory.
8
+ *
9
+ *
10
+ */
11
+
12
+ 'use strict';
13
+
14
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
15
+
16
+ var ReactUpdateQueue = require('./ReactUpdateQueue');
17
+
18
+ var warning = require('fbjs/lib/warning');
19
+
20
+ function warnNoop(publicInstance, callerName) {
21
+ if (process.env.NODE_ENV !== 'production') {
22
+ var constructor = publicInstance.constructor;
23
+ process.env.NODE_ENV !== 'production' ? warning(false, '%s(...): Can only update a mounting component. ' + 'This usually means you called %s() outside componentWillMount() on the server. ' + 'This is a no-op. Please check the code for the %s component.', callerName, callerName, constructor && (constructor.displayName || constructor.name) || 'ReactClass') : void 0;
24
+ }
25
+ }
26
+
27
+ /**
28
+ * This is the update queue used for server rendering.
29
+ * It delegates to ReactUpdateQueue while server rendering is in progress and
30
+ * switches to ReactNoopUpdateQueue after the transaction has completed.
31
+ * @class ReactServerUpdateQueue
32
+ * @param {Transaction} transaction
33
+ */
34
+
35
+ var ReactServerUpdateQueue = function () {
36
+ function ReactServerUpdateQueue(transaction) {
37
+ _classCallCheck(this, ReactServerUpdateQueue);
38
+
39
+ this.transaction = transaction;
40
+ }
41
+
42
+ /**
43
+ * Checks whether or not this composite component is mounted.
44
+ * @param {ReactClass} publicInstance The instance we want to test.
45
+ * @return {boolean} True if mounted, false otherwise.
46
+ * @protected
47
+ * @final
48
+ */
49
+
50
+
51
+ ReactServerUpdateQueue.prototype.isMounted = function isMounted(publicInstance) {
52
+ return false;
53
+ };
54
+
55
+ /**
56
+ * Enqueue a callback that will be executed after all the pending updates
57
+ * have processed.
58
+ *
59
+ * @param {ReactClass} publicInstance The instance to use as `this` context.
60
+ * @param {?function} callback Called after state is updated.
61
+ * @internal
62
+ */
63
+
64
+
65
+ ReactServerUpdateQueue.prototype.enqueueCallback = function enqueueCallback(publicInstance, callback, callerName) {
66
+ if (this.transaction.isInTransaction()) {
67
+ ReactUpdateQueue.enqueueCallback(publicInstance, callback, callerName);
68
+ }
69
+ };
70
+
71
+ /**
72
+ * Forces an update. This should only be invoked when it is known with
73
+ * certainty that we are **not** in a DOM transaction.
74
+ *
75
+ * You may want to call this when you know that some deeper aspect of the
76
+ * component's state has changed but `setState` was not called.
77
+ *
78
+ * This will not invoke `shouldComponentUpdate`, but it will invoke
79
+ * `componentWillUpdate` and `componentDidUpdate`.
80
+ *
81
+ * @param {ReactClass} publicInstance The instance that should rerender.
82
+ * @internal
83
+ */
84
+
85
+
86
+ ReactServerUpdateQueue.prototype.enqueueForceUpdate = function enqueueForceUpdate(publicInstance) {
87
+ if (this.transaction.isInTransaction()) {
88
+ ReactUpdateQueue.enqueueForceUpdate(publicInstance);
89
+ } else {
90
+ warnNoop(publicInstance, 'forceUpdate');
91
+ }
92
+ };
93
+
94
+ /**
95
+ * Replaces all of the state. Always use this or `setState` to mutate state.
96
+ * You should treat `this.state` as immutable.
97
+ *
98
+ * There is no guarantee that `this.state` will be immediately updated, so
99
+ * accessing `this.state` after calling this method may return the old value.
100
+ *
101
+ * @param {ReactClass} publicInstance The instance that should rerender.
102
+ * @param {object|function} completeState Next state.
103
+ * @internal
104
+ */
105
+
106
+
107
+ ReactServerUpdateQueue.prototype.enqueueReplaceState = function enqueueReplaceState(publicInstance, completeState) {
108
+ if (this.transaction.isInTransaction()) {
109
+ ReactUpdateQueue.enqueueReplaceState(publicInstance, completeState);
110
+ } else {
111
+ warnNoop(publicInstance, 'replaceState');
112
+ }
113
+ };
114
+
115
+ /**
116
+ * Sets a subset of the state. This only exists because _pendingState is
117
+ * internal. This provides a merging strategy that is not available to deep
118
+ * properties which is confusing. TODO: Expose pendingState or don't use it
119
+ * during the merge.
120
+ *
121
+ * @param {ReactClass} publicInstance The instance that should rerender.
122
+ * @param {object|function} partialState Next partial state to be merged with state.
123
+ * @internal
124
+ */
125
+
126
+
127
+ ReactServerUpdateQueue.prototype.enqueueSetState = function enqueueSetState(publicInstance, partialState) {
128
+ if (this.transaction.isInTransaction()) {
129
+ ReactUpdateQueue.enqueueSetState(publicInstance, partialState);
130
+ } else {
131
+ warnNoop(publicInstance, 'setState');
132
+ }
133
+ };
134
+
135
+ return ReactServerUpdateQueue;
136
+ }();
137
+
138
+ module.exports = ReactServerUpdateQueue;
@@ -0,0 +1,150 @@
1
+ /**
2
+ * Copyright 2013-present, Facebook, Inc.
3
+ * All rights reserved.
4
+ *
5
+ * This source code is licensed under the BSD-style license found in the
6
+ * LICENSE file in the root directory of this source tree. An additional grant
7
+ * of patent rights can be found in the PATENTS file in the same directory.
8
+ *
9
+ */
10
+
11
+ 'use strict';
12
+
13
+ var _prodInvariant = require('./reactProdInvariant'),
14
+ _assign = require('object-assign');
15
+
16
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
17
+
18
+ var React = require('react/lib/React');
19
+ var ReactCompositeComponent = require('./ReactCompositeComponent');
20
+ var ReactDefaultBatchingStrategy = require('./ReactDefaultBatchingStrategy');
21
+ var ReactReconciler = require('./ReactReconciler');
22
+ var ReactReconcileTransaction = require('./ReactReconcileTransaction');
23
+ var ReactUpdates = require('./ReactUpdates');
24
+
25
+ var emptyObject = require('fbjs/lib/emptyObject');
26
+ var getNextDebugID = require('react/lib/getNextDebugID');
27
+ var invariant = require('fbjs/lib/invariant');
28
+
29
+ function injectDefaults() {
30
+ ReactUpdates.injection.injectReconcileTransaction(ReactReconcileTransaction);
31
+ ReactUpdates.injection.injectBatchingStrategy(ReactDefaultBatchingStrategy);
32
+ }
33
+
34
+ var NoopInternalComponent = function () {
35
+ function NoopInternalComponent(element) {
36
+ _classCallCheck(this, NoopInternalComponent);
37
+
38
+ this._renderedOutput = element;
39
+ this._currentElement = element;
40
+
41
+ if (process.env.NODE_ENV !== 'production') {
42
+ this._debugID = getNextDebugID();
43
+ }
44
+ }
45
+
46
+ NoopInternalComponent.prototype.mountComponent = function mountComponent() {};
47
+
48
+ NoopInternalComponent.prototype.receiveComponent = function receiveComponent(element) {
49
+ this._renderedOutput = element;
50
+ this._currentElement = element;
51
+ };
52
+
53
+ NoopInternalComponent.prototype.unmountComponent = function unmountComponent() {};
54
+
55
+ NoopInternalComponent.prototype.getHostNode = function getHostNode() {
56
+ return undefined;
57
+ };
58
+
59
+ NoopInternalComponent.prototype.getPublicInstance = function getPublicInstance() {
60
+ return null;
61
+ };
62
+
63
+ return NoopInternalComponent;
64
+ }();
65
+
66
+ var ShallowComponentWrapper = function (element) {
67
+ // TODO: Consolidate with instantiateReactComponent
68
+ if (process.env.NODE_ENV !== 'production') {
69
+ this._debugID = getNextDebugID();
70
+ }
71
+
72
+ this.construct(element);
73
+ };
74
+ _assign(ShallowComponentWrapper.prototype, ReactCompositeComponent, {
75
+ _constructComponent: ReactCompositeComponent._constructComponentWithoutOwner,
76
+ _instantiateReactComponent: function (element) {
77
+ return new NoopInternalComponent(element);
78
+ },
79
+ _replaceNodeWithMarkup: function () {},
80
+ _renderValidatedComponent: ReactCompositeComponent._renderValidatedComponentWithoutOwnerOrContext
81
+ });
82
+
83
+ function _batchedRender(renderer, element, context) {
84
+ var transaction = ReactUpdates.ReactReconcileTransaction.getPooled(true);
85
+ renderer._render(element, transaction, context);
86
+ ReactUpdates.ReactReconcileTransaction.release(transaction);
87
+ }
88
+
89
+ var ReactShallowRenderer = function () {
90
+ function ReactShallowRenderer() {
91
+ _classCallCheck(this, ReactShallowRenderer);
92
+
93
+ this._instance = null;
94
+ }
95
+
96
+ ReactShallowRenderer.prototype.getMountedInstance = function getMountedInstance() {
97
+ return this._instance ? this._instance._instance : null;
98
+ };
99
+
100
+ ReactShallowRenderer.prototype.render = function render(element, context) {
101
+ // Ensure we've done the default injections. This might not be true in the
102
+ // case of a simple test that only requires React and the TestUtils in
103
+ // conjunction with an inline-requires transform.
104
+ injectDefaults();
105
+
106
+ !React.isValidElement(element) ? process.env.NODE_ENV !== 'production' ? invariant(false, 'ReactShallowRenderer render(): Invalid component element.%s', typeof element === 'function' ? ' Instead of passing a component class, make sure to instantiate ' + 'it by passing it to React.createElement.' : '') : _prodInvariant('12', typeof element === 'function' ? ' Instead of passing a component class, make sure to instantiate ' + 'it by passing it to React.createElement.' : '') : void 0;
107
+ !(typeof element.type !== 'string') ? process.env.NODE_ENV !== 'production' ? invariant(false, 'ReactShallowRenderer render(): Shallow rendering works only with custom components, not primitives (%s). Instead of calling `.render(el)` and inspecting the rendered output, look at `el.props` directly instead.', element.type) : _prodInvariant('13', element.type) : void 0;
108
+
109
+ if (!context) {
110
+ context = emptyObject;
111
+ }
112
+ ReactUpdates.batchedUpdates(_batchedRender, this, element, context);
113
+
114
+ return this.getRenderOutput();
115
+ };
116
+
117
+ ReactShallowRenderer.prototype.getRenderOutput = function getRenderOutput() {
118
+ return this._instance && this._instance._renderedComponent && this._instance._renderedComponent._renderedOutput || null;
119
+ };
120
+
121
+ ReactShallowRenderer.prototype.unmount = function unmount() {
122
+ if (this._instance) {
123
+ ReactReconciler.unmountComponent(this._instance, false);
124
+ }
125
+ };
126
+
127
+ ReactShallowRenderer.prototype.unstable_batchedUpdates = function unstable_batchedUpdates(callback, bookkeeping) {
128
+ // This is used by Enzyme for fake-simulating events in shallow mode.
129
+ injectDefaults();
130
+ return ReactUpdates.batchedUpdates(callback, bookkeeping);
131
+ };
132
+
133
+ ReactShallowRenderer.prototype._render = function _render(element, transaction, context) {
134
+ if (this._instance) {
135
+ ReactReconciler.receiveComponent(this._instance, element, transaction, context);
136
+ } else {
137
+ var instance = new ShallowComponentWrapper(element);
138
+ ReactReconciler.mountComponent(instance, transaction, null, null, context, 0);
139
+ this._instance = instance;
140
+ }
141
+ };
142
+
143
+ return ReactShallowRenderer;
144
+ }();
145
+
146
+ ReactShallowRenderer.createRenderer = function () {
147
+ return new ReactShallowRenderer();
148
+ };
149
+
150
+ module.exports = ReactShallowRenderer;
@@ -0,0 +1,36 @@
1
+ /**
2
+ * Copyright 2014-present, Facebook, Inc.
3
+ * All rights reserved.
4
+ *
5
+ * This source code is licensed under the BSD-style license found in the
6
+ * LICENSE file in the root directory of this source tree. An additional grant
7
+ * of patent rights can be found in the PATENTS file in the same directory.
8
+ *
9
+ */
10
+
11
+ 'use strict';
12
+
13
+ var _assign = require('object-assign');
14
+
15
+ var ReactReconciler = require('./ReactReconciler');
16
+
17
+ var ReactSimpleEmptyComponent = function (placeholderElement, instantiate) {
18
+ this._currentElement = null;
19
+ this._renderedComponent = instantiate(placeholderElement);
20
+ };
21
+ _assign(ReactSimpleEmptyComponent.prototype, {
22
+ mountComponent: function (transaction, hostParent, hostContainerInfo, context, parentDebugID // 0 in production and for roots
23
+ ) {
24
+ return ReactReconciler.mountComponent(this._renderedComponent, transaction, hostParent, hostContainerInfo, context, parentDebugID);
25
+ },
26
+ receiveComponent: function () {},
27
+ getHostNode: function () {
28
+ return ReactReconciler.getHostNode(this._renderedComponent);
29
+ },
30
+ unmountComponent: function () {
31
+ ReactReconciler.unmountComponent(this._renderedComponent);
32
+ this._renderedComponent = null;
33
+ }
34
+ });
35
+
36
+ module.exports = ReactSimpleEmptyComponent;
@@ -0,0 +1,14 @@
1
+ /*
2
+ * Copyright 2013-present, Facebook, Inc.
3
+ * All rights reserved.
4
+ *
5
+ * This source code is licensed under the BSD-style license found in the
6
+ * LICENSE file in the root directory of this source tree. An additional grant
7
+ * of patent rights can be found in the PATENTS file in the same directory.
8
+ *
9
+ * Flow type for SyntheticEvent class that includes private properties
10
+ *
11
+ *
12
+ */
13
+
14
+ 'use strict';
@@ -0,0 +1,36 @@
1
+ /**
2
+ * Copyright 2013-present, Facebook, Inc.
3
+ * All rights reserved.
4
+ *
5
+ * This source code is licensed under the BSD-style license found in the
6
+ * LICENSE file in the root directory of this source tree. An additional grant
7
+ * of patent rights can be found in the PATENTS file in the same directory.
8
+ *
9
+ *
10
+ */
11
+
12
+ 'use strict';
13
+
14
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
15
+
16
+ var ReactTestEmptyComponent = function () {
17
+ function ReactTestEmptyComponent() {
18
+ _classCallCheck(this, ReactTestEmptyComponent);
19
+
20
+ this._currentElement = null;
21
+ }
22
+
23
+ ReactTestEmptyComponent.prototype.receiveComponent = function receiveComponent() {};
24
+
25
+ ReactTestEmptyComponent.prototype.toJSON = function toJSON() {};
26
+
27
+ ReactTestEmptyComponent.prototype.mountComponent = function mountComponent() {};
28
+
29
+ ReactTestEmptyComponent.prototype.getHostNode = function getHostNode() {};
30
+
31
+ ReactTestEmptyComponent.prototype.unmountComponent = function unmountComponent() {};
32
+
33
+ return ReactTestEmptyComponent;
34
+ }();
35
+
36
+ module.exports = ReactTestEmptyComponent;
@@ -0,0 +1,131 @@
1
+ /**
2
+ * Copyright (c) 2015-present, Facebook, Inc.
3
+ * All rights reserved.
4
+ *
5
+ * This source code is licensed under the BSD-style license found in the
6
+ * LICENSE file in the root directory of this source tree. An additional grant
7
+ * of patent rights can be found in the PATENTS file in the same directory.
8
+ *
9
+ *
10
+ */
11
+ 'use strict';
12
+
13
+ var _prodInvariant = require('./reactProdInvariant'),
14
+ _assign = require('object-assign');
15
+
16
+ var React = require('react/lib/React');
17
+ var ReactReconciler = require('./ReactReconciler');
18
+ var ReactUpdates = require('./ReactUpdates');
19
+
20
+ var emptyObject = require('fbjs/lib/emptyObject');
21
+ var getHostComponentFromComposite = require('./getHostComponentFromComposite');
22
+ var instantiateReactComponent = require('./instantiateReactComponent');
23
+ var invariant = require('fbjs/lib/invariant');
24
+
25
+ var defaultTestOptions = {
26
+ createNodeMock: function () {
27
+ return null;
28
+ }
29
+ };
30
+
31
+ /**
32
+ * Temporary (?) hack so that we can store all top-level pending updates on
33
+ * composites instead of having to worry about different types of components
34
+ * here.
35
+ */
36
+ var TopLevelWrapper = function () {};
37
+ TopLevelWrapper.prototype.isReactComponent = {};
38
+ if (process.env.NODE_ENV !== 'production') {
39
+ TopLevelWrapper.displayName = 'TopLevelWrapper';
40
+ }
41
+ TopLevelWrapper.prototype.render = function () {
42
+ return this.props.child;
43
+ };
44
+ TopLevelWrapper.isReactTopLevelWrapper = true;
45
+
46
+ /**
47
+ * Mounts this component and inserts it into the DOM.
48
+ *
49
+ * @param {ReactComponent} componentInstance The instance to mount.
50
+ * @param {ReactReconcileTransaction} transaction
51
+ * @param {Object} hostParent
52
+ * @param {Object} hostContainerInfo
53
+ */
54
+ function mountComponentIntoNode(componentInstance, transaction, hostParent, hostContainerInfo) {
55
+ var image = ReactReconciler.mountComponent(componentInstance, transaction, null, hostContainerInfo, emptyObject);
56
+ componentInstance._renderedComponent._topLevelWrapper = componentInstance;
57
+ return image;
58
+ }
59
+
60
+ /**
61
+ * Batched mount.
62
+ *
63
+ * @param {ReactComponent} componentInstance The instance to mount.
64
+ * @param {number} rootID ID of the root node.
65
+ * @param {number} containerTag container element to mount into.
66
+ */
67
+ function batchedMountComponentIntoNode(componentInstance, options) {
68
+ var transaction = ReactUpdates.ReactReconcileTransaction.getPooled(true);
69
+ var image = transaction.perform(mountComponentIntoNode, null, componentInstance, transaction, null, options);
70
+ ReactUpdates.ReactReconcileTransaction.release(transaction);
71
+ return image;
72
+ }
73
+
74
+ var ReactTestInstance = function (component) {
75
+ this._component = component;
76
+ };
77
+ ReactTestInstance.prototype.getInstance = function () {
78
+ return this._component._renderedComponent.getPublicInstance();
79
+ };
80
+ ReactTestInstance.prototype.update = function (nextElement) {
81
+ !this._component ? process.env.NODE_ENV !== 'production' ? invariant(false, 'ReactTestRenderer: .update() can\'t be called after unmount.') : _prodInvariant('139') : void 0;
82
+ var nextWrappedElement = React.createElement(TopLevelWrapper, { child: nextElement });
83
+ var component = this._component;
84
+ ReactUpdates.batchedUpdates(function () {
85
+ var transaction = ReactUpdates.ReactReconcileTransaction.getPooled(true);
86
+ transaction.perform(function () {
87
+ ReactReconciler.receiveComponent(component, nextWrappedElement, transaction, emptyObject);
88
+ });
89
+ ReactUpdates.ReactReconcileTransaction.release(transaction);
90
+ });
91
+ };
92
+ ReactTestInstance.prototype.unmount = function (nextElement) {
93
+ var component = this._component;
94
+ ReactUpdates.batchedUpdates(function () {
95
+ var transaction = ReactUpdates.ReactReconcileTransaction.getPooled(true);
96
+ transaction.perform(function () {
97
+ ReactReconciler.unmountComponent(component, false);
98
+ });
99
+ ReactUpdates.ReactReconcileTransaction.release(transaction);
100
+ });
101
+ this._component = null;
102
+ };
103
+ ReactTestInstance.prototype.toJSON = function () {
104
+ var inst = getHostComponentFromComposite(this._component);
105
+ if (inst === null) {
106
+ return null;
107
+ }
108
+ return inst.toJSON();
109
+ };
110
+
111
+ /**
112
+ * As soon as `ReactMount` is refactored to not rely on the DOM, we can share
113
+ * code between the two. For now, we'll hard code the ID logic.
114
+ */
115
+ var ReactTestMount = {
116
+
117
+ render: function (nextElement, options) {
118
+ var nextWrappedElement = React.createElement(TopLevelWrapper, { child: nextElement });
119
+
120
+ var instance = instantiateReactComponent(nextWrappedElement, false);
121
+
122
+ // The initial render is synchronous but any updates that happen during
123
+ // rendering, in componentWillMount or componentDidMount, will be batched
124
+ // according to the current batching strategy.
125
+ ReactUpdates.batchedUpdates(batchedMountComponentIntoNode, instance, _assign({}, defaultTestOptions, options));
126
+ return new ReactTestInstance(instance);
127
+ }
128
+
129
+ };
130
+
131
+ module.exports = ReactTestMount;
@@ -0,0 +1,128 @@
1
+ /**
2
+ * Copyright (c) 2015-present, Facebook, Inc.
3
+ * All rights reserved.
4
+ *
5
+ * This source code is licensed under the BSD-style license found in the
6
+ * LICENSE file in the root directory of this source tree. An additional grant
7
+ * of patent rights can be found in the PATENTS file in the same directory.
8
+ *
9
+ *
10
+ */
11
+ 'use strict';
12
+
13
+ var _assign = require('object-assign');
14
+
15
+ var CallbackQueue = require('./CallbackQueue');
16
+ var PooledClass = require('./PooledClass');
17
+ var Transaction = require('./Transaction');
18
+ var ReactUpdateQueue = require('./ReactUpdateQueue');
19
+
20
+ /**
21
+ * Provides a `CallbackQueue` queue for collecting `onDOMReady` callbacks during
22
+ * the performing of the transaction.
23
+ */
24
+ var ON_DOM_READY_QUEUEING = {
25
+ /**
26
+ * Initializes the internal `onDOMReady` queue.
27
+ */
28
+ initialize: function () {
29
+ this.reactMountReady.reset();
30
+ },
31
+
32
+ /**
33
+ * After DOM is flushed, invoke all registered `onDOMReady` callbacks.
34
+ */
35
+ close: function () {
36
+ this.reactMountReady.notifyAll();
37
+ }
38
+ };
39
+
40
+ /**
41
+ * Executed within the scope of the `Transaction` instance. Consider these as
42
+ * being member methods, but with an implied ordering while being isolated from
43
+ * each other.
44
+ */
45
+ var TRANSACTION_WRAPPERS = [ON_DOM_READY_QUEUEING];
46
+
47
+ /**
48
+ * Currently:
49
+ * - The order that these are listed in the transaction is critical:
50
+ * - Suppresses events.
51
+ * - Restores selection range.
52
+ *
53
+ * Future:
54
+ * - Restore document/overflow scroll positions that were unintentionally
55
+ * modified via DOM insertions above the top viewport boundary.
56
+ * - Implement/integrate with customized constraint based layout system and keep
57
+ * track of which dimensions must be remeasured.
58
+ *
59
+ * @class ReactTestReconcileTransaction
60
+ */
61
+ function ReactTestReconcileTransaction(testOptions) {
62
+ this.reinitializeTransaction();
63
+ this.testOptions = testOptions;
64
+ this.reactMountReady = CallbackQueue.getPooled(this);
65
+ }
66
+
67
+ var Mixin = {
68
+ /**
69
+ * @see Transaction
70
+ * @abstract
71
+ * @final
72
+ * @return {array<object>} List of operation wrap procedures.
73
+ * TODO: convert to array<TransactionWrapper>
74
+ */
75
+ getTransactionWrappers: function () {
76
+ return TRANSACTION_WRAPPERS;
77
+ },
78
+
79
+ /**
80
+ * @return {object} The queue to collect `onDOMReady` callbacks with.
81
+ * TODO: convert to ReactMountReady
82
+ */
83
+ getReactMountReady: function () {
84
+ return this.reactMountReady;
85
+ },
86
+
87
+ /**
88
+ * @return {object} the options passed to ReactTestRenderer
89
+ */
90
+ getTestOptions: function () {
91
+ return this.testOptions;
92
+ },
93
+
94
+ /**
95
+ * @return {object} The queue to collect React async events.
96
+ */
97
+ getUpdateQueue: function () {
98
+ return ReactUpdateQueue;
99
+ },
100
+
101
+ /**
102
+ * Save current transaction state -- if the return value from this method is
103
+ * passed to `rollback`, the transaction will be reset to that state.
104
+ */
105
+ checkpoint: function () {
106
+ // reactMountReady is the our only stateful wrapper
107
+ return this.reactMountReady.checkpoint();
108
+ },
109
+
110
+ rollback: function (checkpoint) {
111
+ this.reactMountReady.rollback(checkpoint);
112
+ },
113
+
114
+ /**
115
+ * `PooledClass` looks for this, and will invoke this before allowing this
116
+ * instance to be reused.
117
+ */
118
+ destructor: function () {
119
+ CallbackQueue.release(this.reactMountReady);
120
+ this.reactMountReady = null;
121
+ }
122
+ };
123
+
124
+ _assign(ReactTestReconcileTransaction.prototype, Transaction, ReactTestReconcileTransaction, Mixin);
125
+
126
+ PooledClass.addPoolingTo(ReactTestReconcileTransaction);
127
+
128
+ module.exports = ReactTestReconcileTransaction;