Skip to content

Commit

Permalink
Merge branch 'master' into mc/fix/adjust-global-cache-instances
Browse files Browse the repository at this point in the history
  • Loading branch information
maschad authored Dec 9, 2024
2 parents 7743aff + 560664d commit 350dfd0
Show file tree
Hide file tree
Showing 16 changed files with 102 additions and 45 deletions.
4 changes: 4 additions & 0 deletions .changeset/moody-terms-shake.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
---

chore: minimizing logs in test output
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/abi-typegen/src/runTypegen.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ describe('runTypegen.js', () => {
});

test('should log messages to stdout', async () => {
const logSpy = vi.spyOn(console, 'log');
const logSpy = vi.spyOn(console, 'log').mockImplementation(() => {});

// setup temp sway project
const project = getTypegenForcProject(AbiTypegenProjectsEnum.SCRIPT);
Expand Down Expand Up @@ -272,7 +272,7 @@ describe('runTypegen.js', () => {
cpSync(fromBin, toBin);

// mocking
const logSpy = vi.spyOn(console, 'log');
const logSpy = vi.spyOn(console, 'log').mockImplementation(() => {});

// executes program
const fn = () =>
Expand Down
10 changes: 5 additions & 5 deletions packages/account/src/providers/provider.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ describe('Provider', () => {
});

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

// Verify that only one transaction was returned (the known type)
const transaction = await mockProvider.getTransaction('0x1234567890abcdef');
Expand Down Expand Up @@ -298,7 +298,7 @@ describe('Provider', () => {
});

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

// Verify that only one transaction was returned (the known type)
const { transactions } = await mockProvider.getTransactions();
Expand Down Expand Up @@ -448,7 +448,7 @@ describe('Provider', () => {
using launched = await setupTestProviderAndWallets();
const { provider } = launched;

const { cleanup, url } = await launchNode({ port: '0' });
const { cleanup, url } = await launchNode({ port: '0', loggingEnabled: false });

const spyFetchChainAndNodeInfo = vi.spyOn(Provider.prototype, 'fetchChainAndNodeInfo');

Expand Down Expand Up @@ -1230,7 +1230,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 @@ -1265,7 +1265,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
6 changes: 3 additions & 3 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 All @@ -132,7 +132,7 @@ describe('launchNode', () => {
const error = await expectToThrowFuelError(
async () =>
launchNode({
loggingEnabled: false,
loggingEnabled: true,
snapshotConfig: {
...defaultSnapshotConfigs,
stateConfig: {
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
3 changes: 3 additions & 0 deletions packages/account/src/test-utils/launchNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,9 @@ export const launchNode = async ({
}
});

// Increase the max listeners to avoid a warning
process.setMaxListeners(100);

// Process exit.
process.on('exit', cleanup);

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
17 changes: 11 additions & 6 deletions packages/fuels/src/cli/commands/dev/autoStartFuelCore.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ describe('autoStartFuelCore', () => {
});
});

function mockLaunchNode() {
function mockAll() {
const launchNode = vi.spyOn(testUtilsMod, 'launchNode').mockReturnValue(
Promise.resolve({
cleanup: () => {},
Expand All @@ -37,33 +37,36 @@ describe('autoStartFuelCore', () => {
pid: 1234,
})
);
return { launchNode };
const log = vi.spyOn(console, 'log').mockImplementation(() => {});
return { launchNode, log };
}

test('should auto start `fuel-core`', async () => {
const { launchNode } = mockLaunchNode();
const { launchNode, log } = mockAll();

const config = structuredClone(fuelsConfig);
config.autoStartFuelCore = true;

await autoStartFuelCore(config);

expect(launchNode).toHaveBeenCalledTimes(1);
expect(log).toHaveBeenCalledTimes(1);
});

test('should not start `fuel-core`', async () => {
const { launchNode } = mockLaunchNode();
const { launchNode, log } = mockAll();

const config = structuredClone(fuelsConfig);
config.autoStartFuelCore = false;

await autoStartFuelCore(config);

expect(launchNode).toHaveBeenCalledTimes(0);
expect(log).toHaveBeenCalledTimes(0);
});

test('should start `fuel-core` node using custom binary', async () => {
const { launchNode } = mockLaunchNode();
const { launchNode, log } = mockAll();

const copyConfig: FuelsConfig = structuredClone(fuelsConfig);
copyConfig.fuelCorePath = 'fuels-core';
Expand All @@ -86,12 +89,13 @@ describe('autoStartFuelCore', () => {
fuelCorePath: 'fuels-core',
})
);
expect(log).toHaveBeenCalledTimes(1);

core.killChildProcess();
});

test('should start `fuel-core` node using system binary', async () => {
const { launchNode } = mockLaunchNode();
const { launchNode, log } = mockAll();

const config = structuredClone(fuelsConfig);
const core = (await autoStartFuelCore(config)) as FuelCoreNode;
Expand All @@ -103,6 +107,7 @@ describe('autoStartFuelCore', () => {
expect(core.port).toBeGreaterThanOrEqual(4000);
expect(core.providerUrl).toMatch(/http:\/\/127\.0\.0\.1:([0-9]+)\/v1\/graphql/);
expect(core.killChildProcess).toBeTruthy();
expect(log).toHaveBeenCalledTimes(1);

core.killChildProcess();
});
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
Loading

0 comments on commit 350dfd0

Please sign in to comment.