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