Skip to content

Commit 68e21c1

Browse files
committed
test: use os.tmpdir() instead of hardcoded /tmp paths
Replace hardcoded /tmp paths with os.tmpdir() for cross-platform compatibility. Fixes test failures on Windows where /tmp directory doesn't exist.
1 parent e6905a9 commit 68e21c1

File tree

3 files changed

+19
-11
lines changed

3 files changed

+19
-11
lines changed

src/commands/analytics/handle-analytics.test.mts

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
import os from 'node:os'
2+
import path from 'node:path'
3+
14
import { beforeEach, describe, expect, it, vi } from 'vitest'
25

36
import { handleAnalytics } from './handle-analytics.mts'
@@ -14,6 +17,8 @@ vi.mock('./output-analytics.mts', () => ({
1417
}))
1518

1619
describe('handleAnalytics', () => {
20+
const tmpAnalyticsPath = path.join(os.tmpdir(), 'analytics.json')
21+
1722
beforeEach(() => {
1823
vi.clearAllMocks()
1924
})
@@ -29,7 +34,7 @@ describe('handleAnalytics', () => {
2934
})
3035

3136
await handleAnalytics({
32-
filepath: '/tmp/analytics.json',
37+
filepath: tmpAnalyticsPath,
3338
outputKind: 'json',
3439
repo: '',
3540
scope: 'org',
@@ -40,7 +45,7 @@ describe('handleAnalytics', () => {
4045
expect(outputAnalytics).toHaveBeenCalledWith(
4146
{ ok: true, data: mockData },
4247
{
43-
filepath: '/tmp/analytics.json',
48+
filepath: tmpAnalyticsPath,
4449
outputKind: 'json',
4550
repo: '',
4651
scope: 'org',
@@ -62,7 +67,7 @@ describe('handleAnalytics', () => {
6267
})
6368

6469
await handleAnalytics({
65-
filepath: '/tmp/analytics.json',
70+
filepath: tmpAnalyticsPath,
6671
outputKind: 'json',
6772
repo: 'test-repo',
6873
scope: 'repo',
@@ -73,7 +78,7 @@ describe('handleAnalytics', () => {
7378
expect(outputAnalytics).toHaveBeenCalledWith(
7479
{ ok: true, data: mockData },
7580
{
76-
filepath: '/tmp/analytics.json',
81+
filepath: tmpAnalyticsPath,
7782
outputKind: 'json',
7883
repo: 'test-repo',
7984
scope: 'repo',
@@ -86,7 +91,7 @@ describe('handleAnalytics', () => {
8691
const { outputAnalytics } = await import('./output-analytics.mts')
8792

8893
await handleAnalytics({
89-
filepath: '/tmp/analytics.json',
94+
filepath: tmpAnalyticsPath,
9095
outputKind: 'json',
9196
repo: '',
9297
scope: 'repo',
@@ -99,7 +104,7 @@ describe('handleAnalytics', () => {
99104
message: 'Missing repository name in command',
100105
},
101106
{
102-
filepath: '/tmp/analytics.json',
107+
filepath: tmpAnalyticsPath,
103108
outputKind: 'json',
104109
repo: '',
105110
scope: 'repo',
@@ -118,7 +123,7 @@ describe('handleAnalytics', () => {
118123
})
119124

120125
await handleAnalytics({
121-
filepath: '/tmp/analytics.json',
126+
filepath: tmpAnalyticsPath,
122127
outputKind: 'json',
123128
repo: '',
124129
scope: 'org',
@@ -148,7 +153,7 @@ describe('handleAnalytics', () => {
148153
})
149154

150155
await handleAnalytics({
151-
filepath: '/tmp/analytics.json',
156+
filepath: tmpAnalyticsPath,
152157
outputKind: 'json',
153158
repo: 'test-repo',
154159
scope: 'repo',
@@ -176,7 +181,7 @@ describe('handleAnalytics', () => {
176181
})
177182

178183
await handleAnalytics({
179-
filepath: '/tmp/analytics.json',
184+
filepath: tmpAnalyticsPath,
180185
outputKind: 'json',
181186
repo: '',
182187
scope: 'org',

src/utils/dlx-detection.test.mts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import os from 'node:os'
12
import path from 'node:path'
23

34
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
@@ -142,7 +143,7 @@ describe('dlx-detection', () => {
142143

143144
it('skips when cwd contains dlx- prefix', () => {
144145
const result = shouldSkipShadow('/usr/local/bin/pnpm', {
145-
cwd: '/tmp/dlx-socket-cli-12345/node_modules/.bin',
146+
cwd: path.join(os.tmpdir(), 'dlx-socket-cli-12345/node_modules/.bin'),
146147
})
147148
expect(result).toBe(true)
148149
})

src/utils/tildify.test.mts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import os from 'node:os'
12
import path from 'node:path'
23

34
import { describe, expect, it, vi } from 'vitest'
@@ -54,7 +55,8 @@ describe('tildify utilities', () => {
5455

5556
it('leaves non-home paths unchanged', () => {
5657
expect(tildify('/var/log/system.log')).toBe('/var/log/system.log')
57-
expect(tildify('/tmp/file.txt')).toBe('/tmp/file.txt')
58+
const tmpPath = path.join(os.tmpdir(), 'file.txt')
59+
expect(tildify(tmpPath)).toBe(tmpPath)
5860
expect(tildify('./relative/path')).toBe('./relative/path')
5961
expect(tildify('../parent/path')).toBe('../parent/path')
6062
})

0 commit comments

Comments
 (0)