Skip to content

Define global __WWW__ = true flag during www tests #21504

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;