From f54c9f8bc48a4108c5da2527f92340a2dca66e8e Mon Sep 17 00:00:00 2001 From: Karthik Nadig Date: Mon, 9 Dec 2024 07:27:03 -0800 Subject: [PATCH] Remove sourceMaps --- .eslintignore | 4 - gulpfile.js | 8 +- package.json | 17 --- package.nls.json | 2 - .../diagnostics/applicationDiagnostics.ts | 6 +- .../diagnostics/surceMapSupportService.ts | 46 ------- src/client/application/diagnostics/types.ts | 5 - src/client/application/serviceRegistry.ts | 3 - src/client/common/application/commands.ts | 1 - src/client/common/constants.ts | 1 - src/client/common/utils/localize.ts | 9 -- src/client/extension.ts | 4 - src/client/sourceMapSupport.ts | 85 ------------ .../applicationDiagnostics.unit.test.ts | 20 +-- .../sourceMapSupportService.unit.test.ts | 82 ----------- src/test/sourceMapSupport.test.ts | 95 ------------- src/test/sourceMapSupport.unit.test.ts | 129 ------------------ 17 files changed, 4 insertions(+), 513 deletions(-) delete mode 100644 src/client/application/diagnostics/surceMapSupportService.ts delete mode 100644 src/client/sourceMapSupport.ts delete mode 100644 src/test/application/diagnostics/sourceMapSupportService.unit.test.ts delete mode 100644 src/test/sourceMapSupport.test.ts delete mode 100644 src/test/sourceMapSupport.unit.test.ts diff --git a/.eslintignore b/.eslintignore index 9399ff461dcd..50f4df4044d1 100644 --- a/.eslintignore +++ b/.eslintignore @@ -17,8 +17,6 @@ src/test/proc.ts src/test/smokeTest.ts src/test/standardTest.ts src/test/startupTelemetry.unit.test.ts -src/test/sourceMapSupport.test.ts -src/test/sourceMapSupport.unit.test.ts src/test/testBootstrap.ts src/test/testLogger.ts src/test/testRunner.ts @@ -129,7 +127,6 @@ src/test/application/diagnostics/checks/invalidPythonPathInDebugger.unit.test.ts src/test/application/diagnostics/checks/envPathVariable.unit.test.ts src/test/application/diagnostics/applicationDiagnostics.unit.test.ts src/test/application/diagnostics/promptHandler.unit.test.ts -src/test/application/diagnostics/sourceMapSupportService.unit.test.ts src/test/application/diagnostics/commands/ignore.unit.test.ts src/test/performance/load.perf.test.ts @@ -145,7 +142,6 @@ src/client/interpreter/virtualEnvs/condaInheritEnvPrompt.ts src/client/interpreter/display/index.ts src/client/extension.ts -src/client/sourceMapSupport.ts src/client/startupTelemetry.ts src/client/terminals/codeExecution/terminalCodeExecution.ts diff --git a/gulpfile.js b/gulpfile.js index da46943f7335..f921ff7fd1b1 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -222,12 +222,6 @@ function getAllowedWarningsForWebPack(buildConfig) { throw new Error('Unknown WebPack Configuration'); } } -gulp.task('renameSourceMaps', async () => { - // By default source maps will be disabled in the extension. - // Users will need to use the command `python.enableSourceMapSupport` to enable source maps. - const extensionSourceMap = path.join(__dirname, 'out', 'client', 'extension.js.map'); - await fsExtra.rename(extensionSourceMap, `${extensionSourceMap}.disabled`); -}); gulp.task('verifyBundle', async () => { const matches = await glob.sync(path.join(__dirname, '*.vsix')); @@ -238,7 +232,7 @@ gulp.task('verifyBundle', async () => { } }); -gulp.task('prePublishBundle', gulp.series('webpack', 'renameSourceMaps')); +gulp.task('prePublishBundle', gulp.series('webpack')); gulp.task('checkDependencies', gulp.series('checkNativeDependencies')); gulp.task('prePublishNonBundle', gulp.series('compile')); diff --git a/package.json b/package.json index 2a3e5dc166ef..cb0d3fdea22d 100644 --- a/package.json +++ b/package.json @@ -300,11 +300,6 @@ "command": "python.createEnvironment-button", "title": "%python.command.python.createEnvironment.title%" }, - { - "category": "Python", - "command": "python.enableSourceMapSupport", - "title": "%python.command.python.enableSourceMapSupport.title%" - }, { "category": "Python", "command": "python.execInTerminal", @@ -443,12 +438,6 @@ "scope": "machine-overridable", "type": "string" }, - "python.diagnostics.sourceMapsEnabled": { - "default": false, - "description": "%python.diagnostics.sourceMapsEnabled.description%", - "scope": "application", - "type": "boolean" - }, "python.envFile": { "default": "${workspaceFolder}/.env", "description": "%python.envFile.description%", @@ -1297,12 +1286,6 @@ "title": "%python.command.python.createTerminal.title%", "when": "!virtualWorkspace && shellExecutionSupported" }, - { - "category": "Python", - "command": "python.enableSourceMapSupport", - "title": "%python.command.python.enableSourceMapSupport.title%", - "when": "!virtualWorkspace && shellExecutionSupported" - }, { "category": "Python", "command": "python.execInTerminal", diff --git a/package.nls.json b/package.nls.json index b60863ef1e49..723acae71c21 100644 --- a/package.nls.json +++ b/package.nls.json @@ -18,7 +18,6 @@ "python.command.python.execInREPL.title": "Run Selection/Line in Python REPL", "python.command.python.execSelectionInDjangoShell.title": "Run Selection/Line in Django Shell", "python.command.python.reportIssue.title": "Report Issue...", - "python.command.python.enableSourceMapSupport.title": "Enable Source Map Support For Extension Debugging", "python.command.python.clearCacheAndReload.title": "Clear Cache and Reload Window", "python.command.python.analysis.restartLanguageServer.title": "Restart Language Server", "python.command.python.launchTensorBoard.title": "Launch TensorBoard", @@ -33,7 +32,6 @@ "python.condaPath.description": "Path to the conda executable to use for activation (version 4.4+).", "python.debugger.deprecatedMessage": "This configuration will be deprecated soon. Please replace `python` with `debugpy` to use the new Python Debugger extension.", "python.defaultInterpreterPath.description": "Path to default Python to use when extension loads up for the first time, no longer used once an interpreter is selected for the workspace. See [here](https://aka.ms/AAfekmf) to understand when this is used", - "python.diagnostics.sourceMapsEnabled.description": "Enable source map support for meaningful stack traces in error logs.", "python.envFile.description": "Absolute path to a file containing environment variable definitions.", "python.experiments.enabled.description": "Enables A/B tests experiments in the Python extension. If enabled, you may get included in proposed enhancements and/or features.", "python.experiments.optInto.description": "List of experiments to opt into. If empty, user is assigned the default experiment groups. See [here](https://github.com/microsoft/vscode-python/wiki/AB-Experiments) for more details.", diff --git a/src/client/application/diagnostics/applicationDiagnostics.ts b/src/client/application/diagnostics/applicationDiagnostics.ts index 493c6cfece53..90d2ced8d0ae 100644 --- a/src/client/application/diagnostics/applicationDiagnostics.ts +++ b/src/client/application/diagnostics/applicationDiagnostics.ts @@ -9,7 +9,7 @@ import { Resource } from '../../common/types'; import { IServiceContainer } from '../../ioc/types'; import { traceLog, traceVerbose } from '../../logging'; import { IApplicationDiagnostics } from '../types'; -import { IDiagnostic, IDiagnosticsService, ISourceMapSupportService } from './types'; +import { IDiagnostic, IDiagnosticsService } from './types'; function log(diagnostics: IDiagnostic[]): void { diagnostics.forEach((item) => { @@ -43,9 +43,7 @@ async function runDiagnostics(diagnosticServices: IDiagnosticsService[], resourc export class ApplicationDiagnostics implements IApplicationDiagnostics { constructor(@inject(IServiceContainer) private readonly serviceContainer: IServiceContainer) {} - public register() { - this.serviceContainer.get(ISourceMapSupportService).register(); - } + public register() {} public async performPreStartupHealthCheck(resource: Resource): Promise { // When testing, do not perform health checks, as modal dialogs can be displayed. diff --git a/src/client/application/diagnostics/surceMapSupportService.ts b/src/client/application/diagnostics/surceMapSupportService.ts deleted file mode 100644 index 8ff491e4cb06..000000000000 --- a/src/client/application/diagnostics/surceMapSupportService.ts +++ /dev/null @@ -1,46 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -'use strict'; - -import { inject, injectable } from 'inversify'; -import { ConfigurationTarget } from 'vscode'; -import { IApplicationShell, ICommandManager } from '../../common/application/types'; -import { Commands } from '../../common/constants'; -import { IConfigurationService, IDisposableRegistry } from '../../common/types'; -import { Diagnostics } from '../../common/utils/localize'; -import { ISourceMapSupportService } from './types'; - -@injectable() -export class SourceMapSupportService implements ISourceMapSupportService { - constructor( - @inject(ICommandManager) private readonly commandManager: ICommandManager, - @inject(IDisposableRegistry) private readonly disposables: IDisposableRegistry, - @inject(IConfigurationService) private readonly configurationService: IConfigurationService, - @inject(IApplicationShell) private readonly shell: IApplicationShell, - ) {} - public register(): void { - this.disposables.push( - this.commandManager.registerCommand(Commands.Enable_SourceMap_Support, this.onEnable, this), - ); - } - public async enable(): Promise { - await this.configurationService.updateSetting( - 'diagnostics.sourceMapsEnabled', - true, - undefined, - ConfigurationTarget.Global, - ); - await this.commandManager.executeCommand('workbench.action.reloadWindow'); - } - protected async onEnable(): Promise { - const enableSourceMapsAndReloadVSC = Diagnostics.enableSourceMapsAndReloadVSC; - const selection = await this.shell.showWarningMessage( - Diagnostics.warnBeforeEnablingSourceMaps, - enableSourceMapsAndReloadVSC, - ); - if (selection === enableSourceMapsAndReloadVSC) { - await this.enable(); - } - } -} diff --git a/src/client/application/diagnostics/types.ts b/src/client/application/diagnostics/types.ts index ced9930c81ab..1dc9a3c689df 100644 --- a/src/client/application/diagnostics/types.ts +++ b/src/client/application/diagnostics/types.ts @@ -64,8 +64,3 @@ export const IInvalidPythonPathInDebuggerService = Symbol('IInvalidPythonPathInD export interface IInvalidPythonPathInDebuggerService extends IDiagnosticsService { validatePythonPath(pythonPath?: string, pythonPathSource?: PythonPathSource, resource?: Uri): Promise; } -export const ISourceMapSupportService = Symbol('ISourceMapSupportService'); -export interface ISourceMapSupportService { - register(): void; - enable(): Promise; -} diff --git a/src/client/application/serviceRegistry.ts b/src/client/application/serviceRegistry.ts index 38773bd20198..ff5376d70b24 100644 --- a/src/client/application/serviceRegistry.ts +++ b/src/client/application/serviceRegistry.ts @@ -5,10 +5,7 @@ import { IServiceManager } from '../ioc/types'; import { registerTypes as diagnosticsRegisterTypes } from './diagnostics/serviceRegistry'; -import { SourceMapSupportService } from './diagnostics/surceMapSupportService'; -import { ISourceMapSupportService } from './diagnostics/types'; export function registerTypes(serviceManager: IServiceManager) { - serviceManager.addSingleton(ISourceMapSupportService, SourceMapSupportService); diagnosticsRegisterTypes(serviceManager); } diff --git a/src/client/common/application/commands.ts b/src/client/common/application/commands.ts index 5fde061fb1e0..a145d3410033 100644 --- a/src/client/common/application/commands.ts +++ b/src/client/common/application/commands.ts @@ -34,7 +34,6 @@ interface ICommandNameWithoutArgumentTypeMapping { ['editor.action.rename']: []; [Commands.ViewOutput]: []; [Commands.Start_REPL]: []; - [Commands.Enable_SourceMap_Support]: []; [Commands.Exec_Selection_In_Terminal]: []; [Commands.Exec_Selection_In_Django_Shell]: []; [Commands.Create_Terminal]: []; diff --git a/src/client/common/constants.ts b/src/client/common/constants.ts index 68bd44fa769a..11729e460efa 100644 --- a/src/client/common/constants.ts +++ b/src/client/common/constants.ts @@ -42,7 +42,6 @@ export namespace Commands { export const Create_Environment_Check = 'python.createEnvironmentCheck'; export const Create_Terminal = 'python.createTerminal'; export const Debug_In_Terminal = 'python.debugInTerminal'; - export const Enable_SourceMap_Support = 'python.enableSourceMapSupport'; export const Exec_In_Terminal = 'python.execInTerminal'; export const Exec_In_Terminal_Icon = 'python.execInTerminal-icon'; export const Exec_In_Separate_Terminal = 'python.execInDedicatedTerminal'; diff --git a/src/client/common/utils/localize.ts b/src/client/common/utils/localize.ts index 3e11b1ca177b..f670fe493a1b 100644 --- a/src/client/common/utils/localize.ts +++ b/src/client/common/utils/localize.ts @@ -10,15 +10,6 @@ import { Commands } from '../constants'; // External callers of localize use these tables to retrieve localized values. export namespace Diagnostics { - export const warnSourceMaps = l10n.t( - 'Source map support is enabled in the Python Extension, this will adversely impact performance of the extension.', - ); - export const disableSourceMaps = l10n.t('Disable Source Map Support'); - - export const warnBeforeEnablingSourceMaps = l10n.t( - 'Enabling source map support in the Python Extension will adversely impact performance of the extension.', - ); - export const enableSourceMapsAndReloadVSC = l10n.t('Enable and reload Window.'); export const lsNotSupported = l10n.t( 'Your operating system does not meet the minimum requirements of the Python Language Server. Reverting to the alternative autocompletion provider, Jedi.', ); diff --git a/src/client/extension.ts b/src/client/extension.ts index b9f32187413b..521a8878ab63 100644 --- a/src/client/extension.ts +++ b/src/client/extension.ts @@ -6,10 +6,6 @@ if ((Reflect as any).metadata === undefined) { require('reflect-metadata'); } -// Initialize source maps (this must never be moved up nor further down). -import { initialize } from './sourceMapSupport'; -initialize(require('vscode')); - //=============================================== // We start tracking the extension's startup time at this point. The // locations at which we record various Intervals are marked below in diff --git a/src/client/sourceMapSupport.ts b/src/client/sourceMapSupport.ts deleted file mode 100644 index 0d1ba39eb941..000000000000 --- a/src/client/sourceMapSupport.ts +++ /dev/null @@ -1,85 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -'use strict'; - -import * as path from 'path'; -import { WorkspaceConfiguration } from 'vscode'; -import './common/extensions'; -import { FileSystem } from './common/platform/fileSystem'; -import { EXTENSION_ROOT_DIR } from './constants'; -import { traceError } from './logging'; - -type VSCode = typeof import('vscode'); - -const setting = 'sourceMapsEnabled'; - -export class SourceMapSupport { - private readonly config: WorkspaceConfiguration; - constructor(private readonly vscode: VSCode) { - this.config = this.vscode.workspace.getConfiguration('python.diagnostics', null); - } - public async initialize(): Promise { - if (!this.enabled) { - return; - } - await this.enableSourceMaps(true); - require('source-map-support').install(); - const localize = require('./common/utils/localize') as typeof import('./common/utils/localize'); - const disable = localize.Diagnostics.disableSourceMaps; - this.vscode.window.showWarningMessage(localize.Diagnostics.warnSourceMaps, disable).then((selection) => { - if (selection === disable) { - this.disable().ignoreErrors(); - } - }); - } - public get enabled(): boolean { - return this.config.get(setting, false); - } - public async disable(): Promise { - if (this.enabled) { - await this.config.update(setting, false, this.vscode.ConfigurationTarget.Global); - } - await this.enableSourceMaps(false); - } - protected async enableSourceMaps(enable: boolean) { - const extensionSourceFile = path.join(EXTENSION_ROOT_DIR, 'out', 'client', 'extension.js'); - const debuggerSourceFile = path.join( - EXTENSION_ROOT_DIR, - 'out', - 'client', - 'debugger', - 'debugAdapter', - 'main.js', - ); - await Promise.all([ - this.enableSourceMap(enable, extensionSourceFile), - this.enableSourceMap(enable, debuggerSourceFile), - ]); - } - protected async enableSourceMap(enable: boolean, sourceFile: string) { - const sourceMapFile = `${sourceFile}.map`; - const disabledSourceMapFile = `${sourceFile}.map.disabled`; - if (enable) { - await this.rename(disabledSourceMapFile, sourceMapFile); - } else { - await this.rename(sourceMapFile, disabledSourceMapFile); - } - } - protected async rename(sourceFile: string, targetFile: string) { - const fs = new FileSystem(); - if (await fs.fileExists(targetFile)) { - return; - } - await fs.move(sourceFile, targetFile); - } -} -export function initialize(vscode: VSCode = require('vscode')) { - if (!vscode.workspace.getConfiguration('python.diagnostics', null).get('sourceMapsEnabled', false)) { - new SourceMapSupport(vscode).disable().ignoreErrors(); - return; - } - new SourceMapSupport(vscode).initialize().catch((_ex) => { - traceError('Failed to initialize source map support in extension'); - }); -} diff --git a/src/test/application/diagnostics/applicationDiagnostics.unit.test.ts b/src/test/application/diagnostics/applicationDiagnostics.unit.test.ts index 48ee860dc6bb..3a2b9c2f62dd 100644 --- a/src/test/application/diagnostics/applicationDiagnostics.unit.test.ts +++ b/src/test/application/diagnostics/applicationDiagnostics.unit.test.ts @@ -10,12 +10,7 @@ import { DiagnosticSeverity } from 'vscode'; import { ApplicationDiagnostics } from '../../../client/application/diagnostics/applicationDiagnostics'; import { EnvironmentPathVariableDiagnosticsService } from '../../../client/application/diagnostics/checks/envPathVariable'; import { InvalidPythonInterpreterService } from '../../../client/application/diagnostics/checks/pythonInterpreter'; -import { - DiagnosticScope, - IDiagnostic, - IDiagnosticsService, - ISourceMapSupportService, -} from '../../../client/application/diagnostics/types'; +import { DiagnosticScope, IDiagnostic, IDiagnosticsService } from '../../../client/application/diagnostics/types'; import { IApplicationDiagnostics } from '../../../client/application/types'; import { IWorkspaceService } from '../../../client/common/application/types'; import { createDeferred, createDeferredFromPromise } from '../../../client/common/utils/async'; @@ -62,19 +57,6 @@ suite('Application Diagnostics - ApplicationDiagnostics', () => { process.env.VSC_PYTHON_CI_TEST = oldValueOfVSC_PYTHON_CI_TEST; }); - test('Register should register source maps', () => { - const sourceMapService = typemoq.Mock.ofType(); - sourceMapService.setup((s) => s.register()).verifiable(typemoq.Times.once()); - - serviceContainer - .setup((d) => d.get(typemoq.It.isValue(ISourceMapSupportService), typemoq.It.isAny())) - .returns(() => sourceMapService.object); - - appDiagnostics.register(); - - sourceMapService.verifyAll(); - }); - test('Performing Pre Startup Health Check must diagnose all validation checks', async () => { envHealthCheck .setup((e) => e.diagnose(typemoq.It.isAny())) diff --git a/src/test/application/diagnostics/sourceMapSupportService.unit.test.ts b/src/test/application/diagnostics/sourceMapSupportService.unit.test.ts deleted file mode 100644 index 3ff429742eb8..000000000000 --- a/src/test/application/diagnostics/sourceMapSupportService.unit.test.ts +++ /dev/null @@ -1,82 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -'use strict'; - -import { anyFunction, anything, instance, mock, verify, when } from 'ts-mockito'; -import { ConfigurationTarget } from 'vscode'; -import { SourceMapSupportService } from '../../../client/application/diagnostics/surceMapSupportService'; -import { ApplicationShell } from '../../../client/common/application/applicationShell'; -import { CommandManager } from '../../../client/common/application/commandManager'; -import { ConfigurationService } from '../../../client/common/configuration/service'; -import { Commands } from '../../../client/common/constants'; -import { Diagnostics } from '../../../client/common/utils/localize'; - -suite('Diagnostisc - Source Maps', () => { - test('Command is registered', async () => { - const commandManager = mock(CommandManager); - const service = new SourceMapSupportService(instance(commandManager), [], undefined as any, undefined as any); - service.register(); - verify(commandManager.registerCommand(Commands.Enable_SourceMap_Support, anyFunction(), service)).once(); - }); - test('Setting is turned on and vsc reloaded', async () => { - const commandManager = mock(CommandManager); - const configService = mock(ConfigurationService); - const service = new SourceMapSupportService( - instance(commandManager), - [], - instance(configService), - undefined as any, - ); - when( - configService.updateSetting('diagnostics.sourceMapsEnabled', true, undefined, ConfigurationTarget.Global), - ).thenResolve(); - when(commandManager.executeCommand('workbench.action.reloadWindow')).thenResolve(); - - await service.enable(); - - verify( - configService.updateSetting('diagnostics.sourceMapsEnabled', true, undefined, ConfigurationTarget.Global), - ).once(); - verify(commandManager.executeCommand('workbench.action.reloadWindow')).once(); - }); - test('Display prompt and do not enable', async () => { - const shell = mock(ApplicationShell); - const service = new (class extends SourceMapSupportService { - public async enable() { - throw new Error('Should not be invokved'); - } - public async onEnable() { - await super.onEnable(); - } - })(undefined as any, [], undefined as any, instance(shell)); - when(shell.showWarningMessage(anything(), anything())).thenResolve(); - - await service.onEnable(); - }); - test('Display prompt and must enable', async () => { - const commandManager = mock(CommandManager); - const configService = mock(ConfigurationService); - const shell = mock(ApplicationShell); - const service = new (class extends SourceMapSupportService { - public async onEnable() { - await super.onEnable(); - } - })(instance(commandManager), [], instance(configService), instance(shell)); - - when( - configService.updateSetting('diagnostics.sourceMapsEnabled', true, undefined, ConfigurationTarget.Global), - ).thenResolve(); - when(shell.showWarningMessage(anything(), anything())).thenResolve( - Diagnostics.enableSourceMapsAndReloadVSC as any, - ); - when(commandManager.executeCommand('workbench.action.reloadWindow')).thenResolve(); - - await service.onEnable(); - - verify( - configService.updateSetting('diagnostics.sourceMapsEnabled', true, undefined, ConfigurationTarget.Global), - ).once(); - verify(commandManager.executeCommand('workbench.action.reloadWindow')).once(); - }); -}); diff --git a/src/test/sourceMapSupport.test.ts b/src/test/sourceMapSupport.test.ts deleted file mode 100644 index a591e1236619..000000000000 --- a/src/test/sourceMapSupport.test.ts +++ /dev/null @@ -1,95 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -'use strict'; - -import { expect } from 'chai'; -import * as fs from 'fs'; -import { ConfigurationTarget, Disposable } from 'vscode'; -import { FileSystem } from '../client/common/platform/fileSystem'; -import { Diagnostics } from '../client/common/utils/localize'; -import { SourceMapSupport } from '../client/sourceMapSupport'; -import { noop } from './core'; - -suite('Source Map Support', () => { - function createVSCStub(isEnabled: boolean = false, selectDisableButton: boolean = false) { - const stubInfo = { - configValueRetrieved: false, - configValueUpdated: false, - messageDisplayed: false, - }; - const vscode = { - workspace: { - getConfiguration: (setting: string, _defaultValue: any) => { - if (setting !== 'python.diagnostics') { - return; - } - return { - get: (prop: string) => { - stubInfo.configValueRetrieved = prop === 'sourceMapsEnabled'; - return isEnabled; - }, - update: (prop: string, value: boolean, scope: ConfigurationTarget) => { - if ( - prop === 'sourceMapsEnabled' && - value === false && - scope === ConfigurationTarget.Global - ) { - stubInfo.configValueUpdated = true; - } - }, - }; - }, - }, - window: { - showWarningMessage: () => { - stubInfo.messageDisplayed = true; - return Promise.resolve(selectDisableButton ? Diagnostics.disableSourceMaps : undefined); - }, - }, - ConfigurationTarget: ConfigurationTarget, - }; - return { stubInfo, vscode }; - } - - const disposables: Disposable[] = []; - teardown(() => { - disposables.forEach((disposable) => { - try { - disposable.dispose(); - } catch { - noop(); - } - }); - }); - test('When disabling source maps, the map file is renamed and vice versa', async () => { - const fileSystem = new FileSystem(); - const jsFile = await fileSystem.createTemporaryFile('.js'); - disposables.push(jsFile); - const mapFile = `${jsFile.filePath}.map`; - disposables.push({ - dispose: () => fs.unlinkSync(mapFile), - }); - await fileSystem.writeFile(mapFile, 'ABC'); - expect(await fileSystem.fileExists(mapFile)).to.be.true; - - const stub = createVSCStub(true, true); - const instance = new (class extends SourceMapSupport { - public async enableSourceMap(enable: boolean, sourceFile: string) { - return super.enableSourceMap(enable, sourceFile); - } - })(stub.vscode as any); - - await instance.enableSourceMap(false, jsFile.filePath); - - expect(await fileSystem.fileExists(jsFile.filePath)).to.be.equal(true, 'Source file does not exist'); - expect(await fileSystem.fileExists(mapFile)).to.be.equal(false, 'Source map file not renamed'); - expect(await fileSystem.fileExists(`${mapFile}.disabled`)).to.be.equal(true, 'Expected renamed file not found'); - - await instance.enableSourceMap(true, jsFile.filePath); - - expect(await fileSystem.fileExists(jsFile.filePath)).to.be.equal(true, 'Source file does not exist'); - expect(await fileSystem.fileExists(mapFile)).to.be.equal(true, 'Source map file not found'); - expect(await fileSystem.fileExists(`${mapFile}.disabled`)).to.be.equal(false, 'Source map file not renamed'); - }); -}); diff --git a/src/test/sourceMapSupport.unit.test.ts b/src/test/sourceMapSupport.unit.test.ts deleted file mode 100644 index 3ce5249eca01..000000000000 --- a/src/test/sourceMapSupport.unit.test.ts +++ /dev/null @@ -1,129 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -'use strict'; - -import { expect } from 'chai'; -import * as path from 'path'; -import rewiremock from 'rewiremock'; -import * as sinon from 'sinon'; -import { ConfigurationTarget, Disposable } from 'vscode'; -import { Diagnostics } from '../client/common/utils/localize'; -import { EXTENSION_ROOT_DIR } from '../client/constants'; -import { initialize, SourceMapSupport } from '../client/sourceMapSupport'; -import { noop, sleep } from './core'; - -suite('Source Map Support', () => { - function createVSCStub(isEnabled: boolean = false, selectDisableButton: boolean = false) { - const stubInfo = { - configValueRetrieved: false, - configValueUpdated: false, - messageDisplayed: false, - }; - const vscode = { - workspace: { - getConfiguration: (setting: string, _defaultValue: any) => { - if (setting !== 'python.diagnostics') { - return; - } - return { - get: (prop: string) => { - stubInfo.configValueRetrieved = prop === 'sourceMapsEnabled'; - return isEnabled; - }, - update: (prop: string, value: boolean, scope: ConfigurationTarget) => { - if ( - prop === 'sourceMapsEnabled' && - value === false && - scope === ConfigurationTarget.Global - ) { - stubInfo.configValueUpdated = true; - } - }, - }; - }, - }, - window: { - showWarningMessage: () => { - stubInfo.messageDisplayed = true; - return Promise.resolve(selectDisableButton ? Diagnostics.disableSourceMaps : undefined); - }, - }, - ConfigurationTarget: ConfigurationTarget, - }; - return { stubInfo, vscode }; - } - - const disposables: Disposable[] = []; - teardown(() => { - rewiremock.disable(); - disposables.forEach((disposable) => { - try { - disposable.dispose(); - } catch { - noop(); - } - }); - }); - test('Test message is not displayed when source maps are not enabled', async () => { - const stub = createVSCStub(false); - - initialize(stub.vscode as any); - await sleep(100); - expect(stub.stubInfo.configValueRetrieved).to.be.equal(true, 'Config Value not retrieved'); - expect(stub.stubInfo.messageDisplayed).to.be.equal(false, 'Message displayed'); - }); - test('Test message is displayed when source maps are not enabled', async () => { - const stub = createVSCStub(true); - const instance = new (class extends SourceMapSupport { - protected async enableSourceMaps(_enable: boolean) { - noop(); - } - })(stub.vscode as any); - rewiremock.enable(); - const installStub = sinon.stub(); - rewiremock('source-map-support').with({ install: installStub }); - await instance.initialize(); - - expect(installStub.callCount).to.be.equal(1); - expect(stub.stubInfo.configValueRetrieved).to.be.equal(true, 'Config Value not retrieved'); - expect(stub.stubInfo.messageDisplayed).to.be.equal(true, 'Message displayed'); - expect(stub.stubInfo.configValueUpdated).to.be.equal(false, 'Config Value updated'); - }); - test('Test message is not displayed when source maps are not enabled', async () => { - const stub = createVSCStub(true, true); - const instance = new (class extends SourceMapSupport { - protected async enableSourceMaps(_enable: boolean) { - noop(); - } - })(stub.vscode as any); - - await instance.initialize(); - expect(stub.stubInfo.configValueRetrieved).to.be.equal(true, 'Config Value not retrieved'); - expect(stub.stubInfo.messageDisplayed).to.be.equal(true, 'Message displayed'); - expect(stub.stubInfo.configValueUpdated).to.be.equal(true, 'Config Value not updated'); - }); - async function testRenamingFilesWhenEnablingDisablingSourceMaps(enableSourceMaps: boolean) { - const stub = createVSCStub(true, true); - const sourceFilesPassed: string[] = []; - const instance = new (class extends SourceMapSupport { - public async enableSourceMaps(enable: boolean) { - return super.enableSourceMaps(enable); - } - public async enableSourceMap(enable: boolean, sourceFile: string) { - expect(enable).to.equal(enableSourceMaps); - sourceFilesPassed.push(sourceFile); - return Promise.resolve(); - } - })(stub.vscode as any); - - await instance.enableSourceMaps(enableSourceMaps); - const extensionSourceMap = path.join(EXTENSION_ROOT_DIR, 'out', 'client', 'extension.js'); - const debuggerSourceMap = path.join(EXTENSION_ROOT_DIR, 'out', 'client', 'debugger', 'debugAdapter', 'main.js'); - expect(sourceFilesPassed).to.deep.equal([extensionSourceMap, debuggerSourceMap]); - } - test('Rename extension and debugger source maps when enabling source maps', () => - testRenamingFilesWhenEnablingDisablingSourceMaps(true)); - test('Rename extension and debugger source maps when disabling source maps', () => - testRenamingFilesWhenEnablingDisablingSourceMaps(false)); -});