Set up test infra for dynamic Scheduler flags (#22139)

I copied the set up we use for React.

In the www-variant test job, the Scheduler `__VARIANT__` flags will be
`true`. When writing a test, we can read the value of the flag with the
`gate` pragma and method.

Note: Since these packages are currently released in lockstep, maybe we
should remove SchedulerFeatureFlags and use ReactFeatureFlags for both.
This commit is contained in:
Andrew Clark 2021-08-20 09:56:20 -04:00 committed by GitHub
parent 64f83a6fd2
commit d54be90be6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 43 additions and 2 deletions

View File

@ -8,4 +8,4 @@
export const enableSchedulerDebugging = false;
export const enableIsInputPending = false;
export const enableProfiling = __VARIANT__;
export const enableProfiling = false;

View File

@ -0,0 +1,17 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
*/
// In www, these flags are controlled by GKs. Because most GKs have some
// population running in either mode, we should run our tests that way, too,
//
// Use __VARIANT__ to simulate a GK. The tests will be run twice: once
// with the __VARIANT__ set to `true`, and once set to `false`.
export const enableIsInputPending = __VARIANT__;
export const enableSchedulerDebugging = __VARIANT__;
export const enableProfiling = __VARIANT__;

View File

@ -6,10 +6,13 @@
*
*/
const dynamicFeatureFlags = require('SchedulerFeatureFlags');
// Re-export dynamic flags from the www version.
export const {
enableIsInputPending,
enableSchedulerDebugging,
enableProfiling: enableProfilingFeatureFlag,
} = require('SchedulerFeatureFlags');
} = dynamicFeatureFlags;
export const enableProfiling = __PROFILE__ && enableProfilingFeatureFlag;

View File

@ -57,6 +57,7 @@ function getTestFlags() {
// These are required on demand because some of our tests mutate them. We try
// not to but there are exceptions.
const featureFlags = require('shared/ReactFeatureFlags');
const schedulerFeatureFlags = require('scheduler/src/SchedulerFeatureFlags');
const www = global.__WWW__ === true;
const releaseChannel = www
@ -81,6 +82,11 @@ function getTestFlags() {
source: !process.env.IS_BUILD,
www,
// If there's a naming conflict between scheduler and React feature flags, the
// React ones take precedence.
// TODO: Maybe we should error on conflicts? Or we could namespace
// the flags
...schedulerFeatureFlags,
...featureFlags,
...environmentFlags,
},

View File

@ -19,4 +19,19 @@ jest.mock('shared/ReactFeatureFlags', () => {
return wwwFlags;
});
jest.mock('scheduler/src/SchedulerFeatureFlags', () => {
const schedulerSrcPath = process.cwd() + '/packages/scheduler';
jest.mock(
'SchedulerFeatureFlags',
() =>
jest.requireActual(
schedulerSrcPath + '/src/forks/SchedulerFeatureFlags.www-dynamic'
),
{virtual: true}
);
return jest.requireActual(
schedulerSrcPath + '/src/forks/SchedulerFeatureFlags.www'
);
});
global.__WWW__ = true;