Skip to content

Commit a7bd7c3

Browse files
authored
Allow reading default feature flags from bundle tests (#13629)
1 parent 7204b63 commit a7bd7c3

File tree

3 files changed

+23
-3
lines changed

3 files changed

+23
-3
lines changed

packages/shared/ReactFeatureFlags.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77
* @flow strict
88
*/
99

10-
import invariant from 'shared/invariant';
11-
1210
// Exports ReactDOM.createRoot
1311
export const enableUserTimingAPI = __DEV__;
1412

@@ -47,5 +45,5 @@ export const enableSuspenseServerRenderer = false;
4745

4846
// Only used in www builds.
4947
export function addUserTimingListener() {
50-
invariant(false, 'Not implemented.');
48+
throw new Error('Not implemented.');
5149
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
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+
// This is only used by bundle tests so they can *read* the default feature flags.
9+
// It lets us determine whether we're running in Fire mode without making tests internal.
10+
const ReactFeatureFlags = require('../ReactFeatureFlags');
11+
// Forbid writes because this wouldn't work with bundle tests.
12+
module.exports = Object.freeze({...ReactFeatureFlags});

scripts/jest/config.build.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,18 @@ const packages = readdirSync(packagesRoot).filter(dir => {
1818
const packagePath = join(packagesRoot, dir, 'package.json');
1919
return statSync(packagePath).isFile();
2020
});
21+
2122
// Create a module map to point React packages to the build output
2223
const moduleNameMapper = {};
24+
25+
// Allow bundle tests to read (but not write!) default feature flags.
26+
// This lets us determine whether we're running in Fire mode
27+
// without making relevant tests internal-only.
28+
moduleNameMapper[
29+
'^shared/ReactFeatureFlags'
30+
] = `<rootDir>/packages/shared/forks/ReactFeatureFlags.readonly`;
31+
32+
// Map packages to bundles
2333
packages.forEach(name => {
2434
// Root entry point
2535
moduleNameMapper[`^${name}$`] = `<rootDir>/build/node_modules/${name}`;

0 commit comments

Comments
 (0)