Download projects/gemini-cli/packages/cli/src/utils/cleanup.test.ts from LevelUp2x/adaptai: direct link, hf CLI and curl.
- Browser
- Download file 1.71 kB
-
https://huggingface.co/datasets/LevelUp2x/adaptai/resolve/2147bc06c2ccf123b96f98eace2e6bf6486e7f0e/projects/gemini-cli/packages/cli/src/utils/cleanup.test.ts
- Command line
-
hf download hf://datasets/LevelUp2x/adaptai@2147bc06c2ccf123b96f98eace2e6bf6486e7f0e/projects/gemini-cli/packages/cli/src/utils/cleanup.test.ts
-
curl -L -o cleanup.test.ts https://huggingface.co/datasets/LevelUp2x/adaptai/resolve/2147bc06c2ccf123b96f98eace2e6bf6486e7f0e/projects/gemini-cli/packages/cli/src/utils/cleanup.test.ts
1.71 kB
| /** | |
| * @license | |
| * Copyright 2025 Google LLC | |
| * SPDX-License-Identifier: Apache-2.0 | |
| */ | |
| import { vi } from 'vitest'; | |
| import { registerCleanup, runExitCleanup } from './cleanup'; | |
| describe('cleanup', () => { | |
| const originalCleanupFunctions = global['cleanupFunctions']; | |
| beforeEach(() => { | |
| // Isolate cleanup functions for each test | |
| global['cleanupFunctions'] = []; | |
| }); | |
| afterAll(() => { | |
| // Restore original cleanup functions | |
| global['cleanupFunctions'] = originalCleanupFunctions; | |
| }); | |
| it('should run a registered synchronous function', async () => { | |
| const cleanupFn = vi.fn(); | |
| registerCleanup(cleanupFn); | |
| await runExitCleanup(); | |
| expect(cleanupFn).toHaveBeenCalledTimes(1); | |
| }); | |
| it('should run a registered asynchronous function', async () => { | |
| const cleanupFn = vi.fn().mockResolvedValue(undefined); | |
| registerCleanup(cleanupFn); | |
| await runExitCleanup(); | |
| expect(cleanupFn).toHaveBeenCalledTimes(1); | |
| }); | |
| it('should run multiple registered functions', async () => { | |
| const syncFn = vi.fn(); | |
| const asyncFn = vi.fn().mockResolvedValue(undefined); | |
| registerCleanup(syncFn); | |
| registerCleanup(asyncFn); | |
| await runExitCleanup(); | |
| 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 successFn = vi.fn(); | |
| registerCleanup(errorFn); | |
| registerCleanup(successFn); | |
| await runExitCleanup(); | |
| expect(errorFn).toHaveBeenCalledTimes(1); | |
| expect(successFn).toHaveBeenCalledTimes(1); | |
| }); | |
| }); | |