|
| 1 | +import * as path from 'path'; |
| 2 | +import { IExtensionContext } from '../../extension/common/types'; |
| 3 | +import { registerConfiglessDebug } from '../../extension/noConfigDebugInit'; |
| 4 | +import * as TypeMoq from 'typemoq'; |
| 5 | +import * as sinon from 'sinon'; |
| 6 | +import { Uri } from 'vscode'; |
| 7 | +import * as utils from '../../extension/utils'; |
| 8 | +import { assert } from 'console'; |
| 9 | +import * as fs from 'fs'; |
| 10 | + |
| 11 | +suite('registerConfiglessDebug', function () { |
| 12 | + this.timeout(100000); // Increase timeout to 10 seconds |
| 13 | + let replaceStub: sinon.SinonStub; |
| 14 | + let appendStub: sinon.SinonStub; |
| 15 | + let context: TypeMoq.IMock<IExtensionContext>; |
| 16 | + let createFileSystemWatcher: sinon.SinonStub; |
| 17 | + |
| 18 | + setup(() => { |
| 19 | + context = TypeMoq.Mock.ofType<IExtensionContext>(); |
| 20 | + |
| 21 | + context.setup((c) => c.storageUri).returns(() => Uri.parse('a')); |
| 22 | + context.setup((c) => (c as any).extensionPath).returns(() => 'b'); |
| 23 | + context.setup((c) => c.subscriptions).returns(() => []); |
| 24 | + |
| 25 | + createFileSystemWatcher = sinon.stub(utils, 'createFileSystemWatcher'); |
| 26 | + createFileSystemWatcher.callsFake(() => { |
| 27 | + return { |
| 28 | + onDidCreate: (cb: (arg0: Uri) => void) => { |
| 29 | + cb(Uri.parse('a')); |
| 30 | + }, |
| 31 | + }; |
| 32 | + }); |
| 33 | + sinon.stub(fs, 'readFile').callsFake( |
| 34 | + (TypeMoq.It.isAny(), |
| 35 | + TypeMoq.It.isAny(), |
| 36 | + (err, data) => { |
| 37 | + console.log(err, data); |
| 38 | + }), |
| 39 | + ); |
| 40 | + }); |
| 41 | + teardown(() => { |
| 42 | + sinon.restore(); |
| 43 | + }); |
| 44 | + |
| 45 | + test('should add environment variables for DEBUGPY_ADAPTER_ENDPOINTS, BUNDLED_DEBUGPY_PATH, and PATH', async () => { |
| 46 | + const debugAdapterEndpointDir = path.join(context.object.extensionPath, 'noConfigDebugAdapterEndpoints'); |
| 47 | + const debuggerAdapterEndpointPath = path.join(debugAdapterEndpointDir, 'debuggerAdapterEndpoint.txt'); |
| 48 | + const noConfigScriptsDir = path.join(context.object.extensionPath, 'bundled/scripts/noConfigScripts'); |
| 49 | + const bundledDebugPath = path.join(context.object.extensionPath, 'bundled/libs/debugpy'); |
| 50 | + |
| 51 | + const environmentVariableCollectionMock = TypeMoq.Mock.ofType<any>(); |
| 52 | + replaceStub = sinon.stub(); |
| 53 | + appendStub = sinon.stub(); |
| 54 | + environmentVariableCollectionMock |
| 55 | + .setup((x) => x.replace(TypeMoq.It.isAny(), TypeMoq.It.isAny())) |
| 56 | + .callback((key, value) => { |
| 57 | + if (key === 'DEBUGPY_ADAPTER_ENDPOINTS') { |
| 58 | + assert(value === debuggerAdapterEndpointPath); |
| 59 | + } else if (key === 'BUNDLED_DEBUGPY_PATH') { |
| 60 | + assert(value === bundledDebugPath); |
| 61 | + } |
| 62 | + }) |
| 63 | + .returns(replaceStub); |
| 64 | + environmentVariableCollectionMock |
| 65 | + .setup((x) => x.append(TypeMoq.It.isAny(), TypeMoq.It.isAny())) |
| 66 | + .callback((key, value) => { |
| 67 | + if (key === 'PATH') { |
| 68 | + assert(value === `:${noConfigScriptsDir}`); |
| 69 | + } |
| 70 | + }) |
| 71 | + .returns(appendStub); |
| 72 | + |
| 73 | + context.setup((c) => c.environmentVariableCollection).returns(() => environmentVariableCollectionMock.object); |
| 74 | + |
| 75 | + await registerConfiglessDebug(context.object); |
| 76 | + console.log('All done!'); |
| 77 | + sinon.assert.calledTwice(replaceStub); |
| 78 | + }); |
| 79 | +}); |
0 commit comments