Always mock FBLogger during unit tests

Summary: Unit tests tend to randomly bail out once FBLogger is (indirectly) required by some module under test. This makes sure FBLogger is stubbed by default. We might want to do the same for `User` in the future.

Reviewed By: jknoxville

Differential Revision: D22186274

fbshipit-source-id: 2ede364c4b691d69826781355592226b075d8367
This commit is contained in:
Michel Weststrate
2020-07-01 08:58:40 -07:00
committed by Facebook GitHub Bot
parent 83e6968fa1
commit bf79c9472e
6 changed files with 5 additions and 26 deletions

View File

@@ -8,10 +8,6 @@
*/
jest.mock('../../defaultPlugins');
try {
jest.mock('../../fb/Logger', () => require('../../fb-stubs/Logger'));
} catch {}
import dispatcher, {
getDynamicPlugins,
checkDisabled,
@@ -24,7 +20,7 @@ import path from 'path';
import {ipcRenderer, remote} from 'electron';
import {FlipperPlugin} from 'flipper';
import reducers, {State} from '../../reducers/index';
import {init as initLogger} from '../../fb-stubs/Logger';
import {getInstance} from '../../fb-stubs/Logger';
import configureStore from 'redux-mock-store';
import {TEST_PASSING_GK, TEST_FAILING_GK} from '../../fb-stubs/GK';
import TestPlugin from './TestPlugin';
@@ -34,7 +30,7 @@ import {SandyPluginDefinition} from 'flipper-plugin';
const mockStore = configureStore<State, {}>([])(
reducers(undefined, {type: 'INIT'}),
);
const logger = initLogger(mockStore);
const logger = getInstance();
const samplePluginDetails: PluginDetails = {
name: 'other Name',

View File

@@ -23,9 +23,7 @@ export function init(store: Store, _args?: Args): Logger {
export function getInstance(): Logger {
if (!instance) {
throw new Error(
'Requested Logger instance without initializing it. Make sure init() is called at app start',
);
return init(undefined as any /* store is not actually used */);
}
return instance;
}

View File

@@ -10,12 +10,6 @@
import * as React from 'react';
import {render, fireEvent, waitFor, act} from '@testing-library/react';
try {
jest.mock('../../../../fb/Logger');
} catch {
jest.mock('../../../../fb-stubs/Logger');
}
import ManagedDataInspector from '../ManagedDataInspector';
import {sleep} from '../../../../utils';

View File

@@ -7,11 +7,6 @@
* @format
*/
try {
jest.mock('../../fb/Logger');
} catch (e) {
jest.mock('../../fb-stubs/Logger');
}
import {State} from '../../reducers/index';
import configureStore from 'redux-mock-store';
import {default as BaseDevice} from '../../devices/BaseDevice';

View File

@@ -10,12 +10,6 @@
import React from 'react';
import {render, fireEvent} from '@testing-library/react';
try {
jest.mock('../../../app/src/fb/Logger');
} catch {
jest.mock('../../../app/src/fb-stubs/Logger');
}
import {Element} from 'flipper';
import MultipleSelectorSection from '../MultipleSelectionSection';

View File

@@ -10,3 +10,5 @@
global.fetch = require('jest-fetch-mock');
require('immer').enableMapSet();
require('../app/src/fb-stubs/Logger').init(undefined, {isTest: true});