diff options
| author | Pyush Sinha <[email protected]> | 2025-07-05 23:27:00 -0700 |
|---|---|---|
| committer | GitHub <[email protected]> | 2025-07-06 06:27:00 +0000 |
| commit | 39e8509452b359774cc363a7e98810e48ec516a4 (patch) | |
| tree | 84807b28a1be51bfd89212114244559c241f5d64 /packages/cli/src/utils/userStartupWarnings.test.ts | |
| parent | da9b1baa6e64ac9c83c988b580d45423ce7d574d (diff) | |
feat: add user startup warnings, add home directory check (#3056)
Diffstat (limited to 'packages/cli/src/utils/userStartupWarnings.test.ts')
| -rw-r--r-- | packages/cli/src/utils/userStartupWarnings.test.ts | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/packages/cli/src/utils/userStartupWarnings.test.ts b/packages/cli/src/utils/userStartupWarnings.test.ts new file mode 100644 index 00000000..61053029 --- /dev/null +++ b/packages/cli/src/utils/userStartupWarnings.test.ts @@ -0,0 +1,74 @@ +/** + * @license + * Copyright 2025 Google LLC + * SPDX-License-Identifier: Apache-2.0 + */ + +import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest'; +import { getUserStartupWarnings } from './userStartupWarnings.js'; +import * as os from 'os'; +import fs from 'fs/promises'; + +vi.mock('os', () => ({ + default: { homedir: vi.fn() }, + homedir: vi.fn(), +})); + +vi.mock('fs/promises', () => ({ + default: { realpath: vi.fn() }, +})); + +describe('getUserStartupWarnings', () => { + const homeDir = '/home/user'; + + beforeEach(() => { + vi.mocked(os.homedir).mockReturnValue(homeDir); + vi.mocked(fs.realpath).mockImplementation(async (path) => path.toString()); + }); + + afterEach(() => { + vi.clearAllMocks(); + }); + + describe('home directory check', () => { + it('should return a warning when running in home directory', async () => { + vi.mocked(fs.realpath) + .mockResolvedValueOnce(homeDir) + .mockResolvedValueOnce(homeDir); + + const warnings = await getUserStartupWarnings(homeDir); + + expect(warnings).toContainEqual( + expect.stringContaining('home directory'), + ); + }); + + it('should not return a warning when running in a project directory', async () => { + vi.mocked(fs.realpath) + .mockResolvedValueOnce('/some/project/path') + .mockResolvedValueOnce(homeDir); + + const warnings = await getUserStartupWarnings('/some/project/path'); + expect(warnings).not.toContainEqual( + expect.stringContaining('home directory'), + ); + }); + + it('should handle errors when checking directory', async () => { + vi.mocked(fs.realpath) + .mockRejectedValueOnce(new Error('FS error')) + .mockResolvedValueOnce(homeDir); + + const warnings = await getUserStartupWarnings('/error/path'); + expect(warnings).toContainEqual( + expect.stringContaining('Could not verify'), + ); + }); + }); + + // // Example of how to add a new check: + // describe('node version check', () => { + // // Tests for node version check would go here + // // This shows how easy it is to add new test sections + // }); +}); |
