Remove ReactNativeVersionCheck __DEV__ gating, print error instead of throwing
Reviewed By: cblappert Differential Revision: D6192020 fbshipit-source-id: 026f376d6d43ab3de188f94f2a4d5f0cf485733c
This commit is contained in:
parent
870f540336
commit
1dca01b532
|
@ -126,10 +126,8 @@ if (!global.__fbDisableExceptionsManager) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check for compatibility between the JS and native code
|
// Check for compatibility between the JS and native code
|
||||||
if (__DEV__) {
|
const ReactNativeVersionCheck = require('ReactNativeVersionCheck');
|
||||||
const ReactNativeVersionCheck = require('ReactNativeVersionCheck');
|
ReactNativeVersionCheck.checkVersions();
|
||||||
ReactNativeVersionCheck.checkVersions();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Set up Promise
|
// Set up Promise
|
||||||
// The native Promise implementation throws the following error:
|
// The native Promise implementation throws the following error:
|
||||||
|
|
|
@ -34,7 +34,7 @@ exports.checkVersions = function checkVersions(): void {
|
||||||
ReactNativeVersion.version.major !== nativeVersion.major ||
|
ReactNativeVersion.version.major !== nativeVersion.major ||
|
||||||
ReactNativeVersion.version.minor !== nativeVersion.minor
|
ReactNativeVersion.version.minor !== nativeVersion.minor
|
||||||
) {
|
) {
|
||||||
throw new Error(
|
console.error(
|
||||||
`React Native version mismatch.\n\nJavaScript version: ${_formatVersion(
|
`React Native version mismatch.\n\nJavaScript version: ${_formatVersion(
|
||||||
ReactNativeVersion.version,
|
ReactNativeVersion.version,
|
||||||
)}\n` +
|
)}\n` +
|
||||||
|
|
|
@ -36,8 +36,24 @@ function _setDevelopmentModeForTests(dev) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function _defineCheckVersionTests() {
|
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(() => {
|
afterEach(() => {
|
||||||
jest.resetModules();
|
jest.resetModules();
|
||||||
|
console.error = consoleError;
|
||||||
|
global.console = globalConsole;
|
||||||
|
spyOnConsoleError.mockReset();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('passes when all the versions are zero', () => {
|
it('passes when all the versions are zero', () => {
|
||||||
|
@ -60,40 +76,43 @@ function _defineCheckVersionTests() {
|
||||||
expect(() => ReactNativeVersionCheck.checkVersions()).not.toThrow();
|
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);
|
_mockJsVersion(0, 1, 0);
|
||||||
_mockNativeVersion(0, 2, 0);
|
_mockNativeVersion(0, 2, 0);
|
||||||
|
|
||||||
const ReactNativeVersionCheck = require('ReactNativeVersionCheck');
|
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);
|
_mockJsVersion(1, 0, 0);
|
||||||
_mockNativeVersion(2, 0, 0);
|
_mockNativeVersion(2, 0, 0);
|
||||||
|
|
||||||
const ReactNativeVersionCheck = require('ReactNativeVersionCheck');
|
const ReactNativeVersionCheck = require('ReactNativeVersionCheck');
|
||||||
expect(() => ReactNativeVersionCheck.checkVersions()).toThrowError(
|
ReactNativeVersionCheck.checkVersions();
|
||||||
/React Native version mismatch/,
|
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);
|
_mockJsVersion(0, 1, 0);
|
||||||
_mockNativeVersion(0, 1, 2);
|
_mockNativeVersion(0, 1, 2);
|
||||||
|
|
||||||
const ReactNativeVersionCheck = require('ReactNativeVersionCheck');
|
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');
|
_mockJsVersion(0, 1, 0, 'beta.0');
|
||||||
_mockNativeVersion(0, 1, 0, 'alpha.1');
|
_mockNativeVersion(0, 1, 0, 'alpha.1');
|
||||||
|
|
||||||
const ReactNativeVersionCheck = require('ReactNativeVersionCheck');
|
const ReactNativeVersionCheck = require('ReactNativeVersionCheck');
|
||||||
expect(() => ReactNativeVersionCheck.checkVersions()).not.toThrow();
|
ReactNativeVersionCheck.checkVersions();
|
||||||
|
expect(spyOnConsoleError).toHaveBeenCalledTimes(0);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue