diff options
| author | christine betts <[email protected]> | 2025-07-30 21:26:31 +0000 |
|---|---|---|
| committer | GitHub <[email protected]> | 2025-07-30 21:26:31 +0000 |
| commit | 7bc876654254d9a11d66135735ad10f1066ad213 (patch) | |
| tree | 3b21e328199f8631c0d865fdf041103c18bd261e /packages/core/src/ide/ide-installer.test.ts | |
| parent | c1fe6889569610878c45216556fb99424b5bcba4 (diff) | |
Introduce IDE mode installer (#4877)
Diffstat (limited to 'packages/core/src/ide/ide-installer.test.ts')
| -rw-r--r-- | packages/core/src/ide/ide-installer.test.ts | 90 |
1 files changed, 90 insertions, 0 deletions
diff --git a/packages/core/src/ide/ide-installer.test.ts b/packages/core/src/ide/ide-installer.test.ts new file mode 100644 index 00000000..83459d6b --- /dev/null +++ b/packages/core/src/ide/ide-installer.test.ts @@ -0,0 +1,90 @@ +/** + * @license + * Copyright 2025 Google LLC + * SPDX-License-Identifier: Apache-2.0 + */ + +import { vi, describe, it, expect, beforeEach, afterEach } from 'vitest'; +import { getIdeInstaller, IdeInstaller } from './ide-installer.js'; +import * as child_process from 'child_process'; +import * as fs from 'fs'; +import * as os from 'os'; +import { DetectedIde } from './detect-ide.js'; + +vi.mock('child_process'); +vi.mock('fs'); +vi.mock('os'); + +describe('ide-installer', () => { + describe('getIdeInstaller', () => { + it('should return a VsCodeInstaller for "vscode"', () => { + const installer = getIdeInstaller(DetectedIde.VSCode); + expect(installer).not.toBeNull(); + // A more specific check might be needed if we export the class + expect(installer).toBeInstanceOf(Object); + }); + + it('should return null for an unknown IDE', () => { + const installer = getIdeInstaller('unknown' as DetectedIde); + expect(installer).toBeNull(); + }); + }); + + describe('VsCodeInstaller', () => { + let installer: IdeInstaller; + + beforeEach(() => { + // We get a new installer for each test to reset the find command logic + installer = getIdeInstaller(DetectedIde.VSCode)!; + vi.spyOn(child_process, 'execSync').mockImplementation(() => ''); + vi.spyOn(fs, 'existsSync').mockReturnValue(false); + vi.spyOn(os, 'homedir').mockReturnValue('/home/user'); + }); + + afterEach(() => { + vi.restoreAllMocks(); + }); + + describe('isInstalled', () => { + it('should return true if command is in PATH', async () => { + expect(await installer.isInstalled()).toBe(true); + }); + + it('should return true if command is in a known location', async () => { + vi.spyOn(child_process, 'execSync').mockImplementation(() => { + throw new Error('Command not found'); + }); + vi.spyOn(fs, 'existsSync').mockReturnValue(true); + // Re-create the installer so it re-runs findVsCodeCommand + installer = getIdeInstaller(DetectedIde.VSCode)!; + expect(await installer.isInstalled()).toBe(true); + }); + + it('should return false if command is not found', async () => { + vi.spyOn(child_process, 'execSync').mockImplementation(() => { + throw new Error('Command not found'); + }); + vi.spyOn(fs, 'existsSync').mockReturnValue(false); + // Re-create the installer so it re-runs findVsCodeCommand + installer = getIdeInstaller(DetectedIde.VSCode)!; + expect(await installer.isInstalled()).toBe(false); + }); + }); + + describe('install', () => { + it('should return a failure message if VS Code is not installed', async () => { + vi.spyOn(child_process, 'execSync').mockImplementation(() => { + throw new Error('Command not found'); + }); + vi.spyOn(fs, 'existsSync').mockReturnValue(false); + // Re-create the installer so it re-runs findVsCodeCommand + installer = getIdeInstaller(DetectedIde.VSCode)!; + const result = await installer.install(); + expect(result.success).toBe(false); + expect(result.message).toContain( + 'not found in your PATH or common installation locations', + ); + }); + }); + }); +}); |
