Fix crash reporter plugin test

Summary: The test were broken, as the `CrashReporterPlugin.id` was empty. This value is populated when plugin is loaded, thus added a helper function for that. Also removed a duplicate test.

Reviewed By: danielbuechele

Differential Revision: D13517063

fbshipit-source-id: ffb99316933cd27068c6bce67cfa6e95633b6246
This commit is contained in:
Pritesh Nandgaonkar
2018-12-19 06:29:05 -08:00
committed by Facebook Github Bot
parent ea54b6d4ca
commit 3135c99cc5

View File

@@ -23,6 +23,10 @@ function setNotificationID(notificationID: number) {
CrashReporterPlugin.notificationID = notificationID; CrashReporterPlugin.notificationID = notificationID;
} }
function setCrashReporterPluginID(id: string) {
CrashReporterPlugin.id = id;
}
function getCrash( function getCrash(
id: number, id: number,
callstack: string, callstack: string,
@@ -39,7 +43,16 @@ function getCrash(
beforeEach(() => { beforeEach(() => {
setNotificationID(0); // Resets notificationID to 0 setNotificationID(0); // Resets notificationID to 0
setDefaultPersistedState({crashes: []}); // Resets defaultpersistedstate setDefaultPersistedState({crashes: []}); // Resets defaultpersistedstate
setCrashReporterPluginID('CrashReporter');
}); });
afterAll(() => {
// Reset values
setNotificationID(0);
setDefaultPersistedState({crashes: []});
setCrashReporterPluginID('');
});
test('test the parsing of the reason for crash when log matches the predefined regex', () => { test('test the parsing of the reason for crash when log matches the predefined regex', () => {
const log = 'Blaa Blaaa \n Blaa Blaaa \n Exception Type: SIGSEGV'; const log = 'Blaa Blaaa \n Blaa Blaaa \n Exception Type: SIGSEGV';
const crash = parseCrashLog(log); const crash = parseCrashLog(log);
@@ -97,20 +110,6 @@ test('test getPersistedState for non-empty defaultPersistedState and undefined p
); );
expect(perisistedState).toEqual({crashes: [crash]}); expect(perisistedState).toEqual({crashes: [crash]});
}); });
test('test getPersistedState for non-empty defaultPersistedState and defined pluginState', () => {
const crash = getCrash(0, 'callstack', 'crash0', 'crash0');
const pluginKey = getPluginKey(null, CrashReporterPlugin.id);
setDefaultPersistedState({crashes: [crash]});
const pluginStateCrash = getCrash(1, 'callstack', 'crash1', 'crash1');
//$FlowFixMe
const pluginStates = {'unknown#CrashReporter': {crashes: [pluginStateCrash]}};
const perisistedState = getPersistedState(
pluginKey,
CrashReporterPlugin,
pluginStates,
);
expect(perisistedState).toEqual({crashes: [pluginStateCrash]});
});
test('test getPersistedState for non-empty defaultPersistedState and defined pluginState', () => { test('test getPersistedState for non-empty defaultPersistedState and defined pluginState', () => {
const crash = getCrash(0, 'callstack', 'crash0', 'crash0'); const crash = getCrash(0, 'callstack', 'crash0', 'crash0');
const pluginKey = getPluginKey(null, CrashReporterPlugin.id); const pluginKey = getPluginKey(null, CrashReporterPlugin.id);