@samitouri / QOS-React-2 / commits / d54be90be6

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.

Andrew Clark committed Aug 20, 2021 at 09:56 UTC d54be90be658afca13c3f882ff28de14e0bd35ad
5 files changed +43 -2
packages/scheduler/src/SchedulerFeatureFlags.js
+1 -1
@@ -8,4 +8,4 @@
8
9 export const enableSchedulerDebugging = false;
10 export const enableIsInputPending = false;
11 -export const enableProfiling = __VARIANT__;
11 +export const enableProfiling = false;
packages/scheduler/src/forks/SchedulerFeatureFlags.www-dynamic.js new
+17
@@ -0,0 +1,17 @@
1 +/**
2 + * Copyright (c) Facebook, Inc. and its affiliates.
3 + *
4 + * This source code is licensed under the MIT license found in the
5 + * LICENSE file in the root directory of this source tree.
6 + *
7 + */
8 +
9 +// In www, these flags are controlled by GKs. Because most GKs have some
10 +// population running in either mode, we should run our tests that way, too,
11 +//
12 +// Use __VARIANT__ to simulate a GK. The tests will be run twice: once
13 +// with the __VARIANT__ set to `true`, and once set to `false`.
14 +
15 +export const enableIsInputPending = __VARIANT__;
16 +export const enableSchedulerDebugging = __VARIANT__;
17 +export const enableProfiling = __VARIANT__;
packages/scheduler/src/forks/SchedulerFeatureFlags.www.js
+4 -1
@@ -6,10 +6,13 @@
6 *
7 */
8
9 +const dynamicFeatureFlags = require('SchedulerFeatureFlags');
10 +
11 +// Re-export dynamic flags from the www version.
12 export const {
13 enableIsInputPending,
14 enableSchedulerDebugging,
15 enableProfiling: enableProfilingFeatureFlag,
13 -} = require('SchedulerFeatureFlags');
16 +} = dynamicFeatureFlags;
17
18 export const enableProfiling = __PROFILE__ && enableProfilingFeatureFlag;
scripts/jest/TestFlags.js
+6
@@ -57,6 +57,7 @@ function getTestFlags() {
57 // These are required on demand because some of our tests mutate them. We try
58 // not to but there are exceptions.
59 const featureFlags = require('shared/ReactFeatureFlags');
60 + const schedulerFeatureFlags = require('scheduler/src/SchedulerFeatureFlags');
61
62 const www = global.__WWW__ === true;
63 const releaseChannel = www
@@ -81,6 +82,11 @@ function getTestFlags() {
82 source: !process.env.IS_BUILD,
83 www,
84
85 + // If there's a naming conflict between scheduler and React feature flags, the
86 + // React ones take precedence.
87 + // TODO: Maybe we should error on conflicts? Or we could namespace
88 + // the flags
89 + ...schedulerFeatureFlags,
90 ...featureFlags,
91 ...environmentFlags,
92 },
scripts/jest/setupTests.www.js
+15
@@ -19,4 +19,19 @@ jest.mock('shared/ReactFeatureFlags', () => {
19 return wwwFlags;
20 });
21
22 +jest.mock('scheduler/src/SchedulerFeatureFlags', () => {
23 + const schedulerSrcPath = process.cwd() + '/packages/scheduler';
24 + jest.mock(
25 + 'SchedulerFeatureFlags',
26 + () =>
27 + jest.requireActual(
28 + schedulerSrcPath + '/src/forks/SchedulerFeatureFlags.www-dynamic'
29 + ),
30 + {virtual: true}
31 + );
32 + return jest.requireActual(
33 + schedulerSrcPath + '/src/forks/SchedulerFeatureFlags.www'
34 + );
35 +});
36 +
37 global.__WWW__ = true;