Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a clear error when renderers clash in tests #12867

Merged
merged 1 commit into from
May 21, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
29 changes: 24 additions & 5 deletions scripts/jest/setupHostConfigs.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,32 @@ inlinedHostConfigs.forEach(rendererInfo => {
return;
}
jest.mock(`react-reconciler/inline.${rendererInfo.shortName}`, () => {
jest.mock(shimHostConfigPath, () =>
require.requireActual(
let hasImportedShimmedConfig = false;

// We want the reconciler to pick up the host config for this renderer.
jest.mock(shimHostConfigPath, () => {
hasImportedShimmedConfig = true;
return require.requireActual(
`react-reconciler/src/forks/ReactFiberHostConfig.${
rendererInfo.shortName
}.js`
)
);
return require.requireActual('react-reconciler');
);
});

const renderer = require.requireActual('react-reconciler');
// If the shimmed config factory function above has not run,
// it means this test file loads more than one renderer
// but doesn't reset modules between them. This won't work.
if (!hasImportedShimmedConfig) {
throw new Error(
`Could not import the "${rendererInfo.shortName}" renderer ` +
`in this suite because another renderer has already been ` +
`loaded earlier. Call jest.resetModules() before importing any ` +
`of the following entry points:\n\n` +
rendererInfo.entryPoints.map(entry => ` * ${entry}`)
);
}

return renderer;
});
});