Skip to content

Commit e7ae355

Browse files
committed
test: isolate ozone test directories
1 parent e348056 commit e7ae355

1 file changed

Lines changed: 12 additions & 9 deletions

File tree

‎src/main/ozone.test.ts‎

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
11
import fs from 'node:fs';
2+
import os from 'node:os';
23
import path from 'node:path';
34

45
import { applyOzonePlatform, isX11BackendEnabled, setX11Backend } from './ozone';
56

6-
const USER_DATA = '/tmp/gitify-test-userdata';
7-
const MARKER = path.join(USER_DATA, 'UseX11Backend');
7+
let userData: string;
8+
let marker: string;
89

10+
const getPathMock = vi.hoisted(() => vi.fn<(name: string) => string>());
911
const appendSwitchMock = vi.fn();
1012

1113
vi.mock('electron', () => ({
1214
app: {
13-
getPath: (name: string) => (name === 'userData' ? '/tmp/gitify-test-userdata' : ''),
15+
getPath: getPathMock,
1416
commandLine: {
1517
appendSwitch: (...a: unknown[]) => appendSwitchMock(...a),
1618
},
@@ -34,14 +36,15 @@ describe('main/ozone.ts', () => {
3436

3537
beforeEach(() => {
3638
vi.clearAllMocks();
37-
// Electron creates userData for a real app; the stubbed path needs it too.
38-
fs.mkdirSync(USER_DATA, { recursive: true });
39-
fs.rmSync(MARKER, { force: true });
39+
userData = fs.mkdtempSync(path.join(os.tmpdir(), 'gitify-ozone-'));
40+
marker = path.join(userData, 'UseX11Backend');
41+
getPathMock.mockImplementation((name) => (name === 'userData' ? userData : ''));
4042
});
4143

4244
afterEach(() => {
45+
vi.restoreAllMocks();
4346
setPlatform(realPlatform);
44-
fs.rmSync(MARKER, { force: true });
47+
fs.rmSync(userData, { recursive: true, force: true });
4548
});
4649

4750
describe('setX11Backend / isX11BackendEnabled', () => {
@@ -51,11 +54,11 @@ describe('main/ozone.ts', () => {
5154

5255
it('round-trips the preference through the marker file', () => {
5356
setX11Backend(true);
54-
expect(fs.existsSync(MARKER)).toBe(true);
57+
expect(fs.existsSync(marker)).toBe(true);
5558
expect(isX11BackendEnabled()).toBe(true);
5659

5760
setX11Backend(false);
58-
expect(fs.existsSync(MARKER)).toBe(false);
61+
expect(fs.existsSync(marker)).toBe(false);
5962
expect(isX11BackendEnabled()).toBe(false);
6063
});
6164

0 commit comments

Comments
 (0)