Skip to content

Commit 1e184e7

Browse files
acdlitezhengjitf
authored andcommitted
Set up test infra for dynamic Scheduler flags (facebook#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.
1 parent a93f5a5 commit 1e184e7

File tree

5 files changed

+43
-2
lines changed

5 files changed

+43
-2
lines changed

packages/scheduler/src/SchedulerFeatureFlags.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@
88

99
export const enableSchedulerDebugging = false;
1010
export const enableIsInputPending = false;
11-
export const enableProfiling = __VARIANT__;
11+
export const enableProfiling = false;
Original file line numberDiff line numberDiff line change
@@ -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
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,13 @@
66
*
77
*/
88

9+
const dynamicFeatureFlags = require('SchedulerFeatureFlags');
10+
11+
// Re-export dynamic flags from the www version.
912
export const {
1013
enableIsInputPending,
1114
enableSchedulerDebugging,
1215
enableProfiling: enableProfilingFeatureFlag,
13-
} = require('SchedulerFeatureFlags');
16+
} = dynamicFeatureFlags;
1417

1518
export const enableProfiling = __PROFILE__ && enableProfilingFeatureFlag;

scripts/jest/TestFlags.js

+6
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ function getTestFlags() {
5757
// These are required on demand because some of our tests mutate them. We try
5858
// not to but there are exceptions.
5959
const featureFlags = require('shared/ReactFeatureFlags');
60+
const schedulerFeatureFlags = require('scheduler/src/SchedulerFeatureFlags');
6061

6162
const www = global.__WWW__ === true;
6263
const releaseChannel = www
@@ -81,6 +82,11 @@ function getTestFlags() {
8182
source: !process.env.IS_BUILD,
8283
www,
8384

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,
8490
...featureFlags,
8591
...environmentFlags,
8692
},

scripts/jest/setupTests.www.js

+15
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,19 @@ jest.mock('shared/ReactFeatureFlags', () => {
1919
return wwwFlags;
2020
});
2121

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+
2237
global.__WWW__ = true;

0 commit comments

Comments
 (0)