Remove ReactNativeVersionCheck __DEV__ gating, print error instead of throwing

Reviewed By: cblappert

Differential Revision: D6192020

fbshipit-source-id: 026f376d6d43ab3de188f94f2a4d5f0cf485733c
This commit is contained in:
Héctor Ramos Ortiz 2017-10-31 14:18:00 -07:00 committed by Facebook Github Bot
parent 870f540336
commit 1dca01b532
3 changed files with 34 additions and 17 deletions

View File

@ -126,10 +126,8 @@ if (!global.__fbDisableExceptionsManager) {
}
// Check for compatibility between the JS and native code
if (__DEV__) {
const ReactNativeVersionCheck = require('ReactNativeVersionCheck');
ReactNativeVersionCheck.checkVersions();
}
const ReactNativeVersionCheck = require('ReactNativeVersionCheck');
ReactNativeVersionCheck.checkVersions();
// Set up Promise
// The native Promise implementation throws the following error:

View File

@ -34,7 +34,7 @@ exports.checkVersions = function checkVersions(): void {
ReactNativeVersion.version.major !== nativeVersion.major ||
ReactNativeVersion.version.minor !== nativeVersion.minor
) {
throw new Error(
console.error(
`React Native version mismatch.\n\nJavaScript version: ${_formatVersion(
ReactNativeVersion.version,
)}\n` +

View File

@ -36,8 +36,24 @@ function _setDevelopmentModeForTests(dev) {
}
function _defineCheckVersionTests() {
const consoleError = console.error;
const globalConsole = global.console;
let spyOnConsoleError;
let consoleOutput;
beforeEach(() => {
consoleOutput = '';
console.error = jest.fn();
global.console = {error: jest.fn(error => (consoleOutput += error))};
spyOnConsoleError = jest.spyOn(global.console, 'error');
});
afterEach(() => {
jest.resetModules();
console.error = consoleError;
global.console = globalConsole;
spyOnConsoleError.mockReset();
});
it('passes when all the versions are zero', () => {
@ -60,40 +76,43 @@ function _defineCheckVersionTests() {
expect(() => ReactNativeVersionCheck.checkVersions()).not.toThrow();
});
it("throws when the minor doesn't match when the major is zero", () => {
it("logs error when the minor doesn't match when the major is zero", () => {
_mockJsVersion(0, 1, 0);
_mockNativeVersion(0, 2, 0);
const ReactNativeVersionCheck = require('ReactNativeVersionCheck');
expect(() => ReactNativeVersionCheck.checkVersions()).toThrowError(
/React Native version mismatch/,
);
ReactNativeVersionCheck.checkVersions();
expect(spyOnConsoleError).toHaveBeenCalledTimes(1);
expect(consoleOutput).toMatch(/React Native version mismatch/);
});
it("throws when the major doesn't match", () => {
it("logs error when the major doesn't match", () => {
_mockJsVersion(1, 0, 0);
_mockNativeVersion(2, 0, 0);
const ReactNativeVersionCheck = require('ReactNativeVersionCheck');
expect(() => ReactNativeVersionCheck.checkVersions()).toThrowError(
/React Native version mismatch/,
);
ReactNativeVersionCheck.checkVersions();
expect(spyOnConsoleError).toHaveBeenCalledTimes(1);
expect(consoleOutput).toMatch(/React Native version mismatch/);
});
it("doesn't throw if the patch doesn't match", () => {
it("doesn't log error if the patch doesn't match", () => {
_mockJsVersion(0, 1, 0);
_mockNativeVersion(0, 1, 2);
const ReactNativeVersionCheck = require('ReactNativeVersionCheck');
expect(() => ReactNativeVersionCheck.checkVersions()).not.toThrow();
ReactNativeVersionCheck.checkVersions();
expect(spyOnConsoleError).toHaveBeenCalledTimes(0);
});
it("doesn't throw if the prerelease doesn't match", () => {
it("doesn't log error if the prerelease doesn't match", () => {
_mockJsVersion(0, 1, 0, 'beta.0');
_mockNativeVersion(0, 1, 0, 'alpha.1');
const ReactNativeVersionCheck = require('ReactNativeVersionCheck');
expect(() => ReactNativeVersionCheck.checkVersions()).not.toThrow();
ReactNativeVersionCheck.checkVersions();
expect(spyOnConsoleError).toHaveBeenCalledTimes(0);
});
}