mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-03-20 11:00:40 -07:00
chore: update tests with removed exclude from cli tsconfig (#11540)
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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.',
|
||||
|
||||
Reference in New Issue
Block a user