Fix jest mocking in tests (#592)
Summary: Pull Request resolved: https://github.com/facebook/flipper/pull/592 Finally we can join the 21st century and use `jest.mock` in tests! I'm enabling the ts-jest transform to `*/__tests__/*.tsx` files. This takes care of transforming the typescript, and preserves jest mock capabilities. I have left the existing custom transform on all other files, so they will continue to work as usual. Caveats: * Our existing custom transforms will no longer be applied in tests. * With our current suite this makes no difference. But bear in mind things like importing directly from 'flipper' instead of the actual files, won't work. However, I don't see this being a problem, as I think they'll only be needed inside the actual product code. Reviewed By: passy Differential Revision: D17978753 fbshipit-source-id: df7b312b5dd5592e4aa4f8df605f5952ea3158e9
This commit is contained in:
committed by
Facebook Github Bot
parent
cc19cc75ee
commit
781344f7de
51
src/fb-stubs/__mocks__/Logger.tsx
Normal file
51
src/fb-stubs/__mocks__/Logger.tsx
Normal file
@@ -0,0 +1,51 @@
|
||||
/**
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*
|
||||
* @format
|
||||
*/
|
||||
|
||||
import {Store} from '../../reducers/index';
|
||||
import {getStringFromErrorLike} from '../../utils/errors';
|
||||
import {Args, Logger, TrackType} from '../../fb-interfaces/Logger';
|
||||
|
||||
export function extractError(
|
||||
...data: Array<any>
|
||||
): {message: string; error: Error} {
|
||||
const message = data.map(getStringFromErrorLike).join(' ');
|
||||
const error = data.find(e => e instanceof Error) || new Error(message);
|
||||
return {
|
||||
message,
|
||||
error,
|
||||
};
|
||||
}
|
||||
|
||||
export class FBLogger implements Logger {
|
||||
constructor(_store?: Store, _args?: Args) {}
|
||||
|
||||
track(_type: TrackType, _event: string, _data?: any, _plugin?: string) {}
|
||||
|
||||
trackTimeSince(_mark: string, _eventName?: string) {}
|
||||
|
||||
info = (..._data: Array<any>) => {};
|
||||
|
||||
warn = (..._data: Array<any>) => {};
|
||||
|
||||
error = (..._data: Array<any>) => {};
|
||||
|
||||
debug = (..._data: Array<any>) => {};
|
||||
|
||||
getLogs(): Array<string> {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
export function init(_store: Store, _args?: Args): Logger {
|
||||
return new FBLogger();
|
||||
}
|
||||
|
||||
export function getInstance(): Logger {
|
||||
return new FBLogger();
|
||||
}
|
||||
Reference in New Issue
Block a user