@@ -2,7 +2,6 @@ import * as assert from 'assert';
2
2
import * as sinon from 'sinon' ;
3
3
import * as fs from 'fs' ;
4
4
import * as path from 'path' ;
5
- import * as os from 'os' ;
6
5
import { writeTestIdsFile } from '../../../client/testing/testController/common/utils' ;
7
6
import { EXTENSION_ROOT_DIR } from '../../../client/constants' ;
8
7
@@ -21,11 +20,13 @@ suite('writeTestIdsFile tests', () => {
21
20
const testIds = [ 'test1' , 'test2' , 'test3' ] ;
22
21
const writeFileStub = sandbox . stub ( fs . promises , 'writeFile' ) . resolves ( ) ;
23
22
24
- const result = await writeTestIdsFile ( testIds ) ;
25
-
26
- const tmpDir = os . tmpdir ( ) ;
23
+ // Set up XDG_RUNTIME_DIR
24
+ process . env = {
25
+ ...process . env ,
26
+ XDG_RUNTIME_DIR : '/xdg/runtime/dir' ,
27
+ } ;
27
28
28
- assert . ok ( result . startsWith ( tmpDir ) ) ;
29
+ await writeTestIdsFile ( testIds ) ;
29
30
30
31
assert . ok ( writeFileStub . calledOnceWith ( sinon . match . string , testIds . join ( '\n' ) ) ) ;
31
32
} ) ;
@@ -48,3 +49,41 @@ suite('writeTestIdsFile tests', () => {
48
49
assert . ok ( writeFileStub . calledOnceWith ( sinon . match . string , testIds . join ( '\n' ) ) ) ;
49
50
} ) ;
50
51
} ) ;
52
+
53
+ suite ( 'getTempDir tests' , ( ) => {
54
+ let sandbox : sinon . SinonSandbox ;
55
+ let originalPlatform : NodeJS . Platform ;
56
+ let originalEnv : NodeJS . ProcessEnv ;
57
+
58
+ setup ( ( ) => {
59
+ sandbox = sinon . createSandbox ( ) ;
60
+ originalPlatform = process . platform ;
61
+ originalEnv = process . env ;
62
+ } ) ;
63
+
64
+ teardown ( ( ) => {
65
+ sandbox . restore ( ) ;
66
+ Object . defineProperty ( process , 'platform' , { value : originalPlatform } ) ;
67
+ process . env = originalEnv ;
68
+ } ) ;
69
+
70
+ test ( 'should use XDG_RUNTIME_DIR on non-Windows if available' , async ( ) => {
71
+ if ( process . platform === 'win32' ) {
72
+ return ;
73
+ }
74
+ // Force platform to be Linux
75
+ Object . defineProperty ( process , 'platform' , { value : 'linux' } ) ;
76
+
77
+ // Set up XDG_RUNTIME_DIR
78
+ process . env = { ...process . env , XDG_RUNTIME_DIR : '/xdg/runtime/dir' } ;
79
+
80
+ const testIds = [ 'test1' , 'test2' , 'test3' ] ;
81
+ sandbox . stub ( fs . promises , 'access' ) . resolves ( ) ;
82
+ sandbox . stub ( fs . promises , 'writeFile' ) . resolves ( ) ;
83
+
84
+ // This will use getTempDir internally
85
+ const result = await writeTestIdsFile ( testIds ) ;
86
+
87
+ assert . ok ( result . startsWith ( '/xdg/runtime/dir' ) ) ;
88
+ } ) ;
89
+ } ) ;
0 commit comments