Skip to content

Commit

Permalink
fix: console level debugLogger (#1077)
Browse files Browse the repository at this point in the history
  • Loading branch information
andrearampin authored Oct 30, 2023
1 parent 442c570 commit 3cce32e
Show file tree
Hide file tree
Showing 9 changed files with 14 additions and 14 deletions.
4 changes: 2 additions & 2 deletions packages/checkout/sdk/src/balances/balances.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ describe('balances', () => {
} as unknown as Web3Provider));

beforeEach(() => {
jest.spyOn(console, 'debug').mockImplementation(() => {});
jest.spyOn(console, 'info').mockImplementation(() => {});
});

describe('getBalance()', () => {
Expand Down Expand Up @@ -224,7 +224,7 @@ describe('balances', () => {
beforeEach(() => {
jest.restoreAllMocks();
resetBlockscoutClientMap();
jest.spyOn(console, 'debug').mockImplementation(() => {});
jest.spyOn(console, 'info').mockImplementation(() => {});
getTokenAllowListMock = jest.fn().mockReturnValue({
tokens: [
{
Expand Down
2 changes: 1 addition & 1 deletion packages/checkout/sdk/src/smartCheckout/buy/buy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ describe('buy', () => {
const seaportContractAddress = '0xSEAPORT';

beforeEach(() => {
jest.spyOn(console, 'debug').mockImplementation(() => {});
jest.spyOn(console, 'info').mockImplementation(() => {});
});

describe('buy', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ describe('cancel', () => {
baseConfig: { environment: Environment.SANDBOX },
});

jest.spyOn(console, 'debug').mockImplementation(() => {});
jest.spyOn(console, 'info').mockImplementation(() => {});
});

it('should sign the cancel transaction', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ describe('routingCalculator', () => {
config = new CheckoutConfiguration({
baseConfig: { environment: Environment.SANDBOX },
});
jest.spyOn(console, 'debug').mockImplementation(() => {});
jest.spyOn(console, 'info').mockImplementation(() => {});
});

it('should return no options if no routing options are available', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ describe('quoteFetcher', () => {
});

beforeEach(() => {
jest.spyOn(console, 'debug').mockImplementation(() => {});
jest.spyOn(console, 'info').mockImplementation(() => {});
});

it('should fetch quotes', async () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/checkout/sdk/src/smartCheckout/sell/sell.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ describe('sell', () => {
baseConfig: { environment: Environment.SANDBOX },
});

jest.spyOn(console, 'debug').mockImplementation(() => {});
jest.spyOn(console, 'info').mockImplementation(() => {});
});

describe('sell', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ describe('smartCheckout', () => {

beforeEach(() => {
jest.resetAllMocks();
jest.spyOn(console, 'debug').mockImplementation(() => {});
jest.spyOn(console, 'info').mockImplementation(() => {});
mockProvider = {
getSigner: jest.fn().mockReturnValue({
getAddress: jest.fn().mockResolvedValue('0xADDRESS'),
Expand Down
10 changes: 5 additions & 5 deletions packages/checkout/sdk/src/utils/debugLogger.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { CheckoutConfiguration } from '../config';

describe('debugLogger', () => {
beforeEach(() => {
jest.spyOn(console, 'debug').mockImplementation(() => {});
jest.spyOn(console, 'info').mockImplementation(() => {});
});

it('should call underlying function and return result of the promise', async () => {
Expand All @@ -17,18 +17,18 @@ describe('debugLogger', () => {
expect(result).toEqual(mockResult);
});

it('should call console.debug if production false', () => {
it('should call console if production false', () => {
const testCheckoutConfig = { isProduction: false } as CheckoutConfiguration;
const consoleDebugSpy = jest.spyOn(console, 'debug').mockImplementation();
const consoleDebugSpy = jest.spyOn(console, 'info').mockImplementation();
const debugString = 'Test Debug String';
debugLogger(testCheckoutConfig, debugString, 1);
expect(consoleDebugSpy).toHaveBeenCalledWith(debugString, 1);
consoleDebugSpy.mockRestore();
});

it('should not call console.debug if production', () => {
it('should not call console if production', () => {
const testCheckoutConfig = { isProduction: true } as CheckoutConfiguration;
const consoleDebugSpy = jest.spyOn(console, 'debug').mockImplementation();
const consoleDebugSpy = jest.spyOn(console, 'info').mockImplementation();
const debugString = 'Test Debug String';
debugLogger(testCheckoutConfig, debugString, 1);
expect(consoleDebugSpy).not.toBeCalled();
Expand Down
2 changes: 1 addition & 1 deletion packages/checkout/sdk/src/utils/debugLogger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { CheckoutConfiguration } from '../config';

export const debugLogger = (config: CheckoutConfiguration, debugString: string, seconds: number) => {
// eslint-disable-next-line no-console
if (!config.isProduction) console.debug(debugString, seconds);
if (!config.isProduction) console.info(debugString, seconds);
};

export const measureAsyncExecution = async <T>(
Expand Down

0 comments on commit 3cce32e

Please sign in to comment.