Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions packages/core/src/ide/detect-ide.test.ts
Original file line number Diff line number Diff line change
@@ -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();
});
});
});