From a293d75f753b01db2cf47ddbaaae68bb08e755f2 Mon Sep 17 00:00:00 2001 From: Andrew Clark Date: Wed, 1 Mar 2017 12:48:02 -0800 Subject: [PATCH 1/2] Test that ReactErrorUtils module can be shimmed We do this in www --- scripts/fiber/tests-passing.txt | 2 ++ .../utils/__tests__/ReactErrorUtils-test.js | 25 +++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/scripts/fiber/tests-passing.txt b/scripts/fiber/tests-passing.txt index ade485d62d..e8f18715b8 100644 --- a/scripts/fiber/tests-passing.txt +++ b/scripts/fiber/tests-passing.txt @@ -1695,6 +1695,7 @@ src/renderers/shared/utils/__tests__/ReactErrorUtils-test.js * should return null if no error is thrown (development) * can nest with same debug name (development) * does not return nested errors (development) +* can be shimmed (development) * it should rethrow errors caught by invokeGuardedCallbackAndCatchFirstError (production) * should call the callback the passed arguments (production) * should call the callback with the provided context (production) @@ -1702,6 +1703,7 @@ src/renderers/shared/utils/__tests__/ReactErrorUtils-test.js * should return null if no error is thrown (production) * can nest with same debug name (production) * does not return nested errors (production) +* can be shimmed (production) src/renderers/shared/utils/__tests__/accumulateInto-test.js * throws if the second item is null diff --git a/src/renderers/shared/utils/__tests__/ReactErrorUtils-test.js b/src/renderers/shared/utils/__tests__/ReactErrorUtils-test.js index 74069e5900..c540a2bb1e 100644 --- a/src/renderers/shared/utils/__tests__/ReactErrorUtils-test.js +++ b/src/renderers/shared/utils/__tests__/ReactErrorUtils-test.js @@ -106,5 +106,30 @@ describe('ReactErrorUtils', () => { expect(err3).toBe(null); // Returns null because inner error was already captured expect(err2).toBe(err1); }); + + it(`can be shimmed (${environment})`, () => { + const ops = []; + // Override the original invokeGuardedCallback + ReactErrorUtils.invokeGuardedCallback = function(name, func, context, a) { + ops.push(a); + try { + func.call(context, a); + } catch (error) { + return error; + } + return null; + }; + + var err = new Error('foo'); + var callback = function() { + throw err; + }; + ReactErrorUtils.invokeGuardedCallbackAndCatchFirstError('foo', callback, null, 'somearg'); + expect(() => ReactErrorUtils.rethrowCaughtError()).toThrow(err); + // invokeGuardedCallbackAndCatchFirstError and rethrowCaughtError close + // over ReactErrorUtils.invokeGuardedCallback so should use the + // shimmed version. + expect(ops).toEqual(['somearg']); + }); } }); From b1a565f8fa976f7b4b772084ab97b58b7bf28ebf Mon Sep 17 00:00:00 2001 From: Andrew Clark Date: Wed, 1 Mar 2017 14:38:29 -0800 Subject: [PATCH 2/2] Convert shorthanded syntax for function Flow types to expanded form Something in www's test pipeline isn't able to parse this. --- src/renderers/shared/utils/ReactErrorUtils.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/renderers/shared/utils/ReactErrorUtils.js b/src/renderers/shared/utils/ReactErrorUtils.js index c2cd671767..f53bdddc5a 100644 --- a/src/renderers/shared/utils/ReactErrorUtils.js +++ b/src/renderers/shared/utils/ReactErrorUtils.js @@ -26,7 +26,7 @@ let caughtError = null; const ReactErrorUtils = { invokeGuardedCallback: function( name: string | null, - func: (A, B, C, D, E, F) => void, + func: (a: A, b: B, c: C, d: D, e: E, f: F) => void, context: Context, a: A, b: B, @@ -55,7 +55,7 @@ const ReactErrorUtils = { */ invokeGuardedCallbackAndCatchFirstError: function( name: string | null, - func: (A, B, C, D, E, F) => void, + func: (a: A, b: B, c: C, d: D, e: E, f: F) => void, context: Context, a: A, b: B,