Run ExceptionsManager unit tests in both __DEV__ and prod mode
Summary: Changelog: [General][Fixed] - Run ExceptionsManager unit tests in both __DEV__ and prod mode This suite of unittests use a `__DEV__` check in various places to check that the correct data is sent to either LogBox (in __DEV__) or the Native ExceptionsManager (in PROD). However, we're not actually running both modes, so half of the assert branches in these tests aren't ever utilized. This diff uses the same approach as ReactNativeVersionCheck-test.js to execute this test suite twice: Once in DEV and once in PROD mode. Reviewed By: motiz88 Differential Revision: D36099190 fbshipit-source-id: 40b8ea26f1d9e093202f3c3f3b55111110a8d64c
This commit is contained in:
Родитель
5d34c55523
Коммит
a154207371
|
@ -26,7 +26,33 @@ const capturedErrorDefaults = {
|
||||||
willRetry: false,
|
willRetry: false,
|
||||||
};
|
};
|
||||||
|
|
||||||
describe('ExceptionsManager', () => {
|
describe('checkVersion', () => {
|
||||||
|
describe('in development', () => {
|
||||||
|
setDevelopmentModeForTests(true);
|
||||||
|
runExceptionsManagerTests();
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('in production', () => {
|
||||||
|
setDevelopmentModeForTests(false);
|
||||||
|
runExceptionsManagerTests();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
function setDevelopmentModeForTests(dev) {
|
||||||
|
let originalDev;
|
||||||
|
|
||||||
|
beforeAll(() => {
|
||||||
|
originalDev = global.__DEV__;
|
||||||
|
global.__DEV__ = dev;
|
||||||
|
});
|
||||||
|
|
||||||
|
afterAll(() => {
|
||||||
|
global.__DEV__ = originalDev;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function runExceptionsManagerTests() {
|
||||||
|
describe('ExceptionsManager', () => {
|
||||||
let nativeReportException;
|
let nativeReportException;
|
||||||
let logBoxAddException;
|
let logBoxAddException;
|
||||||
|
|
||||||
|
@ -193,7 +219,9 @@ describe('ExceptionsManager', () => {
|
||||||
expect(exceptionData.componentStack).toBe(
|
expect(exceptionData.componentStack).toBe(
|
||||||
capturedErrorDefaults.componentStack,
|
capturedErrorDefaults.componentStack,
|
||||||
);
|
);
|
||||||
expect(exceptionData.stack[0].file).toMatch(/ReactFiberErrorDialog\.js$/);
|
expect(exceptionData.stack[0].file).toMatch(
|
||||||
|
/ReactFiberErrorDialog\.js$/,
|
||||||
|
);
|
||||||
expect(exceptionData.isFatal).toBe(false);
|
expect(exceptionData.isFatal).toBe(false);
|
||||||
expect(logToConsoleInReact).toBe(false);
|
expect(logToConsoleInReact).toBe(false);
|
||||||
expect(console.error).toBeCalledWith(formattedMessage);
|
expect(console.error).toBeCalledWith(formattedMessage);
|
||||||
|
@ -225,7 +253,9 @@ describe('ExceptionsManager', () => {
|
||||||
expect(exceptionData.componentStack).toBe(
|
expect(exceptionData.componentStack).toBe(
|
||||||
capturedErrorDefaults.componentStack,
|
capturedErrorDefaults.componentStack,
|
||||||
);
|
);
|
||||||
expect(exceptionData.stack[0].file).toMatch(/ReactFiberErrorDialog\.js$/);
|
expect(exceptionData.stack[0].file).toMatch(
|
||||||
|
/ReactFiberErrorDialog\.js$/,
|
||||||
|
);
|
||||||
expect(exceptionData.isFatal).toBe(false);
|
expect(exceptionData.isFatal).toBe(false);
|
||||||
expect(logToConsoleInReact).toBe(false);
|
expect(logToConsoleInReact).toBe(false);
|
||||||
expect(console.error).toBeCalledWith(formattedMessage);
|
expect(console.error).toBeCalledWith(formattedMessage);
|
||||||
|
@ -375,7 +405,9 @@ describe('ExceptionsManager', () => {
|
||||||
expect(nativeReportException.mock.calls.length).toBe(1);
|
expect(nativeReportException.mock.calls.length).toBe(1);
|
||||||
exceptionData = nativeReportException.mock.calls[0][0];
|
exceptionData = nativeReportException.mock.calls[0][0];
|
||||||
}
|
}
|
||||||
expect(exceptionData.message).toBe('console.error: Some error happened');
|
expect(exceptionData.message).toBe(
|
||||||
|
'console.error: Some error happened',
|
||||||
|
);
|
||||||
expect(exceptionData.originalMessage).toBe('Some error happened');
|
expect(exceptionData.originalMessage).toBe('Some error happened');
|
||||||
expect(exceptionData.name).toBe('console.error');
|
expect(exceptionData.name).toBe('console.error');
|
||||||
expect(
|
expect(
|
||||||
|
@ -439,7 +471,9 @@ describe('ExceptionsManager', () => {
|
||||||
|
|
||||||
test('logging a warning-looking object', () => {
|
test('logging a warning-looking object', () => {
|
||||||
// Forces `strignifySafe` to invoke `toString()`.
|
// Forces `strignifySafe` to invoke `toString()`.
|
||||||
const object = {toString: () => 'Warning: Some error may have happened'};
|
const object = {
|
||||||
|
toString: () => 'Warning: Some error may have happened',
|
||||||
|
};
|
||||||
object.cycle = object;
|
object.cycle = object;
|
||||||
|
|
||||||
const args = [object];
|
const args = [object];
|
||||||
|
@ -789,7 +823,9 @@ describe('ExceptionsManager', () => {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
expect(mockError).toHaveBeenCalledTimes(1);
|
expect(mockError).toHaveBeenCalledTimes(1);
|
||||||
expect(mockError.mock.calls[0][0]).toMatch(/Error: Some error happened/);
|
expect(mockError.mock.calls[0][0]).toMatch(
|
||||||
|
/Error: Some error happened/,
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('can handle throwing decorators recursion when exception is logged', () => {
|
test('can handle throwing decorators recursion when exception is logged', () => {
|
||||||
|
@ -820,8 +856,8 @@ describe('ExceptionsManager', () => {
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
}
|
||||||
const linesByFile = new Map();
|
const linesByFile = new Map();
|
||||||
|
|
||||||
function getLineFromFrame({lineNumber /* 1-based */, file}) {
|
function getLineFromFrame({lineNumber /* 1-based */, file}) {
|
||||||
|
|
Загрузка…
Ссылка в новой задаче