From 820d7d44b56033ce872a147ec61c0a320b261fa9 Mon Sep 17 00:00:00 2001 From: Andrew Schwartzmeyer Date: Thu, 24 Jun 2021 14:02:08 -0700 Subject: [PATCH 1/2] Fix `Package` task This now leaves the VSIX named as `vsce` creates it: `powershell-YYYY.MM.X.vsix`, instead of renaming it `PowerShell-Insiders.vsix`. I can't think of anything this would break, since the upload is not actually done with the deleted `Upload` task but with an ADO pipeline task. --- docs/development.md | 1 - vscode-powershell.build.ps1 | 22 +++++++--------------- 2 files changed, 7 insertions(+), 16 deletions(-) diff --git a/docs/development.md b/docs/development.md index 4dbdf37a94..914fe5d4bf 100644 --- a/docs/development.md +++ b/docs/development.md @@ -73,7 +73,6 @@ Update-Version -RepositoryName vscode-powershell # Push branches to GitHub and ADO # Open PRs for review # Download and test assets (assert correct PSES is included) -# Rename VSIX correctly New-DraftRelease -RepositoryName PowerShellEditorServices New-DraftRelease -RepositoryName vscode-powershell # Point releases to branches for automatic tagging diff --git a/vscode-powershell.build.ps1 b/vscode-powershell.build.ps1 index af26a0dc5d..143a54a299 100644 --- a/vscode-powershell.build.ps1 +++ b/vscode-powershell.build.ps1 @@ -36,14 +36,6 @@ task ResolveEditorServicesPath -Before CleanEditorServices, BuildEditorServices, } } -task UploadArtifacts { - if ($env:TF_BUILD) { - # SYSTEM_PHASENAME is the Job name. - Copy-Item -Path PowerShell-insiders.vsix ` - -Destination "$env:BUILD_ARTIFACTSTAGINGDIRECTORY/$($script:PackageJson.name)-$($script:PackageJson.version)-$env:SYSTEM_PHASENAME.vsix" - } -} - #endregion #region Restore tasks @@ -145,15 +137,15 @@ task Package UpdateReadme, { throw "Unable to find PowerShell EditorServices" } - Write-Host "`n### Packaging PowerShell-insiders.vsix`n" -ForegroundColor Green + $packageName = "$($script:PackageJson.name)-$($script:PackageJson.version).vsix" + Write-Host "`n### Packaging $packageName`n" -ForegroundColor Green exec { & node ./node_modules/vsce/out/vsce package --no-gitHubIssueLinking } - # Change the package to have a static name for automation purposes - Move-Item -Force .\$($script:PackageJson.name)-$($script:PackageJson.version).vsix .\PowerShell-insiders.vsix - if ($env:TF_BUILD) { - Copy-Item -Verbose -Recurse "./PowerShell-insiders.vsix" "$env:BUILD_ARTIFACTSTAGINGDIRECTORY/vscode-powershell/PowerShell-insiders.vsix" - Copy-Item -Verbose -Recurse "./scripts/Install-VSCode.ps1" "$env:BUILD_ARTIFACTSTAGINGDIRECTORY/vscode-powershell/Install-VSCode.ps1" + $artifactsPath = "$env:BUILD_ARTIFACTSTAGINGDIRECTORY/vscode-powershell/" + "./$packageName", "./scripts/Install-VSCode.ps1" | ForEach-Object { + Copy-Item -Verbose -Recurse $_ $artifactsPath + } } } @@ -162,4 +154,4 @@ task Package UpdateReadme, { # The set of tasks for a release task Release Clean, Build, Package # The default task is to run the entire CI build -task . CleanAll, BuildAll, Test, Package, UploadArtifacts +task . CleanAll, BuildAll, Test, Package From 00da48bb2fd1720bcdf9472fc4681d591e19ce20 Mon Sep 17 00:00:00 2001 From: Andrew Schwartzmeyer Date: Fri, 25 Jun 2021 12:56:34 -0700 Subject: [PATCH 2/2] Export `InvokePesterStub.ps1` to `PowerShellEditorServices` This fixes the path to the script which is now part of the `PowerShellEditorServices` repository. This was necessary in order to sign it, as it must be signed _before_ the VSIX is created. Moving it to the other repo was the best way to solve the "chicken-egg" problem that presented. --- .vsts-ci/templates/release-general.yml | 1 - InvokePesterStub.ps1 | 192 ------------------------- src/features/PesterTests.ts | 2 +- 3 files changed, 1 insertion(+), 194 deletions(-) delete mode 100755 InvokePesterStub.ps1 diff --git a/.vsts-ci/templates/release-general.yml b/.vsts-ci/templates/release-general.yml index 5ab6752f3f..25398a01f3 100644 --- a/.vsts-ci/templates/release-general.yml +++ b/.vsts-ci/templates/release-general.yml @@ -42,7 +42,6 @@ steps: # NOTE: Code AKA *.vsix files are not signed pattern: | Install-VSCode.ps1 - InvokePesterStub.ps1 - template: EsrpScan.yml@ComplianceRepo parameters: diff --git a/InvokePesterStub.ps1 b/InvokePesterStub.ps1 deleted file mode 100755 index 6fc1e799f9..0000000000 --- a/InvokePesterStub.ps1 +++ /dev/null @@ -1,192 +0,0 @@ -#!/usr/bin/env pwsh - -<# -.SYNOPSIS - Stub around Invoke-Pester command used by VSCode PowerShell extension. -.DESCRIPTION - The stub checks the version of Pester and if >= 4.6.0, invokes Pester - using the LineNumber parameter (if specified). Otherwise, it invokes - using the TestName parameter (if specified). If the All parameter - is specified, then all the tests are invoked in the specifed file. - Finally, if none of these three parameters are specified, all tests - are invoked and a warning is issued indicating what the user can do - to allow invocation of individual Describe blocks. -.EXAMPLE - PS C:\> .\InvokePesterStub.ps1 ~\project\test\foo.tests.ps1 -LineNumber 14 - Invokes a specific test by line number in the specified file. -.EXAMPLE - PS C:\> .\InvokePesterStub.ps1 ~\project\test\foo.tests.ps1 -TestName 'Foo Tests' - Invokes a specific test by test name in the specified file. -.EXAMPLE - PS C:\> .\InvokePesterStub.ps1 ~\project\test\foo.tests.ps1 -All - Invokes all tests in the specified file. -.INPUTS - None -.OUTPUTS - None -#> -param( - # Specifies the path to the test script. - [Parameter(Position=0, Mandatory)] - [ValidateNotNullOrEmpty()] - [string] - $ScriptPath, - - # Specifies the name of the test taken from the Describe block's name. - [Parameter()] - [string] - $TestName, - - # Specifies the starting line number of the DescribeBlock. This feature requires - # Pester 4.6.0 or higher. - [Parameter()] - [ValidatePattern('\d*')] - [string] - $LineNumber, - - # If specified, executes all the tests in the specified test script. - [Parameter()] - [switch] - $All, - - [Parameter()] - [switch] $MinimumVersion5, - - [Parameter(Mandatory)] - [string] $Output, - - [Parameter()] - [string] $OutputPath -) - -$pesterModule = Microsoft.PowerShell.Core\Get-Module Pester -# add one line, so the subsequent output is not shifted to the side -Write-Output '' - -if (!$pesterModule) { - Write-Output "Importing Pester module..." - if ($MinimumVersion5) { - $pesterModule = Microsoft.PowerShell.Core\Import-Module Pester -ErrorAction Ignore -PassThru -MinimumVersion 5.0.0 - } - - if (!$pesterModule) { - $pesterModule = Microsoft.PowerShell.Core\Import-Module Pester -ErrorAction Ignore -PassThru - } - - if (!$pesterModule) { - Write-Warning "Failed to import Pester. You must install Pester module to run or debug Pester tests." - Write-Warning "$(if ($MinimumVersion5) {"Recommended version to install is Pester 5.0.0 or newer. "})You can install Pester by executing: Install-Module Pester$(if ($MinimumVersion5) {" -MinimumVersion 5.0.0" }) -Scope CurrentUser -Force" - return - } -} - -$pester4Output = switch ($Output) { - "None" { "None" } - "Minimal" { "Fails" } - default { "All" } -} - -if ($MinimumVersion5 -and $pesterModule.Version -lt "5.0.0") { - Write-Warning "Pester 5.0.0 or newer is required because setting PowerShell > Pester: Use Legacy Code Lens is disabled, but Pester $($pesterModule.Version) is loaded. Some of the code lens features might not work as expected." -} - - -function Get-InvokePesterParams { - $invokePesterParams = @{ - Script = $ScriptPath - } - - if ($pesterModule.Version -ge '3.4.0') { - # -PesterOption was introduced before 3.4.0, and VSCodeMarker in 4.0.3-rc, - # but because no-one checks the integrity of this hashtable we can call - # all of the versions down to 3.4.0 like this - $invokePesterParams.Add("PesterOption", @{ IncludeVSCodeMarker = $true }) - } - - if ($pesterModule.Version -ge '3.4.5') { - # -Show was introduced in 3.4.5 - $invokePesterParams.Add("Show", $pester4Output) - } - - return $invokePesterParams -} - -if ($All) { - if ($pesterModule.Version -ge '5.0.0') { - $configuration = @{ - Run = @{ - Path = $ScriptPath - } - } - # only override this if user asks us to do it, to allow Pester to pick up - # $PesterPreference from caller context and merge it with the configuration - # we provide below, this way user can specify his output (and other) settings - # using the standard [PesterConfiguration] object, and we can avoid providing - # settings for everything - if ("FromPreference" -ne $Output) { - $configuration.Add('Output', @{ Verbosity = $Output }) - } - - if ($OutputPath) { - $configuration.Add('TestResult', @{ - Enabled = $true - OutputPath = $OutputPath - }) - } - Pester\Invoke-Pester -Configuration $configuration | Out-Null - } - else { - $invokePesterParams = Get-InvokePesterParams - Pester\Invoke-Pester @invokePesterParams - } -} -elseif (($LineNumber -match '\d+') -and ($pesterModule.Version -ge '4.6.0')) { - if ($pesterModule.Version -ge '5.0.0') { - $configuration = @{ - Run = @{ - Path = $ScriptPath - } - Filter = @{ - Line = "${ScriptPath}:$LineNumber" - } - } - if ("FromPreference" -ne $Output) { - $configuration.Add('Output', @{ Verbosity = $Output }) - } - - if ($OutputPath) { - $configuration.Add('TestResult', @{ - Enabled = $true - OutputPath = $OutputPath - }) - } - - Pester\Invoke-Pester -Configuration $configuration | Out-Null - } - else { - Pester\Invoke-Pester -Script $ScriptPath -PesterOption (New-PesterOption -ScriptBlockFilter @{ - IncludeVSCodeMarker=$true; Line=$LineNumber; Path=$ScriptPath}) -Show $pester4Output - } -} -elseif ($TestName) { - if ($pesterModule.Version -ge '5.0.0') { - throw "Running tests by test name is unsafe. This should not trigger for Pester 5." - } - else { - $invokePesterParams = Get-InvokePesterParams - Pester\Invoke-Pester @invokePesterParams - } -} -else { - if ($pesterModule.Version -ge '5.0.0') { - throw "Running tests by expandable string is unsafe. This should not trigger for Pester 5." - } - - # We get here when the TestName expression is of type ExpandableStringExpressionAst. - # PSES will not attempt to "evaluate" the expression so it returns null for the TestName. - Write-Warning "The Describe block's TestName cannot be evaluated. EXECUTING ALL TESTS instead." - Write-Warning "To avoid this, install Pester >= 4.6.0 or remove any expressions in the TestName." - - $invokePesterParams = Get-InvokePesterParams - Pester\Invoke-Pester @invokePesterParams -} diff --git a/src/features/PesterTests.ts b/src/features/PesterTests.ts index 6504b1cc0f..759f6189a4 100644 --- a/src/features/PesterTests.ts +++ b/src/features/PesterTests.ts @@ -18,7 +18,7 @@ export class PesterTestsFeature implements vscode.Disposable { private invokePesterStubScriptPath: string; constructor(private sessionManager: SessionManager) { - this.invokePesterStubScriptPath = path.resolve(__dirname, "../../../InvokePesterStub.ps1"); + this.invokePesterStubScriptPath = path.resolve(__dirname, "../../../modules/PowerShellEditorServices/InvokePesterStub.ps1"); // File context-menu command - Run Pester Tests this.command = vscode.commands.registerCommand(