Skip to content

Commit

Permalink
chore: suppressing more logs
Browse files Browse the repository at this point in the history
  • Loading branch information
petertonysmith94 committed Dec 6, 2024
1 parent 7814cef commit d987097
Show file tree
Hide file tree
Showing 10 changed files with 32 additions and 27 deletions.
2 changes: 1 addition & 1 deletion packages/abi-typegen/src/cli.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ describe('cli.ts', () => {
test('should handle errors when running cli action', () => {
const runTypegenError = new Error('Pretty message');

const logSpy = vi.spyOn(console, 'log');
const logSpy = vi.spyOn(console, 'log').mockImplementation(() => {});
const { exit } = mockDeps({ runTypegenError });

const inputs = ['*-no-abis-here.json'];
Expand Down
4 changes: 2 additions & 2 deletions packages/account/src/providers/provider.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1181,7 +1181,7 @@ describe('Provider', () => {
const spy = vi.spyOn(fuelTsVersionsMod, 'checkFuelCoreVersionCompatibility');
spy.mockImplementationOnce(() => mock);

const consoleWarnSpy = vi.spyOn(console, 'warn');
const consoleWarnSpy = vi.spyOn(console, 'warn').mockImplementation(() => {});

using launched = await setupTestProviderAndWallets();
const { provider } = launched;
Expand Down Expand Up @@ -1216,7 +1216,7 @@ Supported fuel-core version: ${mock.supportedVersion}.`
const spy = vi.spyOn(fuelTsVersionsMod, 'checkFuelCoreVersionCompatibility');
spy.mockImplementationOnce(() => mock);

const consoleWarnSpy = vi.spyOn(console, 'warn');
const consoleWarnSpy = vi.spyOn(console, 'warn').mockImplementation(() => {});

using launched = await setupTestProviderAndWallets();
const { provider } = launched;
Expand Down
4 changes: 2 additions & 2 deletions packages/account/src/test-utils/launchNode.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ describe('launchNode', () => {
});

test('should throw on error and log error message', { timeout: 15000 }, async () => {
const logSpy = vi.spyOn(console, 'log');
const logSpy = vi.spyOn(console, 'log').mockImplementation(() => {});

const invalidCoin = {
asset_id: 'whatever',
Expand Down Expand Up @@ -238,7 +238,7 @@ describe('launchNode', () => {

test('calling cleanup on externally killed node does not throw', async () => {
const mkdirSyncSpy = vi.spyOn(fsMod, 'mkdirSync');
const logSpy = vi.spyOn(console, 'log');
const logSpy = vi.spyOn(console, 'log').mockImplementation(() => {});

const { pid, cleanup } = await launchNode({ loggingEnabled: false });
expect(mkdirSyncSpy).toHaveBeenCalledTimes(1);
Expand Down
9 changes: 5 additions & 4 deletions packages/account/src/test-utils/launchNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { randomBytes, randomUUID } from '@fuel-ts/crypto';
import { FuelError } from '@fuel-ts/errors';
import type { SnapshotConfigs } from '@fuel-ts/utils';
import { defaultConsensusKey, hexlify, defaultSnapshotConfigs } from '@fuel-ts/utils';
import { log } from 'console';
import { existsSync, mkdirSync, rmSync, writeFileSync } from 'fs';
import os from 'os';
import path from 'path';
Expand Down Expand Up @@ -200,8 +201,7 @@ export const launchNode = async ({

if (loggingEnabled) {
child.stderr.on('data', (chunk) => {
// eslint-disable-next-line no-console
console.log(chunk.toString());
log(chunk.toString());
});
}

Expand Down Expand Up @@ -268,8 +268,9 @@ export const launchNode = async ({
});
}
if (/error/i.test(text)) {
// eslint-disable-next-line no-console
console.log(text);
if (loggingEnabled) {
log(text);
}
reject(new FuelError(FuelError.CODES.NODE_LAUNCH_FAILED, text));
}
});
Expand Down
12 changes: 6 additions & 6 deletions packages/create-fuels/src/utils/logger.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,23 +28,23 @@ describe('logger', () => {
});

test('should log', () => {
const logSpy = vi.spyOn(console, 'log');
const logSpy = vi.spyOn(console, 'log').mockImplementation(() => {});
configureLogging({ isLoggingEnabled: true, isDebugEnabled: false });
log('message');
expect(logSpy).toHaveBeenCalledTimes(1);
expect(logSpy).toHaveBeenCalledWith('message');
});

test('should not log', () => {
const logSpy = vi.spyOn(console, 'log');
const logSpy = vi.spyOn(console, 'log').mockImplementation(() => {});

configureLogging({ isLoggingEnabled: false, isDebugEnabled: false });
log('any message');
expect(logSpy).not.toHaveBeenCalled();
});

test('should debug', () => {
const logSpy = vi.spyOn(console, 'log');
const logSpy = vi.spyOn(console, 'log').mockImplementation(() => {});

configureLogging({ isLoggingEnabled: true, isDebugEnabled: true });
debug('message');
Expand All @@ -53,22 +53,22 @@ describe('logger', () => {
});

test('should not log', () => {
const logSpy = vi.spyOn(console, 'log');
const logSpy = vi.spyOn(console, 'log').mockImplementation(() => {});

configureLogging({ isLoggingEnabled: false, isDebugEnabled: false });
loggerMod.debug('any debug message');
expect(logSpy).toHaveBeenCalledTimes(0);
});

test('should warn', () => {
const logSpy = vi.spyOn(console, 'log');
const logSpy = vi.spyOn(console, 'log').mockImplementation(() => {});
warn('message1', 'message2');
expect(logSpy).toHaveBeenCalledTimes(1);
expect(logSpy).toHaveBeenCalledWith(chalk.yellow('message1 message2'));
});

test('should error', () => {
const logSpy = vi.spyOn(console, 'log');
const logSpy = vi.spyOn(console, 'log').mockImplementation(() => {});
error('message1', 'message2');
expect(logSpy).toHaveBeenCalledTimes(1);
expect(logSpy).toHaveBeenCalledWith(chalk.red('message1 message2'));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ describe('buildSwayPrograms', () => {

test('logs to console when logging is enabled', async () => {
const { spawn } = mockAll();
const logSpy = vi.spyOn(console, 'log');
const logSpy = vi.spyOn(console, 'log').mockImplementation(() => {});

configureLogging({ isLoggingEnabled: true, isDebugEnabled: false });

Expand All @@ -70,7 +70,7 @@ describe('buildSwayPrograms', () => {

test('logs debug to console when debug is enabled', async () => {
const { spawn } = mockAll();
const logSpy = vi.spyOn(console, 'log');
const logSpy = vi.spyOn(console, 'log').mockImplementation(() => {});
configureLogging({ isLoggingEnabled: true, isDebugEnabled: true });

await buildSwayProgram(fuelsConfig, '/any/workspace/path');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ describe('checkForAndDisplayUpdates', () => {
FUEL_CORE: '1.0.0',
});

const log = vi.spyOn(loggerMod, 'log');
const warn = vi.spyOn(loggerMod, 'warn');
const log = vi.spyOn(loggerMod, 'log').mockImplementation(() => {});
const warn = vi.spyOn(loggerMod, 'warn').mockImplementation(() => {});

return { log, warn };
};
Expand Down Expand Up @@ -67,7 +67,7 @@ describe('checkForAndDisplayUpdates', () => {
new Error('Failed to fetch')
);

const log = vi.spyOn(loggerMod, 'log');
const log = vi.spyOn(loggerMod, 'log').mockImplementation(() => {});

await checkForAndDisplayUpdatesMod.checkForAndDisplayUpdates();

Expand Down
12 changes: 6 additions & 6 deletions packages/fuels/src/cli/utils/logger.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,23 +26,23 @@ describe('logger', () => {
});

test('should log', () => {
const logSpy = vi.spyOn(console, 'log');
const logSpy = vi.spyOn(console, 'log').mockImplementation(() => {});
configureLogging({ isLoggingEnabled: true, isDebugEnabled: false });
log('message');
expect(logSpy).toHaveBeenCalledTimes(1);
expect(logSpy).toHaveBeenCalledWith('message');
});

test('should not log', () => {
const logSpy = vi.spyOn(console, 'log');
const logSpy = vi.spyOn(console, 'log').mockImplementation(() => {});

configureLogging({ isLoggingEnabled: false, isDebugEnabled: false });
log('any message');
expect(logSpy).not.toHaveBeenCalled();
});

test('should debug', () => {
const logSpy = vi.spyOn(console, 'log');
const logSpy = vi.spyOn(console, 'log').mockImplementation(() => {});

configureLogging({ isLoggingEnabled: true, isDebugEnabled: true });
debug('message');
Expand All @@ -51,22 +51,22 @@ describe('logger', () => {
});

test('should not log', () => {
const logSpy = vi.spyOn(console, 'log');
const logSpy = vi.spyOn(console, 'log').mockImplementation(() => {});

configureLogging({ isLoggingEnabled: false, isDebugEnabled: false });
loggerMod.debug('any debug message');
expect(logSpy).toHaveBeenCalledTimes(0);
});

test('should warn', () => {
const logSpy = vi.spyOn(console, 'log');
const logSpy = vi.spyOn(console, 'log').mockImplementation(() => {});
warn('message1', 'message2');
expect(logSpy).toHaveBeenCalledTimes(1);
expect(logSpy).toHaveBeenCalledWith(chalk.yellow('message1 message2'));
});

test('should error', () => {
const logSpy = vi.spyOn(console, 'log');
const logSpy = vi.spyOn(console, 'log').mockImplementation(() => {});
error('message1', 'message2');
expect(logSpy).toHaveBeenCalledTimes(1);
expect(logSpy).toHaveBeenCalledWith(chalk.red('message1 message2'));
Expand Down
2 changes: 1 addition & 1 deletion packages/fuels/test/features/init.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ describe('init', () => {
});

it('should error if no inputs/workspace is supplied', async () => {
const logSpy = vi.spyOn(console, 'log');
const logSpy = vi.spyOn(console, 'log').mockImplementation(() => {});
const exit = vi.spyOn(process, 'exit').mockResolvedValue({} as never);

await runCommand(Commands.init, ['--path', paths.root, '-o', paths.outputDir]);
Expand Down
4 changes: 4 additions & 0 deletions packages/utils/src/utils/toUtf8String.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ import { toUtf8String } from './toUtf8String';
* @group browser
*/
describe('toUtf8String', () => {
beforeAll(() => {
vi.spyOn(console, 'log').mockImplementation(() => {});
});

it('should convert valid UTF-8 bytes to a string', () => {
const bytes = new Uint8Array([72, 101, 108, 108, 111, 32, 87, 111, 114, 108, 100]);
expect(toUtf8String(bytes)).toEqual('Hello World');
Expand Down

0 comments on commit d987097

Please sign in to comment.