@@ -6,7 +6,7 @@ import { IExtensionContext } from '../../extension/common/types';
6
6
import { registerNoConfigDebug as registerNoConfigDebug } from '../../extension/noConfigDebugInit' ;
7
7
import * as TypeMoq from 'typemoq' ;
8
8
import * as sinon from 'sinon' ;
9
- import { DebugConfiguration , DebugSessionOptions , RelativePattern , Uri } from 'vscode' ;
9
+ import { DebugConfiguration , DebugSessionOptions , RelativePattern , Uri , workspace } from 'vscode' ;
10
10
import * as utils from '../../extension/utils' ;
11
11
import { assert } from 'console' ;
12
12
import * as fs from 'fs' ;
@@ -21,18 +21,15 @@ suite('setup for no-config debug scenario', function () {
21
21
let bundledDebugPath : string ;
22
22
let DEBUGPY_ADAPTER_ENDPOINTS = 'DEBUGPY_ADAPTER_ENDPOINTS' ;
23
23
let BUNDLED_DEBUGPY_PATH = 'BUNDLED_DEBUGPY_PATH' ;
24
- let tempDirPath : string ;
24
+ let workspaceUriStub : sinon . SinonStub ;
25
25
26
26
const testDataDir = path . join ( __dirname , 'testData' ) ;
27
27
const testFilePath = path . join ( testDataDir , 'debuggerAdapterEndpoint.txt' ) ;
28
28
setup ( ( ) => {
29
29
try {
30
30
context = TypeMoq . Mock . ofType < IExtensionContext > ( ) ;
31
31
32
- const randomSuffix = '1234567899' ;
33
- const tempDirName = `noConfigDebugAdapterEndpoints-${ randomSuffix } ` ;
34
- tempDirPath = path . join ( os . tmpdir ( ) , tempDirName ) ;
35
- context . setup ( ( c ) => ( c as any ) . extensionPath ) . returns ( ( ) => 'fake/extension/path' ) ;
32
+ context . setup ( ( c ) => ( c as any ) . extensionPath ) . returns ( ( ) => os . tmpdir ( ) ) ;
36
33
context . setup ( ( c ) => c . subscriptions ) . returns ( ( ) => [ ] ) ;
37
34
noConfigScriptsDir = path . join ( context . object . extensionPath , 'bundled/scripts/noConfigScripts' ) ;
38
35
bundledDebugPath = path . join ( context . object . extensionPath , 'bundled/libs/debugpy' ) ;
@@ -41,12 +38,15 @@ suite('setup for no-config debug scenario', function () {
41
38
let randomBytesStub = sinon . stub ( crypto , 'randomBytes' ) ;
42
39
// Provide a valid Buffer object
43
40
randomBytesStub . callsFake ( ( _size : number ) => Buffer . from ( '1234567899' , 'hex' ) ) ;
41
+
42
+ workspaceUriStub = sinon . stub ( workspace , 'workspaceFolders' ) . value ( [ { uri : Uri . parse ( os . tmpdir ( ) ) } ] ) ;
44
43
} catch ( error ) {
45
44
console . error ( 'Error in setup:' , error ) ;
46
45
}
47
46
} ) ;
48
47
teardown ( ( ) => {
49
48
sinon . restore ( ) ;
49
+ workspaceUriStub . restore ( ) ;
50
50
} ) ;
51
51
52
52
test ( 'should add environment variables for DEBUGPY_ADAPTER_ENDPOINTS, BUNDLED_DEBUGPY_PATH, and PATH' , async ( ) => {
@@ -59,7 +59,7 @@ suite('setup for no-config debug scenario', function () {
59
59
. setup ( ( x ) => x . replace ( TypeMoq . It . isAny ( ) , TypeMoq . It . isAny ( ) ) )
60
60
. callback ( ( key , value ) => {
61
61
if ( key === DEBUGPY_ADAPTER_ENDPOINTS ) {
62
- assert ( value . includes ( 'noConfigDebugAdapterEndpoints-1234567899 ' ) ) ;
62
+ assert ( value . includes ( 'endpoint- ' ) ) ;
63
63
} else if ( key === BUNDLED_DEBUGPY_PATH ) {
64
64
assert ( value === bundledDebugPath ) ;
65
65
} else if ( key === 'PYDEVD_DISABLE_FILE_VALIDATION' ) {
@@ -99,7 +99,7 @@ suite('setup for no-config debug scenario', function () {
99
99
100
100
// Assert
101
101
sinon . assert . calledOnce ( createFileSystemWatcherFunct ) ;
102
- const expectedPattern = new RelativePattern ( tempDirPath , '**/*' ) ;
102
+ const expectedPattern = new RelativePattern ( path . join ( os . tmpdir ( ) , '.noConfigDebugAdapterEndpoints' ) , '**/*' ) ;
103
103
sinon . assert . calledWith ( createFileSystemWatcherFunct , expectedPattern ) ;
104
104
} ) ;
105
105
@@ -163,6 +163,29 @@ suite('setup for no-config debug scenario', function () {
163
163
164
164
sinon . assert . calledWith ( debugStub , undefined , expectedConfig , optionsExpected ) ;
165
165
} ) ;
166
+
167
+ test ( 'should check if tempFilePath exists when debuggerAdapterEndpointFolder exists' , async ( ) => {
168
+ // Arrange
169
+ const environmentVariableCollectionMock = TypeMoq . Mock . ofType < any > ( ) ;
170
+ context . setup ( ( c ) => c . environmentVariableCollection ) . returns ( ( ) => environmentVariableCollectionMock . object ) ;
171
+
172
+ const fsExistsSyncStub = sinon . stub ( fs , 'existsSync' ) . returns ( true ) ;
173
+ const fsUnlinkSyncStub = sinon . stub ( fs , 'unlinkSync' ) ;
174
+
175
+ // Act
176
+ await registerNoConfigDebug ( context . object . environmentVariableCollection , context . object . extensionPath ) ;
177
+
178
+ // Assert
179
+ sinon . assert . calledWith (
180
+ fsExistsSyncStub ,
181
+ sinon . match ( ( value : any ) => value . includes ( 'endpoint-' ) ) ,
182
+ ) ;
183
+ sinon . assert . calledOnce ( fsUnlinkSyncStub ) ;
184
+
185
+ // Cleanup
186
+ fsExistsSyncStub . restore ( ) ;
187
+ fsUnlinkSyncStub . restore ( ) ;
188
+ } ) ;
166
189
} ) ;
167
190
168
191
function setupFileSystemWatchers ( ) : sinon . SinonStub {
0 commit comments