mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-03-10 22:21:22 -07:00
chore: update tests with removed exclude from cli tsconfig (#11540)
This commit is contained in:
@@ -121,7 +121,7 @@ describe('computeSessionStats', () => {
|
||||
totalSuccess: 0,
|
||||
totalFail: 0,
|
||||
totalDurationMs: 0,
|
||||
totalDecisions: { accept: 0, reject: 0, modify: 0 },
|
||||
totalDecisions: { accept: 0, reject: 0, modify: 0, auto_accept: 0 },
|
||||
byName: {},
|
||||
},
|
||||
files: {
|
||||
@@ -169,7 +169,7 @@ describe('computeSessionStats', () => {
|
||||
totalSuccess: 1,
|
||||
totalFail: 0,
|
||||
totalDurationMs: 250,
|
||||
totalDecisions: { accept: 0, reject: 0, modify: 0 },
|
||||
totalDecisions: { accept: 0, reject: 0, modify: 0, auto_accept: 0 },
|
||||
byName: {},
|
||||
},
|
||||
files: {
|
||||
@@ -207,7 +207,7 @@ describe('computeSessionStats', () => {
|
||||
totalSuccess: 0,
|
||||
totalFail: 0,
|
||||
totalDurationMs: 0,
|
||||
totalDecisions: { accept: 0, reject: 0, modify: 0 },
|
||||
totalDecisions: { accept: 0, reject: 0, modify: 0, auto_accept: 0 },
|
||||
byName: {},
|
||||
},
|
||||
files: {
|
||||
@@ -229,7 +229,7 @@ describe('computeSessionStats', () => {
|
||||
totalSuccess: 8,
|
||||
totalFail: 2,
|
||||
totalDurationMs: 1000,
|
||||
totalDecisions: { accept: 6, reject: 2, modify: 2 },
|
||||
totalDecisions: { accept: 6, reject: 2, modify: 2, auto_accept: 0 },
|
||||
byName: {},
|
||||
},
|
||||
files: {
|
||||
@@ -252,7 +252,7 @@ describe('computeSessionStats', () => {
|
||||
totalSuccess: 0,
|
||||
totalFail: 0,
|
||||
totalDurationMs: 0,
|
||||
totalDecisions: { accept: 0, reject: 0, modify: 0 },
|
||||
totalDecisions: { accept: 0, reject: 0, modify: 0, auto_accept: 0 },
|
||||
byName: {},
|
||||
},
|
||||
files: {
|
||||
@@ -278,7 +278,7 @@ describe('computeSessionStats', () => {
|
||||
totalSuccess: 0,
|
||||
totalFail: 0,
|
||||
totalDurationMs: 0,
|
||||
totalDecisions: { accept: 0, reject: 0, modify: 0 },
|
||||
totalDecisions: { accept: 0, reject: 0, modify: 0, auto_accept: 0 },
|
||||
byName: {},
|
||||
},
|
||||
files: {
|
||||
|
||||
@@ -60,12 +60,15 @@ export const computeSessionStats = (
|
||||
const totalDecisions =
|
||||
tools.totalDecisions.accept +
|
||||
tools.totalDecisions.reject +
|
||||
tools.totalDecisions.modify;
|
||||
tools.totalDecisions.modify +
|
||||
tools.totalDecisions.auto_accept;
|
||||
const successRate =
|
||||
tools.totalCalls > 0 ? (tools.totalSuccess / tools.totalCalls) * 100 : 0;
|
||||
const agreementRate =
|
||||
totalDecisions > 0
|
||||
? (tools.totalDecisions.accept / totalDecisions) * 100
|
||||
? ((tools.totalDecisions.accept + tools.totalDecisions.auto_accept) /
|
||||
totalDecisions) *
|
||||
100
|
||||
: 0;
|
||||
|
||||
return {
|
||||
|
||||
@@ -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.',
|
||||
|
||||
@@ -13,14 +13,6 @@
|
||||
"src/**/*.json",
|
||||
"./package.json"
|
||||
],
|
||||
"exclude": [
|
||||
"node_modules",
|
||||
"dist",
|
||||
// TODO(5691): Fix type errors and remove excludes.
|
||||
"src/utils/cleanup.test.ts",
|
||||
"src/utils/handleAutoUpdate.test.ts",
|
||||
"src/utils/startupWarnings.test.ts",
|
||||
"src/ui/utils/computeStats.test.ts"
|
||||
],
|
||||
"exclude": ["node_modules", "dist"],
|
||||
"references": [{ "path": "../core" }]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user