@@ -48,3 +48,79 @@ suite('writeTestIdsFile tests', () => {
4848 assert . ok ( writeFileStub . calledOnceWith ( sinon . match . string , testIds . join ( '\n' ) ) ) ;
4949 } ) ;
5050} ) ;
51+
52+ suite ( 'getTempDir tests' , ( ) => {
53+ let sandbox : sinon . SinonSandbox ;
54+ let originalPlatform : NodeJS . Platform ;
55+ let originalEnv : NodeJS . ProcessEnv ;
56+
57+ setup ( ( ) => {
58+ sandbox = sinon . createSandbox ( ) ;
59+ originalPlatform = process . platform ;
60+ originalEnv = process . env ;
61+ } ) ;
62+
63+ teardown ( ( ) => {
64+ sandbox . restore ( ) ;
65+ Object . defineProperty ( process , 'platform' , { value : originalPlatform } ) ;
66+ process . env = originalEnv ;
67+ } ) ;
68+
69+ test ( 'should use os.tmpdir on Windows' , async ( ) => {
70+ // Force platform to be Windows
71+ Object . defineProperty ( process , 'platform' , { value : 'win32' } ) ;
72+
73+ const tmpDirStub = sandbox . stub ( os , 'tmpdir' ) . returns ( '/windows/temp/path' ) ;
74+
75+ const testIds = [ 'test1' , 'test2' , 'test3' ] ;
76+ sandbox . stub ( fs . promises , 'access' ) . resolves ( ) ;
77+ sandbox . stub ( fs . promises , 'writeFile' ) . resolves ( ) ;
78+
79+ // This will use getTempDir internally
80+ const result = await writeTestIdsFile ( testIds ) ;
81+
82+ assert . ok ( result . startsWith ( '/windows/temp/path' ) ) ;
83+ assert . strictEqual ( tmpDirStub . callCount , 1 ) ;
84+ } ) ;
85+
86+ test ( 'should use XDG_RUNTIME_DIR on non-Windows if available' , async ( ) => {
87+ // Force platform to be Linux
88+ Object . defineProperty ( process , 'platform' , { value : 'linux' } ) ;
89+
90+ // Set up XDG_RUNTIME_DIR
91+ process . env = { ...process . env , XDG_RUNTIME_DIR : '/xdg/runtime/dir' } ;
92+
93+ const tmpDirStub = sandbox . stub ( os , 'tmpdir' ) . returns ( '/fallback/tmp/dir' ) ;
94+
95+ const testIds = [ 'test1' , 'test2' , 'test3' ] ;
96+ sandbox . stub ( fs . promises , 'access' ) . resolves ( ) ;
97+ sandbox . stub ( fs . promises , 'writeFile' ) . resolves ( ) ;
98+
99+ // This will use getTempDir internally
100+ const result = await writeTestIdsFile ( testIds ) ;
101+
102+ assert . ok ( result . startsWith ( '/xdg/runtime/dir' ) ) ;
103+ assert . strictEqual ( tmpDirStub . callCount , 0 ) ; // tmpdir should not be called
104+ } ) ;
105+
106+ test ( 'should fall back to os.tmpdir on non-Windows if XDG_RUNTIME_DIR not available' , async ( ) => {
107+ // Force platform to be macOS
108+ Object . defineProperty ( process , 'platform' , { value : 'darwin' } ) ;
109+
110+ // Ensure XDG_RUNTIME_DIR is not set
111+ process . env = { ...process . env } ;
112+ delete process . env . XDG_RUNTIME_DIR ;
113+
114+ const tmpDirStub = sandbox . stub ( os , 'tmpdir' ) . returns ( '/fallback/tmp/dir' ) ;
115+
116+ const testIds = [ 'test1' , 'test2' , 'test3' ] ;
117+ sandbox . stub ( fs . promises , 'access' ) . resolves ( ) ;
118+ sandbox . stub ( fs . promises , 'writeFile' ) . resolves ( ) ;
119+
120+ // This will use getTempDir internally
121+ const result = await writeTestIdsFile ( testIds ) ;
122+
123+ assert . ok ( result . startsWith ( '/fallback/tmp/dir' ) ) ;
124+ assert . strictEqual ( tmpDirStub . callCount , 1 ) ;
125+ } ) ;
126+ } ) ;
0 commit comments