test: isolate Ghostty import config env

This commit is contained in:
Neil
2026-05-31 08:40:47 -07:00
parent e82e48d290
commit 2857805b66
+13 -1
View File
@@ -1,6 +1,6 @@
import type { Store } from '../persistence'
import type { GlobalSettings } from '../../shared/types'
import { describe, expect, it, vi } from 'vitest'
import { afterEach, describe, expect, it, vi } from 'vitest'
const { statMock, readFileMock } = vi.hoisted(() => ({
statMock: vi.fn(),
@@ -19,6 +19,17 @@ vi.mock('os', () => ({
import { previewGhosttyImport } from './index'
const originalXdgConfigHome = process.env.XDG_CONFIG_HOME
afterEach(() => {
vi.clearAllMocks()
if (originalXdgConfigHome !== undefined) {
process.env.XDG_CONFIG_HOME = originalXdgConfigHome
} else {
delete process.env.XDG_CONFIG_HOME
}
})
function createStore(settings: Record<string, unknown> = {}): Store {
return {
getSettings: () => settings as GlobalSettings
@@ -67,6 +78,7 @@ background = #1a1a1a
})
it('imports every discovered config file in Ghostty load order', async () => {
delete process.env.XDG_CONFIG_HOME
statMock.mockImplementation(async (p: string) => {
if (
p === '/Users/alice/.config/ghostty/config.ghostty' ||