Added module for test-utilities used across all packages

Summary: Added new package with test utilities re-used by other packages

Reviewed By: mweststrate

Differential Revision: D21949629

fbshipit-source-id: 8bfa959401669dc8911a1f647f417cafd92c2e4b
This commit is contained in:
Anton Nikolaev
2020-06-09 04:52:39 -07:00
committed by Facebook GitHub Bot
parent eeded4e32f
commit d27fa34505
15 changed files with 106 additions and 19 deletions

View File

@@ -0,0 +1,39 @@
/**
* 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
*/
/*
* 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,
};