1+ import os from 'node:os'
2+ import path from 'node:path'
3+
14import { beforeEach , describe , expect , it , vi } from 'vitest'
25
36import { handleAnalytics } from './handle-analytics.mts'
@@ -14,6 +17,8 @@ vi.mock('./output-analytics.mts', () => ({
1417} ) )
1518
1619describe ( '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' ,
0 commit comments