@@ -6,7 +6,7 @@ import { IExtensionContext } from '../../extension/common/types';
66import { registerNoConfigDebug as registerNoConfigDebug } from '../../extension/noConfigDebugInit' ;
77import * as TypeMoq from 'typemoq' ;
88import * as sinon from 'sinon' ;
9- import { DebugConfiguration , DebugSessionOptions , RelativePattern , Uri } from 'vscode' ;
9+ import { DebugConfiguration , DebugSessionOptions , RelativePattern , Uri , workspace } from 'vscode' ;
1010import * as utils from '../../extension/utils' ;
1111import { assert } from 'console' ;
1212import * as fs from 'fs' ;
@@ -21,18 +21,15 @@ suite('setup for no-config debug scenario', function () {
2121 let bundledDebugPath : string ;
2222 let DEBUGPY_ADAPTER_ENDPOINTS = 'DEBUGPY_ADAPTER_ENDPOINTS' ;
2323 let BUNDLED_DEBUGPY_PATH = 'BUNDLED_DEBUGPY_PATH' ;
24- let tempDirPath : string ;
24+ let workspaceUriStub : sinon . SinonStub ;
2525
2626 const testDataDir = path . join ( __dirname , 'testData' ) ;
2727 const testFilePath = path . join ( testDataDir , 'debuggerAdapterEndpoint.txt' ) ;
2828 setup ( ( ) => {
2929 try {
3030 context = TypeMoq . Mock . ofType < IExtensionContext > ( ) ;
3131
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 ( ) ) ;
3633 context . setup ( ( c ) => c . subscriptions ) . returns ( ( ) => [ ] ) ;
3734 noConfigScriptsDir = path . join ( context . object . extensionPath , 'bundled/scripts/noConfigScripts' ) ;
3835 bundledDebugPath = path . join ( context . object . extensionPath , 'bundled/libs/debugpy' ) ;
@@ -41,12 +38,15 @@ suite('setup for no-config debug scenario', function () {
4138 let randomBytesStub = sinon . stub ( crypto , 'randomBytes' ) ;
4239 // Provide a valid Buffer object
4340 randomBytesStub . callsFake ( ( _size : number ) => Buffer . from ( '1234567899' , 'hex' ) ) ;
41+
42+ workspaceUriStub = sinon . stub ( workspace , 'workspaceFolders' ) . value ( [ { uri : Uri . parse ( os . tmpdir ( ) ) } ] ) ;
4443 } catch ( error ) {
4544 console . error ( 'Error in setup:' , error ) ;
4645 }
4746 } ) ;
4847 teardown ( ( ) => {
4948 sinon . restore ( ) ;
49+ workspaceUriStub . restore ( ) ;
5050 } ) ;
5151
5252 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 () {
5959 . setup ( ( x ) => x . replace ( TypeMoq . It . isAny ( ) , TypeMoq . It . isAny ( ) ) )
6060 . callback ( ( key , value ) => {
6161 if ( key === DEBUGPY_ADAPTER_ENDPOINTS ) {
62- assert ( value . includes ( 'noConfigDebugAdapterEndpoints-1234567899 ' ) ) ;
62+ assert ( value . includes ( 'endpoint- ' ) ) ;
6363 } else if ( key === BUNDLED_DEBUGPY_PATH ) {
6464 assert ( value === bundledDebugPath ) ;
6565 } else if ( key === 'PYDEVD_DISABLE_FILE_VALIDATION' ) {
@@ -99,7 +99,7 @@ suite('setup for no-config debug scenario', function () {
9999
100100 // Assert
101101 sinon . assert . calledOnce ( createFileSystemWatcherFunct ) ;
102- const expectedPattern = new RelativePattern ( tempDirPath , '**/*' ) ;
102+ const expectedPattern = new RelativePattern ( path . join ( os . tmpdir ( ) , '.noConfigDebugAdapterEndpoints' ) , '**/*' ) ;
103103 sinon . assert . calledWith ( createFileSystemWatcherFunct , expectedPattern ) ;
104104 } ) ;
105105
@@ -163,6 +163,29 @@ suite('setup for no-config debug scenario', function () {
163163
164164 sinon . assert . calledWith ( debugStub , undefined , expectedConfig , optionsExpected ) ;
165165 } ) ;
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+ } ) ;
166189} ) ;
167190
168191function setupFileSystemWatchers ( ) : sinon . SinonStub {
0 commit comments