* update fastlane * update dev dependencies * update to eslint 9+ * update testing-library * update react-intl * update bottom-sheet * update expo * update reanimated * upgrade msgpack * upgrade datepicker * upgrade react-navigation * update sentry * update FlasList * update fuse.js moment-timezone node-html-parser and semver * update gesture-handler * update image-picker * update react-native-keychain * update react-native-localize * update react-native-navigation * update watermelonDB * update react-native-permissions * update react-native-safe-area-context and react-native-screens * update react-native-share and react-native-svg * update react-native-video and react-native-webrtc * update @mattermost/rnutils * update @mattermost/rnshare * update @mattermost/hardware-keyboard * fix isMainActivity * update android dependencies * fix upload file progress indicator * fix entry update config & license * revert to stable version of @sentry/react-native * update react-intl again * update moment-timezone * upgrade @react-native-camera-roll/camera-roll * update @react-native-clipboard/clipboard * update @react-navigation again * update @shopify/flash-list * update eslint * update expo again * update html-entities * update mime-db * update react-native-permissions * Revert "update react-intl again" This reverts commit e8e6d5a60dfa56b82b810cbbd7cdffec7697ffc7. * Revert "update react-intl" This reverts commit c77f329bb38910aeeba03869b72d77a8b0e00ba1. * update react-native-keychain * update and patch react-intl * mend * feedback during review 1
85 lines
2.5 KiB
TypeScript
85 lines
2.5 KiB
TypeScript
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
|
// See LICENSE.txt for license information.
|
|
|
|
import Config from '@assets/config.json';
|
|
import keyMirror from '@utils/key_mirror';
|
|
|
|
import {logError, logWarning, logInfo, logDebug} from './log';
|
|
|
|
// Mock Sentry
|
|
jest.mock('@sentry/react-native', () => ({
|
|
addBreadcrumb: jest.fn(),
|
|
}));
|
|
|
|
// Mock console methods
|
|
const originalConsole = global.console;
|
|
|
|
// @ts-expect-error global not in TS def
|
|
global.console = {
|
|
error: jest.fn(),
|
|
warn: jest.fn(),
|
|
log: jest.fn(),
|
|
debug: jest.fn(),
|
|
};
|
|
|
|
describe('Logging functions', () => {
|
|
const Sentry = require('@sentry/react-native');
|
|
const SentryLevels = keyMirror({debug: null, info: null, warning: null, error: null});
|
|
|
|
beforeAll(() => {
|
|
Config.SentryEnabled = true;
|
|
});
|
|
|
|
afterEach(() => {
|
|
jest.clearAllMocks();
|
|
});
|
|
|
|
afterAll(() => {
|
|
global.console = originalConsole;
|
|
Config.SentryEnabled = false;
|
|
});
|
|
|
|
test('logError logs error and adds breadcrumb', () => {
|
|
const args = ['Error message'];
|
|
logError(...args);
|
|
expect(console.error).toHaveBeenCalledWith(...args);
|
|
expect(Sentry.addBreadcrumb).toHaveBeenCalledWith({
|
|
level: SentryLevels.error,
|
|
message: args.join(','),
|
|
type: 'console-log',
|
|
});
|
|
});
|
|
|
|
test('logWarning logs warning and adds breadcrumb', () => {
|
|
const args = ['Warning message'];
|
|
logWarning(...args);
|
|
expect(console.warn).toHaveBeenCalledWith(...args);
|
|
expect(Sentry.addBreadcrumb).toHaveBeenCalledWith({
|
|
level: SentryLevels.warning,
|
|
message: args.join(','),
|
|
type: 'console-log',
|
|
});
|
|
});
|
|
|
|
test('logInfo logs info and adds breadcrumb', () => {
|
|
const args = ['Info message'];
|
|
logInfo(...args);
|
|
expect(console.log).toHaveBeenCalledWith(...args);
|
|
expect(Sentry.addBreadcrumb).toHaveBeenCalledWith({
|
|
level: SentryLevels.info,
|
|
message: args.join(','),
|
|
type: 'console-log',
|
|
});
|
|
});
|
|
|
|
test('logDebug logs debug and adds breadcrumb', () => {
|
|
const args = ['Debug message'];
|
|
logDebug(...args);
|
|
expect(console.debug).toHaveBeenCalledWith(...args);
|
|
expect(Sentry.addBreadcrumb).toHaveBeenCalledWith({
|
|
level: SentryLevels.debug,
|
|
message: args.join(','),
|
|
type: 'console-log',
|
|
});
|
|
});
|
|
});
|