diff --git a/package.json b/package.json index a798e4cd..762667f1 100644 --- a/package.json +++ b/package.json @@ -29,15 +29,10 @@ "type": "boolean", "markdownDescription": "If a skipped test is inconclusive or `Set-ItResult` had the `-Because` parameter specified, those are surfaced as test errors for easy viewing. Enable this setting if you prefer these to be displayed simply as skipped. **NOTE:** If you do this then you cannot see any BECAUSE messages without looking directly at the Pester output." }, - "pester.autoRunOnSave": { - "type": "boolean", - "default": true, - "markdownDescription": "Automatically runs Pester test files upon changes being detected on save. Uncheck this box to disable this behavior." - }, "pester.autoDebugOnSave": { "type": "boolean", "default": false, - "markdownDescription": "When enabled, will automatically start a debug run on a Pester file via the Powershell Integrated Console whenever it changes. This has no effect if `autoRunOnSave` is disabled." + "markdownDescription": "When enabled, continuous run tests will be debugged when changed in the PowerShell extension." }, "pester.suppressCodeLensNotice": { "type": "boolean", @@ -54,34 +49,45 @@ "pester.workingDirectory": { "type": "string", "markdownDescription": "Specifies the working directory of the dedicated Pester Instance. While $PSScriptRoot is recommended when using relative paths in Pester Tests, the runner will also default to the path of the current first workspace folder. Specify this if you want a different working directory." + }, + + // Deprecated Settings + "pester.autoRunOnSave": { + "type": "boolean", + "default": false, + "deprecationMessage": "DEPRECATED: This is now handled by the VSCode native continuous run interface in the test handler.", + "markdownDescription": "Automatically runs Pester test files upon changes being detected on save. Uncheck this box to disable this behavior." } } }, "commands": [ - { - "command": "pester.toggleAutoRunOnSave", - "title": "Pester: Toggle Auto Run on Save", - "category": "PowerShell" - }, { "command": "pester.stopPowerShell", "title": "Pester: Stop PowerShell background process", "category": "PowerShell" } + // DEPRECATED: This is now handled by the VSCode native continuous interface + // { + // "command": "pester.toggleAutoRunOnSave", + // "title": "Pester: Toggle Auto Run on Save", + // "enablement": "", + // "category": "PowerShell" + // }, ], "menus": { - "testing/item/context": [ - { - "command": "pester.toggleAutoRunOnSave", - "group": "pester" - } - ], - "testing/item/gutter": [ - { - "command": "pester.toggleAutoRunOnSave", - "group": "pester" - } - ] + // DEPRECATED: This is now handled by the VSCode native continuous interface + // "testing/item/context": [ + // { + // "command": "pester.toggleAutoRunOnSave", + // "group": "pester" + // } + // ], + // "testing/item/gutter": [ + // { + // "command": "pester.toggleAutoRunOnSave", + // "group": "pester" + // } + // ] } }, "keywords": [ diff --git a/src/extension.ts b/src/extension.ts index 7f7d4076..0f9c1954 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -1,11 +1,5 @@ import { type ExtensionContext, window, workspace, commands } from 'vscode' -import { - autoRunStatusBarItem, - autoRunStatusBarVisibleEvent, - toggleAutoRunOnSaveCommand, - updateAutoRunStatusBarOnConfigChange -} from './features/toggleAutoRunOnSaveCommand' import { PesterTestController } from './pesterTestController' import { getPowerShellExtension, @@ -68,10 +62,6 @@ export async function activate(context: ExtensionContext) { context.subscriptions.push( controller, - toggleAutoRunOnSaveCommand, stopPowerShellCommand, - autoRunStatusBarItem, - autoRunStatusBarVisibleEvent, - updateAutoRunStatusBarOnConfigChange ) } diff --git a/src/pesterTestController.ts b/src/pesterTestController.ts index 184d7583..a213a298 100644 --- a/src/pesterTestController.ts +++ b/src/pesterTestController.ts @@ -39,7 +39,6 @@ import { } from './powershellExtensionClient' import { clear, findTestItem, forAll, getTestItems, isTestItemOptions } from './testItemUtils' import debounce = require('debounce-promise') -import { initialize as statusBarInitialize } from './features/toggleAutoRunOnSaveCommand' /** A wrapper for the vscode TestController API specific to PowerShell Pester Test Suite. * This should only be instantiated once in the extension activate method. */ @@ -135,8 +134,6 @@ export class PesterTestController implements Disposable { this.testWatchers.push( ... (await this.watchWorkspaces()) ) - - statusBarInitialize() } log.debug(`VSCode requested resolve for: ${testItem?.id}`) @@ -300,16 +297,26 @@ export class PesterTestController implements Disposable { return result }, 300) - /** The test controller API calls this when tests are requested to run in the UI. It handles both runs and debugging */ + /** The test controller API calls this when tests are requested to run in the UI. It handles both runs and debugging. + * @param cancelToken The cancellation token passed by VSCode + */ private async testHandler(request: TestRunRequest, cancelToken?: CancellationToken) { if (request.continuous) { - cancelToken?.onCancellationRequested(() => { + /** This cancel will be called when the autorun button is disabled */ + const disableContinuousRunToken = cancelToken + + disableContinuousRunToken?.onCancellationRequested(() => { log.info(`Continuous run was disabled for ${request.include?.map(i => i.id)}`) }) log.info(`Continuous run enabled for ${request.include?.map(i => i.id)}`) + } else { + cancelToken?.onCancellationRequested(() => { + log.warn(`RunRequest cancel initiated for ${request.include?.map(i => i.id)}`) + }) } + if (request.profile === undefined) { throw new Error('No profile provided. This is (currently) a bug.') } @@ -760,20 +767,7 @@ export class PesterTestController implements Disposable { testWatcher.onDidChange(uri => { log.info(`File saved: ${uri.toString()}`) const savedFile = TestFile.getOrCreate(testController, uri) - this.resolveHandler(savedFile, undefined, true).then(() => { - if ( - workspace.getConfiguration('pester').get('autoRunOnSave') - ) { - const runProfile = workspace - .getConfiguration('pester') - .get('autoDebugOnSave') - ? this.debugProfile - : this.runProfile - this.testHandler( - new TestRunRequest([savedFile], undefined, runProfile) - ) - } - }) + this.resolveHandler(savedFile, undefined, true) }, this) const files = await workspace.findFiles(pattern) for (const file of files) {