@samitouri / QOS-React / commits / 0442e8275f

Add a clear error when renderers clash in tests (#12867)

Dan Abramov committed May 21, 2018 at 15:38 UTC 0442e8275f02d500cdc2e8b8b703286a67d7ad1d
1 file changed +24 -5
scripts/jest/setupHostConfigs.js
+24 -5
@@ -27,13 +27,32 @@ inlinedHostConfigs.forEach(rendererInfo => {
27 return;
28 }
29 jest.mock(`react-reconciler/inline.${rendererInfo.shortName}`, () => {
30 - jest.mock(shimHostConfigPath, () =>
31 - require.requireActual(
30 + let hasImportedShimmedConfig = false;
31 +
32 + // We want the reconciler to pick up the host config for this renderer.
33 + jest.mock(shimHostConfigPath, () => {
34 + hasImportedShimmedConfig = true;
35 + return require.requireActual(
36 `react-reconciler/src/forks/ReactFiberHostConfig.${
37 rendererInfo.shortName
38 }.js`
35 - )
36 - );
37 - return require.requireActual('react-reconciler');
39 + );
40 + });
41 +
42 + const renderer = require.requireActual('react-reconciler');
43 + // If the shimmed config factory function above has not run,
44 + // it means this test file loads more than one renderer
45 + // but doesn't reset modules between them. This won't work.
46 + if (!hasImportedShimmedConfig) {
47 + throw new Error(
48 + `Could not import the "${rendererInfo.shortName}" renderer ` +
49 + `in this suite because another renderer has already been ` +
50 + `loaded earlier. Call jest.resetModules() before importing any ` +
51 + `of the following entry points:\n\n` +
52 + rendererInfo.entryPoints.map(entry => ` * ${entry}`)
53 + );
54 + }
55 +
56 + return renderer;
57 });
58 });