chore: update tests with removed exclude from cli tsconfig (#11540)

This commit is contained in:
Adam Weidman
2025-10-21 01:40:54 +02:00
committed by GitHub
parent 70a99af1d3
commit 723b8d33c2
5 changed files with 41 additions and 43 deletions

View File

@@ -4,36 +4,34 @@
* SPDX-License-Identifier: Apache-2.0
*/
import { vi } from 'vitest';
import { registerCleanup, runExitCleanup } from './cleanup';
import { vi, describe, it, expect, beforeEach } from 'vitest';
import type { registerCleanup, runExitCleanup } from './cleanup.js';
describe('cleanup', () => {
const originalCleanupFunctions = global['cleanupFunctions'];
let register: typeof registerCleanup;
let runExit: typeof runExitCleanup;
beforeEach(() => {
// Isolate cleanup functions for each test
global['cleanupFunctions'] = [];
});
afterAll(() => {
// Restore original cleanup functions
global['cleanupFunctions'] = originalCleanupFunctions;
beforeEach(async () => {
vi.resetModules();
const cleanupModule = await import('./cleanup.js');
register = cleanupModule.registerCleanup;
runExit = cleanupModule.runExitCleanup;
});
it('should run a registered synchronous function', async () => {
const cleanupFn = vi.fn();
registerCleanup(cleanupFn);
register(cleanupFn);
await runExitCleanup();
await runExit();
expect(cleanupFn).toHaveBeenCalledTimes(1);
});
it('should run a registered asynchronous function', async () => {
const cleanupFn = vi.fn().mockResolvedValue(undefined);
registerCleanup(cleanupFn);
register(cleanupFn);
await runExitCleanup();
await runExit();
expect(cleanupFn).toHaveBeenCalledTimes(1);
});
@@ -42,25 +40,24 @@ describe('cleanup', () => {
const syncFn = vi.fn();
const asyncFn = vi.fn().mockResolvedValue(undefined);
registerCleanup(syncFn);
registerCleanup(asyncFn);
register(syncFn);
register(asyncFn);
await runExitCleanup();
await runExit();
expect(syncFn).toHaveBeenCalledTimes(1);
expect(asyncFn).toHaveBeenCalledTimes(1);
});
it('should continue running cleanup functions even if one throws an error', async () => {
const errorFn = vi.fn(() => {
throw new Error('Test Error');
const errorFn = vi.fn().mockImplementation(() => {
throw new Error('test error');
});
const successFn = vi.fn();
register(errorFn);
register(successFn);
registerCleanup(errorFn);
registerCleanup(successFn);
await runExitCleanup();
await expect(runExit()).resolves.not.toThrow();
expect(errorFn).toHaveBeenCalledTimes(1);
expect(successFn).toHaveBeenCalledTimes(1);

View File

@@ -26,7 +26,7 @@ vi.mock('./updateEventEmitter.js', async () => {
return {
...actual,
updateEventEmitter: {
...actual.updateEventEmitter,
...(actual['updateEventEmitter'] as EventEmitter),
emit: vi.fn(),
},
};
@@ -247,7 +247,13 @@ describe('handleAutoUpdate', () => {
});
it('should use the "@nightly" tag for nightly updates', async () => {
mockUpdateInfo.update.latest = '2.0.0-nightly';
mockUpdateInfo = {
...mockUpdateInfo,
update: {
...mockUpdateInfo.update,
latest: '2.0.0-nightly',
},
};
mockGetInstallationInfo.mockReturnValue({
updateCommand: 'npm i -g @google/gemini-cli@latest',
updateMessage: 'This is an additional message.',