From e2b0f24e79a05c7d911cd3409af89dfd406a9ba7 Mon Sep 17 00:00:00 2001 From: TrueAlpha-spiral <199723968+TrueAlpha-spiral@users.noreply.github.com> Date: Tue, 17 Mar 2026 20:52:02 +0000 Subject: [PATCH] test: add tests for getIdeDisplayName and detectIde This commit adds a new test file, `packages/core/src/ide/detect-ide.test.ts`, which tests the `getIdeDisplayName` and `detectIde` functions. The tests cover the current single implementation case for VS Code and utilize `vi.stubEnv` to effectively verify the environment-based detection logic. Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com> --- packages/core/src/ide/detect-ide.test.ts | 39 ++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 packages/core/src/ide/detect-ide.test.ts diff --git a/packages/core/src/ide/detect-ide.test.ts b/packages/core/src/ide/detect-ide.test.ts new file mode 100644 index 00000000000..c868090c832 --- /dev/null +++ b/packages/core/src/ide/detect-ide.test.ts @@ -0,0 +1,39 @@ +/** + * @license + * Copyright 2025 Google LLC + * SPDX-License-Identifier: Apache-2.0 + */ + +import { describe, it, expect, beforeEach, afterEach, vi } from 'vitest'; +import { DetectedIde, getIdeDisplayName, detectIde } from './detect-ide.js'; + +describe('detect-ide', () => { + describe('getIdeDisplayName', () => { + it('should return "VS Code" for DetectedIde.VSCode', () => { + expect(getIdeDisplayName(DetectedIde.VSCode)).toBe('VS Code'); + }); + }); + + describe('detectIde', () => { + afterEach(() => { + vi.unstubAllEnvs(); + }); + + it('should return DetectedIde.VSCode if TERM_PROGRAM is vscode', () => { + vi.stubEnv('TERM_PROGRAM', 'vscode'); + expect(detectIde()).toBe(DetectedIde.VSCode); + }); + + it('should return undefined if TERM_PROGRAM is not vscode', () => { + vi.stubEnv('TERM_PROGRAM', 'something-else'); + expect(detectIde()).toBeUndefined(); + }); + + it('should return undefined if TERM_PROGRAM is not set', () => { + // Vitest's vi.unstubAllEnvs or setting to empty isn't perfectly unsetting it, but we can set it to undefined explicitly + // Actually, let's just use stubEnv to remove it temporarily + vi.stubEnv('TERM_PROGRAM', ''); + expect(detectIde()).toBeUndefined(); + }); + }); +});