From efbd69b27e530cb26f0c055265a624242a32305b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Markb=C3=A5ge?= Date: Tue, 1 Jun 2021 13:16:06 -0400 Subject: [PATCH] Define global __WWW__ = true flag during www tests (#21504) * Define global __WWW__ = true flag during www tests We already do that for __PERSISTENT__. * Use @gate www in ReactSuspenseCallback This allows it to not be internal anymore. We test it against the www build. --- ...ernal.js => ReactSuspenseCallback-test.js} | 52 ++++++++++--------- scripts/jest/TestFlags.js | 5 +- scripts/jest/config.source-www.js | 2 +- scripts/jest/setupTests.www.js | 2 + 4 files changed, 31 insertions(+), 30 deletions(-) rename packages/react-reconciler/src/__tests__/{ReactSuspenseCallback-test.internal.js => ReactSuspenseCallback-test.js} (89%) diff --git a/packages/react-reconciler/src/__tests__/ReactSuspenseCallback-test.internal.js b/packages/react-reconciler/src/__tests__/ReactSuspenseCallback-test.js similarity index 89% rename from packages/react-reconciler/src/__tests__/ReactSuspenseCallback-test.internal.js rename to packages/react-reconciler/src/__tests__/ReactSuspenseCallback-test.js index 2314ef0c47ada..38f32c9f494de 100644 --- a/packages/react-reconciler/src/__tests__/ReactSuspenseCallback-test.internal.js +++ b/packages/react-reconciler/src/__tests__/ReactSuspenseCallback-test.js @@ -10,15 +10,12 @@ 'use strict'; let React; -let ReactFeatureFlags; let ReactNoop; let Scheduler; describe('ReactSuspense', () => { beforeEach(() => { jest.resetModules(); - ReactFeatureFlags = require('shared/ReactFeatureFlags'); - ReactFeatureFlags.enableSuspenseCallback = true; React = require('react'); ReactNoop = require('react-noop-renderer'); @@ -47,30 +44,34 @@ describe('ReactSuspense', () => { return {promise, resolve, PromiseComp}; } - it('check type', () => { - const {PromiseComp} = createThenable(); + if (__DEV__) { + // @gate www + it('check type', () => { + const {PromiseComp} = createThenable(); - const elementBadType = ( - - - - ); + const elementBadType = ( + + + + ); - ReactNoop.render(elementBadType); - expect(() => Scheduler.unstable_flushAll()).toErrorDev([ - 'Warning: Unexpected type for suspenseCallback.', - ]); + ReactNoop.render(elementBadType); + expect(() => Scheduler.unstable_flushAll()).toErrorDev([ + 'Warning: Unexpected type for suspenseCallback.', + ]); - const elementMissingCallback = ( - - - - ); + const elementMissingCallback = ( + + + + ); - ReactNoop.render(elementMissingCallback); - expect(() => Scheduler.unstable_flushAll()).toErrorDev([]); - }); + ReactNoop.render(elementMissingCallback); + expect(() => Scheduler.unstable_flushAll()).toErrorDev([]); + }); + } + // @gate www it('1 then 0 suspense callback', async () => { const {promise, resolve, PromiseComp} = createThenable(); @@ -97,6 +98,7 @@ describe('ReactSuspense', () => { expect(ops).toEqual([]); }); + // @gate www it('2 then 1 then 0 suspense callback', async () => { const { promise: promise1, @@ -143,6 +145,7 @@ describe('ReactSuspense', () => { expect(ops).toEqual([]); }); + // @gate www it('nested suspense promises are reported only for their tier', () => { const {promise, PromiseComp} = createThenable(); @@ -174,6 +177,7 @@ describe('ReactSuspense', () => { expect(ops2).toEqual([new Set([promise])]); }); + // @gate www it('competing suspense promises', async () => { const { promise: promise1, @@ -242,6 +246,7 @@ describe('ReactSuspense', () => { }); if (__DEV__) { + // @gate www it('regression test for #16215 that relies on implementation details', async () => { // Regression test for https://github.com/facebook/react/pull/16215. // The bug only happens if there's an error earlier in the commit phase. @@ -272,9 +277,6 @@ describe('ReactSuspense', () => { }, })); - ReactFeatureFlags = require('shared/ReactFeatureFlags'); - ReactFeatureFlags.enableSuspenseCallback = true; - React = require('react'); ReactNoop = require('react-noop-renderer'); Scheduler = require('scheduler'); diff --git a/scripts/jest/TestFlags.js b/scripts/jest/TestFlags.js index d46a26fb942e9..93ba09dbf0324 100644 --- a/scripts/jest/TestFlags.js +++ b/scripts/jest/TestFlags.js @@ -56,10 +56,7 @@ function getTestFlags() { // not to but there are exceptions. const featureFlags = require('shared/ReactFeatureFlags'); - // TODO: This is a heuristic to detect the release channel by checking a flag - // that is known to only be enabled in www. What we should do instead is set - // the release channel explicitly in the each test config file. - const www = featureFlags.enableSuspenseCallback === true; + const www = global.__WWW__ === true; const releaseChannel = www ? __EXPERIMENTAL__ ? 'modern' diff --git a/scripts/jest/config.source-www.js b/scripts/jest/config.source-www.js index 0d79c83bbebb0..060291a748216 100644 --- a/scripts/jest/config.source-www.js +++ b/scripts/jest/config.source-www.js @@ -30,7 +30,7 @@ module.exports = Object.assign({}, baseConfig, { ], setupFiles: [ ...baseConfig.setupFiles, - require.resolve('./setupHostConfigs.js'), require.resolve('./setupTests.www.js'), + require.resolve('./setupHostConfigs.js'), ], }); diff --git a/scripts/jest/setupTests.www.js b/scripts/jest/setupTests.www.js index de8a70d40be75..3812d8f1354b5 100644 --- a/scripts/jest/setupTests.www.js +++ b/scripts/jest/setupTests.www.js @@ -19,3 +19,5 @@ jest.mock('shared/ReactFeatureFlags', () => { return wwwFlags; }); + +global.__WWW__ = true;