SchedulerMock.unstable_yieldValue -> SchedulerMock.log (#26312)

(This only affects our own internal repo; it's not a public API.)

I think most of us agree this is a less confusing name. It's possible
someone will confuse it with `console.log`. If that becomes a problem we
can warn in dev or something.
This commit is contained in:
Andrew Clark
2023-03-06 11:09:07 -05:00
committed by GitHub
parent 4bbac04cd3
commit 1528c5ccdf
99 changed files with 2286 additions and 2889 deletions
+7 -6
View File
@@ -1,7 +1,8 @@
'use strict';
const JestReact = require('jest-react');
const SchedulerMatchers = require('./schedulerTestMatchers');
// TODO: Move to ReactInternalTestUtils
function captureAssertion(fn) {
// Trick to use a Jest matcher inside another Jest matcher. `fn` contains an
@@ -20,12 +21,13 @@ function captureAssertion(fn) {
}
function assertYieldsWereCleared(Scheduler) {
const actualYields = Scheduler.unstable_clearYields();
const actualYields = Scheduler.unstable_clearLog();
if (actualYields.length !== 0) {
throw new Error(
'Log of yielded values is not empty. ' +
'Call expect(Scheduler).toHaveYielded(...) first.'
const error = Error(
'The event log is not empty. Call assertLog(...) first.'
);
Error.captureStackTrace(error, assertYieldsWereCleared);
throw error;
}
}
@@ -41,6 +43,5 @@ function toMatchRenderedOutput(ReactNoop, expectedJSX) {
}
module.exports = {
...SchedulerMatchers,
toMatchRenderedOutput,
};
@@ -1,96 +0,0 @@
'use strict';
function captureAssertion(fn) {
// Trick to use a Jest matcher inside another Jest matcher. `fn` contains an
// assertion; if it throws, we capture the error and return it, so the stack
// trace presented to the user points to the original assertion in the
// test file.
try {
fn();
} catch (error) {
return {
pass: false,
message: () => error.message,
};
}
return {pass: true};
}
function assertYieldsWereCleared(Scheduler) {
const actualYields = Scheduler.unstable_clearYields();
if (actualYields.length !== 0) {
const error = Error(
'Log of yielded values is not empty. ' +
'Call expect(Scheduler).toHaveYielded(...) first.'
);
Error.captureStackTrace(error, assertYieldsWereCleared);
throw error;
}
}
function toFlushAndYield(Scheduler, expectedYields) {
assertYieldsWereCleared(Scheduler);
Scheduler.unstable_flushAllWithoutAsserting();
const actualYields = Scheduler.unstable_clearYields();
return captureAssertion(() => {
expect(actualYields).toEqual(expectedYields);
});
}
function toFlushAndYieldThrough(Scheduler, expectedYields) {
assertYieldsWereCleared(Scheduler);
Scheduler.unstable_flushNumberOfYields(expectedYields.length);
const actualYields = Scheduler.unstable_clearYields();
return captureAssertion(() => {
expect(actualYields).toEqual(expectedYields);
});
}
function toFlushUntilNextPaint(Scheduler, expectedYields) {
assertYieldsWereCleared(Scheduler);
Scheduler.unstable_flushUntilNextPaint();
const actualYields = Scheduler.unstable_clearYields();
return captureAssertion(() => {
expect(actualYields).toEqual(expectedYields);
});
}
function toFlushWithoutYielding(Scheduler) {
return toFlushAndYield(Scheduler, []);
}
function toFlushExpired(Scheduler, expectedYields) {
assertYieldsWereCleared(Scheduler);
Scheduler.unstable_flushExpired();
const actualYields = Scheduler.unstable_clearYields();
return captureAssertion(() => {
expect(actualYields).toEqual(expectedYields);
});
}
function toHaveYielded(Scheduler, expectedYields) {
return captureAssertion(() => {
const actualYields = Scheduler.unstable_clearYields();
expect(actualYields).toEqual(expectedYields);
});
}
function toFlushAndThrow(Scheduler, ...rest) {
assertYieldsWereCleared(Scheduler);
return captureAssertion(() => {
expect(() => {
Scheduler.unstable_flushAllWithoutAsserting();
}).toThrow(...rest);
});
}
module.exports = {
toFlushAndYield,
toFlushAndYieldThrough,
toFlushUntilNextPaint,
toFlushWithoutYielding,
toFlushExpired,
toHaveYielded,
toFlushAndThrow,
};
+40 -40
View File
@@ -73,12 +73,12 @@ Index: build/node_modules/react/umd/react.development.js
*
@@ -16,9 +16,9 @@
}(this, (function () { 'use strict';
// TODO: this is special because it gets imported during build.
-var ReactVersion = '16.6.1-canary-b3d1a81a9';
+var ReactVersion = '1.2.3';
// The Symbol used to tag the ReactElement-like types. If there is no native Symbol
// nor polyfill, then a plain number is used for performance.
var hasSymbol = typeof Symbol === 'function' && Symbol.for;
@@ -132,12 +132,12 @@ Index: build/node_modules/react/cjs/react.development.js
*
@@ -19,9 +19,9 @@
var checkPropTypes = require('prop-types/checkPropTypes');
// TODO: this is special because it gets imported during build.
-var ReactVersion = '16.6.1-canary-b3d1a81a9';
+var ReactVersion = '1.2.3';
// The Symbol used to tag the ReactElement-like types. If there is no native Symbol
// nor polyfill, then a plain number is used for performance.
var hasSymbol = typeof Symbol === 'function' && Symbol.for;
@@ -154,12 +154,12 @@ Index: build/node_modules/react-art/umd/react-art.development.js
*
@@ -20,9 +20,9 @@
var _assign = ReactInternals.assign;
// TODO: this is special because it gets imported during build.
-var ReactVersion = '16.6.1-canary-b3d1a81a9';
+var ReactVersion = '1.2.3';
/**
* Use invariant() to assert state which your program assumes to be true.
*
@@ -194,12 +194,12 @@ Index: build/node_modules/react-art/cjs/react-art.development.js
*
@@ -25,9 +25,9 @@
var FastNoSideEffects = require('art/modes/fast-noSideEffects');
// TODO: this is special because it gets imported during build.
-var ReactVersion = '16.6.1-canary-b3d1a81a9';
+var ReactVersion = '1.2.3';
/**
* Use invariant() to assert state which your program assumes to be true.
*
@@ -246,14 +246,14 @@ Index: build/node_modules/react-dom/umd/react-dom-server.browser.development.js
*
@@ -61,9 +61,9 @@
// preserve the format and params in the www builds.
// TODO: this is special because it gets imported during build.
-var ReactVersion = '16.6.1-canary-b3d1a81a9';
+var ReactVersion = '1.2.3';
var ReactInternals = React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;
var _assign = ReactInternals.assign;
Index: build/node_modules/react-dom/umd/react-dom.production.min.js
===================================================================
@@ -327,12 +327,12 @@ Index: build/node_modules/react-dom/umd/react-dom.development.js
*
@@ -19471,9 +19471,9 @@
}
// TODO: this is special because it gets imported during build.
-var ReactVersion = '16.6.1-canary-b3d1a81a9';
+var ReactVersion = '1.2.3';
// TODO: This type is shared between the reconciler and ReactDOM, but will
// eventually be lifted out to the renderer.
var ReactCurrentOwner = ReactSharedInternals.ReactCurrentOwner;
@@ -407,12 +407,12 @@ Index: build/node_modules/react-dom/cjs/react-dom-server.browser.development.js
*
@@ -65,9 +65,9 @@
// preserve the format and params in the www builds.
// TODO: this is special because it gets imported during build.
-var ReactVersion = '16.6.1-canary-b3d1a81a9';
+var ReactVersion = '1.2.3';
/**
* Similar to invariant but only logs a warning if the condition is not met.
* This can be used to log issues in development environments in critical
@@ -467,12 +467,12 @@ Index: build/node_modules/react-dom/cjs/react-dom-server.node.development.js
*
@@ -21,9 +21,9 @@
var stream = require('stream');
// TODO: this is special because it gets imported during build.
-var ReactVersion = '16.6.1-canary-b3d1a81a9';
+var ReactVersion = '1.2.3';
/**
* Use invariant() to assert state which your program assumes to be true.
*
@@ -511,12 +511,12 @@ Index: build/node_modules/react-dom/cjs/react-dom.development.js
*
@@ -19347,9 +19347,9 @@
}
// TODO: this is special because it gets imported during build.
-var ReactVersion = '16.6.1-canary-b3d1a81a9';
+var ReactVersion = '1.2.3';
// TODO: This type is shared between the reconciler and ReactDOM, but will
// eventually be lifted out to the renderer.
var ReactCurrentOwner = ReactSharedInternals.ReactCurrentOwner;
@@ -694,14 +694,14 @@ Index: build/node_modules/react-test-renderer/umd/react-test-renderer.developmen
*
@@ -11622,9 +11622,9 @@
}
// TODO: this is special because it gets imported during build.
-var ReactVersion = '16.6.1-canary-b3d1a81a9';
+var ReactVersion = '1.2.3';
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
Index: build/node_modules/react-test-renderer/umd/react-test-renderer.production.min.js
===================================================================
@@ -717,8 +717,8 @@ Index: build/node_modules/react-test-renderer/umd/react-test-renderer.production
@@ -117,5 +117,5 @@
!0===b.unstable_isConcurrent&&(d=!0));var e={children:[],createNodeMock:c,tag:"CONTAINER"},g=Gd(e,d,!1);null==g?n("215"):void 0;ac(a,g,null,null);a={root:void 0,toJSON:function(){if(null==g||null==g.current||null==e||0===e.children.length)return null;if(1===e.children.length)return bc(e.children[0]);var a=null;if(e.children&&e.children.length)for(var b=0;b<e.children.length;b++){var c=bc(e.children[b]);null!==c&&(null===a?a=[c]:a.push(c))}return a},toTree:function(){return null==g||null==g.current?
null:sb(g.current)},update:function(a){null!=g&&null!=g.current&&ac(a,g,null,null)},unmount:function(){null!=g&&null!=g.current&&(ac(null,g,null,null),g=e=null)},getInstance:function(){if(null==g||null==g.current)return null;a:{var a=g.current;if(a.child)switch(a.child.tag){case 5:a=Ra(a.child.stateNode);break a;default:a=a.child.stateNode}else a=null}return a},unstable_flushAll:Ad,unstable_flushSync:function(a){Ab();a:{la?n("187"):void 0;var b=ob;ob=!0;try{b:{var c=Ia;Ia=1073741823;try{var d=a(void 0,
void 0,void 0,void 0);break b}finally{Ia=c}d=void 0}break a}finally{ob=b,mb(1073741823,!1)}d=void 0}return d},unstable_flushNumberOfYields:Bd,unstable_clearYields:Ab};Object.defineProperty(a,"root",{configurable:!0,enumerable:!0,get:function(){if(null===g)throw Error("Can't access .root on unmounted test renderer");var a=cc(g.current);if(0===a.length)throw Error("Can't access .root on unmounted test renderer");return 1===a.length?a[0]:ec(g.current)}});return a},unstable_yield:function(a){I.push(a)},
unstable_clearYields:Ab,unstable_batchedUpdates:function(a,b){if(jc)return a(b);jc=!0;try{return a(b)}finally{if(jc=!1,(null!==ub||null!==ic)&&ub&&(b=ub,a=ic,ic=ub=null,td(b),a))for(b=0;b<a.length;b++)td(a[b])}},unstable_setNowImplementation:function(a){jb=a}},gc=new WeakMap;(function(a){var b=a.findFiberByHostInstance;return Dd(V({},a,{findHostInstanceByFiber:function(a){a=zd(a);return null===a?null:a.stateNode},findFiberByHostInstance:function(a){return b?b(a):null}}))})({findFiberByHostInstance:function(){throw Error("TestRenderer does not support findFiberByHostInstance()");
void 0,void 0,void 0);break b}finally{Ia=c}d=void 0}break a}finally{ob=b,mb(1073741823,!1)}d=void 0}return d},unstable_flushNumberOfYields:Bd,unstable_clearLog:Ab};Object.defineProperty(a,"root",{configurable:!0,enumerable:!0,get:function(){if(null===g)throw Error("Can't access .root on unmounted test renderer");var a=cc(g.current);if(0===a.length)throw Error("Can't access .root on unmounted test renderer");return 1===a.length?a[0]:ec(g.current)}});return a},unstable_yield:function(a){I.push(a)},
unstable_clearLog:Ab,unstable_batchedUpdates:function(a,b){if(jc)return a(b);jc=!0;try{return a(b)}finally{if(jc=!1,(null!==ub||null!==ic)&&ub&&(b=ub,a=ic,ic=ub=null,td(b),a))for(b=0;b<a.length;b++)td(a[b])}},unstable_setNowImplementation:function(a){jb=a}},gc=new WeakMap;(function(a){var b=a.findFiberByHostInstance;return Dd(V({},a,{findHostInstanceByFiber:function(a){a=zd(a);return null===a?null:a.stateNode},findFiberByHostInstance:function(a){return b?b(a):null}}))})({findFiberByHostInstance:function(){throw Error("TestRenderer does not support findFiberByHostInstance()");
-},bundleType:0,version:"16.6.1-canary-b3d1a81a9",rendererPackageName:"react-test-renderer"});var xd={default:wd},yd=xd&&wd||xd;return yd.default||yd});
+},bundleType:0,version:"1.2.3",rendererPackageName:"react-test-renderer"});var xd={default:wd},yd=xd&&wd||xd;return yd.default||yd});
Index: build/node_modules/react-test-renderer/cjs/react-test-renderer-shallow.development.js
@@ -756,14 +756,14 @@ Index: build/node_modules/react-test-renderer/cjs/react-test-renderer.developmen
*
@@ -11498,9 +11498,9 @@
}
// TODO: this is special because it gets imported during build.
-var ReactVersion = '16.6.1-canary-b3d1a81a9';
+var ReactVersion = '1.2.3';
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
Index: build/node_modules/react-test-renderer/cjs/react-test-renderer.production.min.js
===================================================================
@@ -779,8 +779,8 @@ Index: build/node_modules/react-test-renderer/cjs/react-test-renderer.production
@@ -140,5 +140,5 @@
var $d={create:function(a,b){var c=Nd.createNodeMock,d=!1;"object"===typeof b&&null!==b&&("function"===typeof b.createNodeMock&&(c=b.createNodeMock),!0===b.unstable_isConcurrent&&(d=!0));var e={children:[],createNodeMock:c,tag:"CONTAINER"},g=eb(e,d,!1);null==g?n("215"):void 0;Hd(a,g,null,null);a={root:void 0,toJSON:function(){if(null==g||null==g.current||null==e||0===e.children.length)return null;if(1===e.children.length)return Od(e.children[0]);var a=null;if(e.children&&e.children.length)for(var b=
0;b<e.children.length;b++){var c=Od(e.children[b]);null!==c&&(null===a?a=[c]:a.push(c))}return a},toTree:function(){return null==g||null==g.current?null:Sd(g.current)},update:function(a){null!=g&&null!=g.current&&Hd(a,g,null,null)},unmount:function(){null!=g&&null!=g.current&&(Hd(null,g,null,null),g=e=null)},getInstance:function(){if(null==g||null==g.current)return null;a:{var a=g.current;if(a.child)switch(a.child.tag){case 5:a=Ea(a.child.stateNode);break a;default:a=a.child.stateNode}else a=null}return a},
unstable_flushAll:za,unstable_flushSync:function(a){Ba();a:{pd?n("187"):void 0;var b=sd;sd=!0;try{b:{var c=Vc;Vc=1073741823;try{var d=a(void 0,void 0,void 0,void 0);break b}finally{Vc=c}d=void 0}break a}finally{sd=b,Dd(1073741823,!1)}d=void 0}return d},unstable_flushNumberOfYields:Aa,unstable_clearYields:Ba};Object.defineProperty(a,"root",{configurable:!0,enumerable:!0,get:function(){if(null===g)throw Error("Can't access .root on unmounted test renderer");var a=Vd(g.current);if(0===a.length)throw Error("Can't access .root on unmounted test renderer");
return 1===a.length?a[0]:Wd(g.current)}});return a},unstable_yield:function(a){D.push(a)},unstable_clearYields:Ba,unstable_batchedUpdates:function(a,b){if(Ld)return a(b);Ld=!0;try{return a(b)}finally{if(Ld=!1,(null!==Id||null!==Jd)&&Id&&(b=Id,a=Jd,Jd=Id=null,Kd(b),a))for(b=0;b<a.length;b++)Kd(a[b])}},unstable_setNowImplementation:function(a){wa=a}},ae=new WeakMap;function Wd(a){var b=ae.get(a);void 0===b&&null!==a.alternate&&(b=ae.get(a.alternate));void 0===b&&(b=new Zd(a),ae.set(a,b));return b}
unstable_flushAll:za,unstable_flushSync:function(a){Ba();a:{pd?n("187"):void 0;var b=sd;sd=!0;try{b:{var c=Vc;Vc=1073741823;try{var d=a(void 0,void 0,void 0,void 0);break b}finally{Vc=c}d=void 0}break a}finally{sd=b,Dd(1073741823,!1)}d=void 0}return d},unstable_flushNumberOfYields:Aa,unstable_clearLog:Ba};Object.defineProperty(a,"root",{configurable:!0,enumerable:!0,get:function(){if(null===g)throw Error("Can't access .root on unmounted test renderer");var a=Vd(g.current);if(0===a.length)throw Error("Can't access .root on unmounted test renderer");
return 1===a.length?a[0]:Wd(g.current)}});return a},unstable_yield:function(a){D.push(a)},unstable_clearLog:Ba,unstable_batchedUpdates:function(a,b){if(Ld)return a(b);Ld=!0;try{return a(b)}finally{if(Ld=!1,(null!==Id||null!==Jd)&&Id&&(b=Id,a=Jd,Jd=Id=null,Kd(b),a))for(b=0;b<a.length;b++)Kd(a[b])}},unstable_setNowImplementation:function(a){wa=a}},ae=new WeakMap;function Wd(a){var b=ae.get(a);void 0===b&&null!==a.alternate&&(b=ae.get(a.alternate));void 0===b&&(b=new Zd(a),ae.set(a,b));return b}
-(function(a){var b=a.findFiberByHostInstance;return Wa(m({},a,{findHostInstanceByFiber:function(a){a=va(a);return null===a?null:a.stateNode},findFiberByHostInstance:function(a){return b?b(a):null}}))})({findFiberByHostInstance:function(){throw Error("TestRenderer does not support findFiberByHostInstance()");},bundleType:0,version:"16.6.1-canary-b3d1a81a9",rendererPackageName:"react-test-renderer"});var be={default:$d},ce=be&&$d||be;module.exports=ce.default||ce;
+(function(a){var b=a.findFiberByHostInstance;return Wa(m({},a,{findHostInstanceByFiber:function(a){a=va(a);return null===a?null:a.stateNode},findFiberByHostInstance:function(a){return b?b(a):null}}))})({findFiberByHostInstance:function(){throw Error("TestRenderer does not support findFiberByHostInstance()");},bundleType:0,version:"1.2.3",rendererPackageName:"react-test-renderer"});var be={default:$d},ce=be&&$d||be;module.exports=ce.default||ce;
Index: build/node_modules/scheduler/cjs/scheduler.development.js