From 37cae2bc3ad8e48856ac44263f73783236f01e01 Mon Sep 17 00:00:00 2001 From: paulacamargo25 Date: Thu, 15 Feb 2024 17:17:23 -0800 Subject: [PATCH] Open browser after launching (#214) * Add autoStartBrowser and serverReady * add tests * fix lint * fix tests * remove only in test * send telemetry * fix lint --- package.json | 5 +++ .../debugger/configuration/resolvers/base.ts | 1 + .../configuration/resolvers/launch.ts | 7 +++++ src/extension/telemetry/index.ts | 6 ++++ .../resolvers/launch.unit.test.ts | 31 +++++++++++++++++++ 5 files changed, 50 insertions(+) diff --git a/package.json b/package.json index 2f368f43..4239b168 100644 --- a/package.json +++ b/package.json @@ -327,6 +327,11 @@ "description": "Path (fully qualified) to the Python debug adapter executable.", "type": "string" }, + "autoStartBrowser": { + "default": false, + "description": "Open external browser to launch the application", + "type": "boolean" + }, "django": { "default": false, "description": "Django debugging.", diff --git a/src/extension/debugger/configuration/resolvers/base.ts b/src/extension/debugger/configuration/resolvers/base.ts index 78cfda80..7775ae0d 100644 --- a/src/extension/debugger/configuration/resolvers/base.ts +++ b/src/extension/debugger/configuration/resolvers/base.ts @@ -245,6 +245,7 @@ export abstract class BaseConfigurationResolver stopOnEntry: !!debugConfiguration.stopOnEntry, showReturnValue: !!debugConfiguration.showReturnValue, subProcess: !!debugConfiguration.subProcess, + autoStartBrowser: !!debugConfiguration, watson: name.toLowerCase().indexOf('watson') >= 0, pyspark: name.toLowerCase().indexOf('pyspark') >= 0, gevent: name.toLowerCase().indexOf('gevent') >= 0, diff --git a/src/extension/debugger/configuration/resolvers/launch.ts b/src/extension/debugger/configuration/resolvers/launch.ts index 5230637b..474ba04c 100644 --- a/src/extension/debugger/configuration/resolvers/launch.ts +++ b/src/extension/debugger/configuration/resolvers/launch.ts @@ -140,6 +140,13 @@ export class LaunchConfigurationResolver extends BaseConfigurationResolver { expect((debugConfig as DebugConfiguration).debugOptions).contains(DebugOptions.Jinja); }); + const testsForautoStartBrowser = [ + { + autoStartBrowser: true, + module: 'flask', + }, + { + autoStartBrowser: true, + django: true, + }, + ]; + + test('Add serverReadyAction for Django and Flask', async () => { + const pythonPath = `PythonPath_${new Date().toString()}`; + const workspaceFolder = createMoqWorkspaceFolder(__dirname); + const pythonFile = 'xyz.py'; + setupIoc(pythonPath); + setupActiveEditor(pythonFile, PYTHON_LANGUAGE); + const expectedServerReadyAction = { + pattern: '.*(https?:\\/\\/\\S+:[0-9]+\\/?).*', + uriFormat: '%s', + action: 'openExternally', + }; + testsForautoStartBrowser.forEach(async (testParams) => { + const debugConfig = await resolveDebugConfiguration(workspaceFolder, { + ...launch, + ...testParams, + }); + expect(debugConfig).to.have.property('serverReadyAction', expectedServerReadyAction); + }); + }); + async function testSetting( requestType: 'launch' | 'attach', settings: Record,