Skip to content

Commit

Permalink
Deprecate out old autorun settings/operation
Browse files Browse the repository at this point in the history
  • Loading branch information
JustinGrote committed Jul 17, 2023
1 parent c463bec commit 8a02234
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 52 deletions.
52 changes: 29 additions & 23 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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": [
Expand Down
10 changes: 0 additions & 10 deletions src/extension.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -68,10 +62,6 @@ export async function activate(context: ExtensionContext) {

context.subscriptions.push(
controller,
toggleAutoRunOnSaveCommand,
stopPowerShellCommand,
autoRunStatusBarItem,
autoRunStatusBarVisibleEvent,
updateAutoRunStatusBarOnConfigChange
)
}
32 changes: 13 additions & 19 deletions src/pesterTestController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down Expand Up @@ -135,8 +134,6 @@ export class PesterTestController implements Disposable {
this.testWatchers.push(
... (await this.watchWorkspaces())
)

statusBarInitialize()
}

log.debug(`VSCode requested resolve for: ${testItem?.id}`)
Expand Down Expand Up @@ -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.')
}
Expand Down Expand Up @@ -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<boolean>('autoRunOnSave')
) {
const runProfile = workspace
.getConfiguration('pester')
.get<boolean>('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) {
Expand Down

0 comments on commit 8a02234

Please sign in to comment.