Files
flipper/desktop/test-utils/src/consoleMock.tsx
Anton Kastritskiy b4fc108c2e Rename first batch for '.ts' files to '.tsx' in doctor, static and test-utils
Summary: Rename first batch for '.ts' files to '.tsx'

Reviewed By: nikoant

Differential Revision: D33843051

fbshipit-source-id: 68dd2dc6538afce2daaf24c6412dc5db8b38acbc
2022-01-28 08:32:19 -08:00

40 lines
904 B
TypeScript

/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @format
*/
/*
* mock-fs library has issues with calls to console.log in jest tests which are not resolved yet,
* so this console log can be used as a workaround in jest tests with fs-mocks:
* const realConsole = global.console;
* global.console = consoleMock as any;
* afterAll(() => {
* global.console = realConsole;
* });
* See details: https://github.com/tschaub/mock-fs/issues/234
*/
function format(entry: any) {
if (typeof entry === 'object') {
try {
return JSON.stringify(entry);
} catch (e) {}
}
return entry;
}
function log(...msgs: any) {
process.stdout.write(msgs.map(format).join(' ') + '\n');
}
export default {
log,
warn: log,
error: log,
};