@samitouri / QOS-React / commits / a7bd7c3c04

Allow reading default feature flags from bundle tests (#13629)

Dan Abramov committed Sep 12, 2018 at 16:56 UTC a7bd7c3c0480c96e32d9518bb707172dfc72db58
3 files changed +23 -3
packages/shared/ReactFeatureFlags.js
+1 -3
@@ -7,8 +7,6 @@
7 * @flow strict
8 */
9
10 -import invariant from 'shared/invariant';
11 -
10 // Exports ReactDOM.createRoot
11 export const enableUserTimingAPI = __DEV__;
12
@@ -47,5 +45,5 @@ export const enableSuspenseServerRenderer = false;
45
46 // Only used in www builds.
47 export function addUserTimingListener() {
50 - invariant(false, 'Not implemented.');
48 + throw new Error('Not implemented.');
49 }
packages/shared/forks/ReactFeatureFlags.readonly.js new
+12
@@ -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
+10
@@ -18,8 +18,18 @@ const packages = readdirSync(packagesRoot).filter(dir => {
18 const packagePath = join(packagesRoot, dir, 'package.json');
19 return statSync(packagePath).isFile();
20 });
21 +
22 // Create a module map to point React packages to the build output
23 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
33 packages.forEach(name => {
34 // Root entry point
35 moduleNameMapper[`^${name}$`] = `<rootDir>/build/node_modules/${name}`;