Skip to content

Commit

Permalink
Define global __WWW__ = true flag during www tests (#21504)
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
sebmarkbage committed Jun 1, 2021
1 parent 8f6163c commit efbd69b
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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 = (
<React.Suspense suspenseCallback={1} fallback={'Waiting'}>
<PromiseComp />
</React.Suspense>
);
const elementBadType = (
<React.Suspense suspenseCallback={1} fallback={'Waiting'}>
<PromiseComp />
</React.Suspense>
);

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 = (
<React.Suspense fallback={'Waiting'}>
<PromiseComp />
</React.Suspense>
);
const elementMissingCallback = (
<React.Suspense fallback={'Waiting'}>
<PromiseComp />
</React.Suspense>
);

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();

Expand All @@ -97,6 +98,7 @@ describe('ReactSuspense', () => {
expect(ops).toEqual([]);
});

// @gate www
it('2 then 1 then 0 suspense callback', async () => {
const {
promise: promise1,
Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -174,6 +177,7 @@ describe('ReactSuspense', () => {
expect(ops2).toEqual([new Set([promise])]);
});

// @gate www
it('competing suspense promises', async () => {
const {
promise: promise1,
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -272,9 +277,6 @@ describe('ReactSuspense', () => {
},
}));

ReactFeatureFlags = require('shared/ReactFeatureFlags');
ReactFeatureFlags.enableSuspenseCallback = true;

React = require('react');
ReactNoop = require('react-noop-renderer');
Scheduler = require('scheduler');
Expand Down
5 changes: 1 addition & 4 deletions scripts/jest/TestFlags.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
2 changes: 1 addition & 1 deletion scripts/jest/config.source-www.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
],
});
2 changes: 2 additions & 0 deletions scripts/jest/setupTests.www.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,5 @@ jest.mock('shared/ReactFeatureFlags', () => {

return wwwFlags;
});

global.__WWW__ = true;

0 comments on commit efbd69b

Please sign in to comment.