Skip to content

Commit

Permalink
Set up test infra for dynamic Scheduler flags (facebook#22139)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
acdlite authored and zhengjitf committed Apr 15, 2022
1 parent a93f5a5 commit 1e184e7
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 2 deletions.
2 changes: 1 addition & 1 deletion packages/scheduler/src/SchedulerFeatureFlags.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@

export const enableSchedulerDebugging = false;
export const enableIsInputPending = false;
export const enableProfiling = __VARIANT__;
export const enableProfiling = false;
17 changes: 17 additions & 0 deletions packages/scheduler/src/forks/SchedulerFeatureFlags.www-dynamic.js
Original file line number Diff line number Diff line change
@@ -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__;
5 changes: 4 additions & 1 deletion packages/scheduler/src/forks/SchedulerFeatureFlags.www.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
6 changes: 6 additions & 0 deletions scripts/jest/TestFlags.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
},
Expand Down
15 changes: 15 additions & 0 deletions scripts/jest/setupTests.www.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

0 comments on commit 1e184e7

Please sign in to comment.