diff --git a/.changeset/moody-terms-shake.md b/.changeset/moody-terms-shake.md new file mode 100644 index 00000000000..0880568bf0a --- /dev/null +++ b/.changeset/moody-terms-shake.md @@ -0,0 +1,4 @@ +--- +--- + +chore: minimizing logs in test output diff --git a/packages/abi-typegen/src/cli.test.ts b/packages/abi-typegen/src/cli.test.ts index 4c4a1d55716..c960b9a48d2 100644 --- a/packages/abi-typegen/src/cli.test.ts +++ b/packages/abi-typegen/src/cli.test.ts @@ -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']; diff --git a/packages/abi-typegen/src/runTypegen.test.ts b/packages/abi-typegen/src/runTypegen.test.ts index 2ea943f2c98..3fe0e2ae1bb 100644 --- a/packages/abi-typegen/src/runTypegen.test.ts +++ b/packages/abi-typegen/src/runTypegen.test.ts @@ -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); @@ -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 = () => diff --git a/packages/account/src/providers/provider.test.ts b/packages/account/src/providers/provider.test.ts index 334cc62d826..7ce40881d71 100644 --- a/packages/account/src/providers/provider.test.ts +++ b/packages/account/src/providers/provider.test.ts @@ -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'); @@ -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(); @@ -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'); @@ -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; @@ -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; diff --git a/packages/account/src/test-utils/launchNode.test.ts b/packages/account/src/test-utils/launchNode.test.ts index 410ca85ac32..ab52fd47603 100644 --- a/packages/account/src/test-utils/launchNode.test.ts +++ b/packages/account/src/test-utils/launchNode.test.ts @@ -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', @@ -132,7 +132,7 @@ describe('launchNode', () => { const error = await expectToThrowFuelError( async () => launchNode({ - loggingEnabled: false, + loggingEnabled: true, snapshotConfig: { ...defaultSnapshotConfigs, stateConfig: { @@ -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); diff --git a/packages/account/src/test-utils/launchNode.ts b/packages/account/src/test-utils/launchNode.ts index a4371ab023c..cfcd46f890e 100644 --- a/packages/account/src/test-utils/launchNode.ts +++ b/packages/account/src/test-utils/launchNode.ts @@ -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); diff --git a/packages/create-fuels/src/utils/logger.test.ts b/packages/create-fuels/src/utils/logger.test.ts index 3a3344abbd1..fc13e87d273 100644 --- a/packages/create-fuels/src/utils/logger.test.ts +++ b/packages/create-fuels/src/utils/logger.test.ts @@ -28,7 +28,7 @@ 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); @@ -36,7 +36,7 @@ describe('logger', () => { }); 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'); @@ -44,7 +44,7 @@ describe('logger', () => { }); test('should debug', () => { - const logSpy = vi.spyOn(console, 'log'); + const logSpy = vi.spyOn(console, 'log').mockImplementation(() => {}); configureLogging({ isLoggingEnabled: true, isDebugEnabled: true }); debug('message'); @@ -53,7 +53,7 @@ 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'); @@ -61,14 +61,14 @@ describe('logger', () => { }); 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')); diff --git a/packages/fuels/src/cli/commands/build/buildSwayProgram.test.ts b/packages/fuels/src/cli/commands/build/buildSwayProgram.test.ts index f10c9968f35..d91ef982b67 100644 --- a/packages/fuels/src/cli/commands/build/buildSwayProgram.test.ts +++ b/packages/fuels/src/cli/commands/build/buildSwayProgram.test.ts @@ -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 }); @@ -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'); diff --git a/packages/fuels/src/cli/commands/dev/autoStartFuelCore.test.ts b/packages/fuels/src/cli/commands/dev/autoStartFuelCore.test.ts index d950c510c91..f5290233ed9 100644 --- a/packages/fuels/src/cli/commands/dev/autoStartFuelCore.test.ts +++ b/packages/fuels/src/cli/commands/dev/autoStartFuelCore.test.ts @@ -26,7 +26,7 @@ describe('autoStartFuelCore', () => { }); }); - function mockLaunchNode() { + function mockAll() { const launchNode = vi.spyOn(testUtilsMod, 'launchNode').mockReturnValue( Promise.resolve({ cleanup: () => {}, @@ -37,11 +37,12 @@ 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; @@ -49,10 +50,11 @@ describe('autoStartFuelCore', () => { 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; @@ -60,10 +62,11 @@ describe('autoStartFuelCore', () => { 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'; @@ -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; @@ -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(); }); diff --git a/packages/fuels/src/cli/utils/checkForAndDisplayUpdates.test.ts b/packages/fuels/src/cli/utils/checkForAndDisplayUpdates.test.ts index 113f70f096d..d58f57fb47d 100644 --- a/packages/fuels/src/cli/utils/checkForAndDisplayUpdates.test.ts +++ b/packages/fuels/src/cli/utils/checkForAndDisplayUpdates.test.ts @@ -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 }; }; @@ -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(); diff --git a/packages/fuels/src/cli/utils/logger.test.ts b/packages/fuels/src/cli/utils/logger.test.ts index 7c8cd22069c..82f8d48fd97 100644 --- a/packages/fuels/src/cli/utils/logger.test.ts +++ b/packages/fuels/src/cli/utils/logger.test.ts @@ -26,7 +26,7 @@ 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); @@ -34,7 +34,7 @@ describe('logger', () => { }); 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'); @@ -42,7 +42,7 @@ describe('logger', () => { }); test('should debug', () => { - const logSpy = vi.spyOn(console, 'log'); + const logSpy = vi.spyOn(console, 'log').mockImplementation(() => {}); configureLogging({ isLoggingEnabled: true, isDebugEnabled: true }); debug('message'); @@ -51,7 +51,7 @@ 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'); @@ -59,14 +59,14 @@ describe('logger', () => { }); 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')); diff --git a/packages/fuels/test/features/build.test.ts b/packages/fuels/test/features/build.test.ts index 4c2956c1c9f..f03a6388419 100644 --- a/packages/fuels/test/features/build.test.ts +++ b/packages/fuels/test/features/build.test.ts @@ -1,4 +1,4 @@ -import { existsSync, readFileSync, writeFileSync } from 'fs'; +import { existsSync, readdirSync, readFileSync, rmSync, writeFileSync } from 'fs'; import { join } from 'path'; import * as deployMod from '../../src/cli/commands/deploy/index'; @@ -24,6 +24,7 @@ describe('build', { timeout: 180000 }, () => { afterEach(() => { resetConfigAndMocks(paths.fuelsConfigPath); + rmSync(paths.outputDir, { recursive: true, force: true }); }); afterAll(() => { @@ -76,12 +77,12 @@ describe('build', { timeout: 180000 }, () => { expect(killChildProcess).toHaveBeenCalledTimes(0); }); - it('should run `build` command with contracts-only', async () => { + it('should run `build` command with contracts-only [single contract]', async () => { const { autoStartFuelCore, killChildProcess, deploy } = mockAll(); await runInit({ root: paths.root, - contracts: paths.contractsDir, + contracts: paths.contractsFooDir, output: paths.outputDir, forcPath: paths.forcPath, fuelCorePath: paths.fuelCorePath, @@ -96,7 +97,42 @@ describe('build', { timeout: 180000 }, () => { 'index.ts', ].map((f) => join(paths.outputDir, f)); - files.forEach((file) => expect(existsSync(file)).toBeTruthy()); + files.forEach((file) => expect(existsSync(file), `${file} does not exist`).toBeTruthy()); + expect(readdirSync(paths.outputContractsDir)).toHaveLength(3); + + expect(autoStartFuelCore).toHaveBeenCalledTimes(0); + expect(deploy).toHaveBeenCalledTimes(0); + expect(killChildProcess).toHaveBeenCalledTimes(0); + }); + + it('should run `build` command with contracts-only [with glob]', async () => { + const { autoStartFuelCore, killChildProcess, deploy } = mockAll(); + + await runInit({ + root: paths.root, + contracts: `${paths.contractsDir}/*`, + output: paths.outputDir, + forcPath: paths.forcPath, + fuelCorePath: paths.fuelCorePath, + }); + + await runBuild({ root: paths.root }); + + const files = [ + 'contracts/UpgradableChunked.ts', + 'contracts/UpgradableChunkedFactory.ts', + 'contracts/Upgradable.ts', + 'contracts/UpgradableFactory.ts', + 'contracts/BarFoo.ts', + 'contracts/BarFooFactory.ts', + 'contracts/FooBar.ts', + 'contracts/FooBarFactory.ts', + 'contracts/index.ts', + 'index.ts', + ].map((f) => join(paths.outputDir, f)); + + files.forEach((file) => expect(existsSync(file), `${file} does not exist`).toBeTruthy()); + expect(readdirSync(paths.outputContractsDir)).toHaveLength(9); expect(autoStartFuelCore).toHaveBeenCalledTimes(0); expect(deploy).toHaveBeenCalledTimes(0); diff --git a/packages/fuels/test/features/init.test.ts b/packages/fuels/test/features/init.test.ts index 93b9fd72b7e..4c7be45929f 100644 --- a/packages/fuels/test/features/init.test.ts +++ b/packages/fuels/test/features/init.test.ts @@ -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]); diff --git a/packages/fuels/test/utils/runCommands.ts b/packages/fuels/test/utils/runCommands.ts index 88fd9edf656..3558d04eb97 100644 --- a/packages/fuels/test/utils/runCommands.ts +++ b/packages/fuels/test/utils/runCommands.ts @@ -40,14 +40,17 @@ export function bootstrapProject(testFilepath: string) { cpSync(sampleWorkspaceDir, workspaceDir, { recursive: true }); const contractsDir = join(workspaceDir, 'contracts'); + const contractsBarDir = join(contractsDir, 'bar'); const contractsFooDir = join(contractsDir, 'foo'); - const scriptsDir = join(workspaceDir, 'scripts'); - const predicateDir = join(workspaceDir, 'predicate'); const fooContractMainPath = join(contractsDir, 'foo', 'src', 'main.sw'); const upgradableContractPath = join(contractsDir, 'upgradable'); const upgradableChunkedContractPath = join(contractsDir, 'upgradable-chunked'); + const scriptsDir = join(workspaceDir, 'scripts'); + const predicateDir = join(workspaceDir, 'predicate'); + const outputDir = join(root, 'output'); + const outputContractsDir = join(outputDir, 'contracts'); const contractsJsonPath = join(outputDir, 'contract-ids.json'); const fooContractFactoryPath = join(outputDir, 'contracts', 'factories', 'FooBarAbi.ts'); @@ -58,7 +61,11 @@ export function bootstrapProject(testFilepath: string) { root, workspaceDir, contractsDir, + outputContractsDir, + contractsBarDir, contractsFooDir, + upgradableContractPath, + upgradableChunkedContractPath, scriptsDir, predicateDir, fooContractMainPath, @@ -68,8 +75,6 @@ export function bootstrapProject(testFilepath: string) { fooContractFactoryPath, forcPath, fuelCorePath, - upgradableContractPath, - upgradableChunkedContractPath, }; } diff --git a/packages/utils/src/utils/toUtf8String.test.ts b/packages/utils/src/utils/toUtf8String.test.ts index c61f36079e7..263c434bfdd 100644 --- a/packages/utils/src/utils/toUtf8String.test.ts +++ b/packages/utils/src/utils/toUtf8String.test.ts @@ -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'); diff --git a/packages/versions/src/lib/checkFuelCoreVersionCompatibility.test.ts b/packages/versions/src/lib/checkFuelCoreVersionCompatibility.test.ts index 5753e268b32..3a71c11b4dd 100644 --- a/packages/versions/src/lib/checkFuelCoreVersionCompatibility.test.ts +++ b/packages/versions/src/lib/checkFuelCoreVersionCompatibility.test.ts @@ -69,7 +69,7 @@ describe('getDifferenceToUserFuelCoreVersion', () => { }); it("warns when the version doesn't conform to strict major.minor.patch versioning (e.g. nightly build)", () => { - const consoleWarnSpy = vi.spyOn(console, 'warn'); + const consoleWarnSpy = vi.spyOn(console, 'warn').mockImplementation(() => {}); vi.spyOn(getBuiltinVersionsMod, 'getBuiltinVersions').mockImplementation(() => ({ FUELS: '1', // not under test @@ -92,7 +92,7 @@ This unreleased fuel-core build may include features and updates not yet support FUEL_CORE: '0.1.2', })); - const consoleWarnSpy = vi.spyOn(console, 'warn'); + const consoleWarnSpy = vi.spyOn(console, 'warn').mockImplementation(() => {}); checkFuelCoreVersionCompatibility('0.1.2');