Skip to content

Commit

Permalink
[Cleanup] Remove redundant mock clearing (#985)
Browse files Browse the repository at this point in the history
  • Loading branch information
webfiltered authored Feb 23, 2025
1 parent 2ad9c60 commit 5552cac
Show file tree
Hide file tree
Showing 14 changed files with 7 additions and 57 deletions.
11 changes: 1 addition & 10 deletions tests/unit/config/comfyConfigManager.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import log from 'electron-log/main';
import fs, { type PathLike } from 'node:fs';
import path from 'node:path';
import { beforeEach, describe, expect, it, vi } from 'vitest';
import { describe, expect, it, vi } from 'vitest';

import { ComfyConfigManager, DirectoryStructure } from '@/config/comfyConfigManager';

Expand All @@ -12,15 +12,6 @@ const { normalize } = path;
vi.mock('node:fs');

describe('ComfyConfigManager', () => {
// Reset all mocks before each test
beforeEach(() => {
vi.clearAllMocks();
vi.mocked(fs.existsSync).mockReset();
vi.mocked(fs.mkdirSync).mockReset();
vi.mocked(fs.writeFileSync).mockReset();
vi.mocked(fs.renameSync).mockReset();
});

describe('setUpComfyUI', () => {
it('should allow existing directory when it contains ComfyUI structure', () => {
vi.mocked(fs.existsSync).mockReturnValue(true);
Expand Down
6 changes: 1 addition & 5 deletions tests/unit/config/comfyServerConfig.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { mkdtemp, readFile, rm, writeFile } from 'node:fs/promises';
import fsPromises from 'node:fs/promises';
import { tmpdir } from 'node:os';
import path from 'node:path';
import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, it, vi } from 'vitest';
import { afterAll, beforeAll, beforeEach, describe, expect, it, vi } from 'vitest';

import { ComfyServerConfig } from '@/config/comfyServerConfig';

Expand Down Expand Up @@ -42,10 +42,6 @@ describe('ComfyServerConfig', () => {
await rm(tempDir, { recursive: true });
});

afterEach(() => {
vi.clearAllMocks();
});

describe('configPath', () => {
it('should return the correct path', () => {
const { getPath } = app;
Expand Down
7 changes: 0 additions & 7 deletions tests/unit/config/comfySettings.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@ describe('ComfySettings', () => {
let settings: ComfySettings;

beforeEach(async () => {
vi.resetModules();
vi.clearAllMocks();

// Reset writeLocked state
// @ts-expect-error accessing private static
ComfySettings.writeLocked = false;
Expand Down Expand Up @@ -76,10 +73,6 @@ describe('ComfySettings', () => {
});

describe('file operations', () => {
beforeEach(() => {
vi.clearAllMocks();
});

it('should use correct file path', async () => {
await settings.saveSettings();
expect(fsPromises.writeFile).toHaveBeenCalledWith(expectedFilePath, JSON.stringify(DEFAULT_SETTINGS, null, 2));
Expand Down
6 changes: 1 addition & 5 deletions tests/unit/handlers/AppHandlers.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { app, ipcMain } from 'electron';
import { afterEach, beforeEach, describe, expect, test, vi } from 'vitest';
import { beforeEach, describe, expect, test, vi } from 'vitest';

import { IPC_CHANNELS } from '@/constants';
import { registerAppHandlers } from '@/handlers/AppHandlers';
Expand All @@ -16,10 +16,6 @@ describe('AppHandlers', () => {
registerAppHandlers();
});

afterEach(() => {
vi.clearAllMocks();
});

describe('registerHandlers', () => {
const channels = [IPC_CHANNELS.QUIT, IPC_CHANNELS.RESTART_APP];

Expand Down
6 changes: 1 addition & 5 deletions tests/unit/handlers/appinfoHandlers.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ipcMain } from 'electron';
import { Mock, afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
import { Mock, beforeEach, describe, expect, it, vi } from 'vitest';

import { IPC_CHANNELS } from '@/constants';
import { registerAppInfoHandlers } from '@/handlers/appInfoHandlers';
Expand Down Expand Up @@ -49,10 +49,6 @@ describe('AppInfoHandlers', () => {
{ channel: IPC_CHANNELS.GET_WINDOW_STYLE, expected: MOCK_WINDOW_STYLE },
];

afterEach(() => {
vi.clearAllMocks();
});

describe('registerHandlers', () => {
beforeEach(() => {
registerAppInfoHandlers();
Expand Down
1 change: 0 additions & 1 deletion tests/unit/handlers/pathHandler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ const getRegisteredHandler = <T extends (...args: never[]) => unknown>(

describe('PathHandlers', () => {
beforeEach(() => {
vi.resetAllMocks();
vi.mocked(app.getPath).mockImplementation(
(name: string) => (MOCK_PATHS as Record<string, string>)[name] ?? `/mock/${name}`
);
Expand Down
1 change: 0 additions & 1 deletion tests/unit/install/installWizard.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ describe('InstallWizard', () => {
};

beforeEach(async () => {
vi.clearAllMocks();
await ComfySettings.load('/test/path');
installWizard = new InstallWizard(defaultInstallOptions, getTelemetry());
});
Expand Down
1 change: 0 additions & 1 deletion tests/unit/install/installationManager.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@ describe('InstallationManager', () => {
let validationUpdates: InstallValidation[];

beforeEach(async () => {
vi.clearAllMocks();
validationUpdates = [];

// Reset fs mocks with default behaviors - only the ones we need
Expand Down
1 change: 0 additions & 1 deletion tests/unit/main-process/appState.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ const test = baseTest.extend<AppStateModule & { imported: AppStateModule }>({
imported: async ({}, use) => {
const imported = await import('@/main-process/appState');
await use(imported);
vi.clearAllMocks();
vi.resetModules();
},
initializeAppState: async ({ imported }, use) => {
Expand Down
3 changes: 0 additions & 3 deletions tests/unit/main-process/comfyDesktopApp.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,6 @@ describe('ComfyDesktopApp', () => {
let mockVirtualEnvironment: any;

beforeEach(() => {
vi.clearAllMocks();

mockComfySettings = {
get: vi.fn(),
};
Expand Down Expand Up @@ -113,7 +111,6 @@ describe('ComfyDesktopApp', () => {

describe('buildServerArgs', () => {
beforeEach(() => {
vi.clearAllMocks();
mockComfySettings.get.mockReturnValue({});
vi.mocked(findAvailablePort).mockResolvedValue(8188);
});
Expand Down
6 changes: 1 addition & 5 deletions tests/unit/main-process/comfyServer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import log from 'electron-log/main';
import { ChildProcess } from 'node:child_process';
import { EventEmitter } from 'node:events';
import path from 'node:path';
import { test as baseTest, beforeEach, describe, expect, vi } from 'vitest';
import { test as baseTest, describe, expect, vi } from 'vitest';
import waitOn from 'wait-on';

import { ServerArgs } from '@/constants';
Expand Down Expand Up @@ -80,10 +80,6 @@ const test = baseTest.extend<TestContext>({
},
});

beforeEach(() => {
vi.clearAllMocks();
});

describe('buildLaunchArgs', () => {
test('should convert basic arguments correctly', () => {
const args = {
Expand Down
2 changes: 0 additions & 2 deletions tests/unit/services/telemetry.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ describe('MixpanelTelemetry', () => {
};

beforeEach(async () => {
vi.clearAllMocks();
// Initialize settings before each test
await ComfySettings.load('/mock/path');
});
Expand Down Expand Up @@ -232,7 +231,6 @@ describe('promptMetricsConsent', () => {
const versionAfterUpdate = '1.0.1';

beforeEach(async () => {
vi.clearAllMocks();
store = { get: vi.fn(), set: vi.fn() };
appWindow = { loadPage: vi.fn() };
// Initialize settings before each test
Expand Down
6 changes: 1 addition & 5 deletions tests/unit/store/desktopConfig.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import log from 'electron-log/main';
import ElectronStore from 'electron-store';
import fs from 'node:fs/promises';
import path from 'node:path';
import { Mock, afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
import { Mock, beforeEach, describe, expect, it, vi } from 'vitest';

import { DesktopConfig, useDesktopConfig } from '@/store/desktopConfig';

Expand Down Expand Up @@ -39,10 +39,6 @@ describe('DesktopConfig', () => {
(ElectronStore as unknown as Mock).mockImplementation(() => mockStore);
});

afterEach(() => {
vi.clearAllMocks();
});

describe('load', () => {
it('should create and return a new instance when successful', async () => {
const config = await DesktopConfig.load(shell);
Expand Down
7 changes: 1 addition & 6 deletions tests/unit/utils.test.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,12 @@
import type { Systeminformation } from 'systeminformation';
import si from 'systeminformation';
import { beforeEach, describe, expect, it, vi } from 'vitest';
import { describe, expect, it, vi } from 'vitest';

import { validateHardware } from '@/utils';

vi.mock('systeminformation');

describe('validateHardware', () => {
beforeEach(() => {
vi.resetModules();
vi.resetAllMocks();
});

it('accepts Apple Silicon Mac', async () => {
vi.stubGlobal('process', { ...process, platform: 'darwin' });
vi.mocked(si.cpu).mockResolvedValue({ manufacturer: 'Apple' } as Systeminformation.CpuData);
Expand Down

0 comments on commit 5552cac

Please sign in to comment.