Skip to content

Commit a8cfa11

Browse files
Fix PowerShell module tests and upgrade dependencies (#1134)
* Fix PowerShell module tests and upgrade dependencies - Upgrade TypeScript from 4.0.2 to 5.9.3 for Node.js 20 compatibility - Upgrade @types/node to 20.0.0 and remove conflicting @types/glob - Add --skipLibCheck flag to TypeScript compilation for compatibility - Fix Test-CanUnravel function to handle null objects properly - Fix Invoke-Process function to properly return exit codes - Fix LocalizationFunctions to use InvariantCulture for number formatting - Update mocha version check in make.js - All 107 tests now pass successfully * Update Node.js version for PowerShell SDK and fix error handling - Add Node.js 20.x support for PowerShell SDK in CI pipeline - Fix error handlers in make.js to properly exit with code 1 on failures - Update TypeScript version validation to accept 5.x versions - Ensure CI pipeline failures are properly reported instead of silent success * updating the nuget url * CFS changes --------- Co-authored-by: Tarun Ramsinghani <[email protected]>
1 parent 1b6318c commit a8cfa11

File tree

8 files changed

+422
-40
lines changed

8 files changed

+422
-40
lines changed

azure-pipelines-steps-node.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,11 @@ steps:
4444
projects: 'powershell/CompiledHelpers/VstsTaskSdk.csproj'
4545
arguments: '--configuration Release'
4646

47+
- task: NodeTool@0
48+
displayName: use node $(nodeVersionForPowershell) for PowerShell SDK
49+
inputs:
50+
versionSpec: $(nodeVersionForPowershell)
51+
4752
- task: NpmAuthenticate@0
4853
inputs:
4954
workingFile: .npmrc

azure-pipelines.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ variables:
1010
- group: npm-tokens
1111
- name: nodeVersion
1212
value: '16.13.0'
13+
- name: nodeVersionForPowershell
14+
value: '20.x'
1315

1416
resources:
1517
repositories:

powershell/Tests/lib/TestHelpersModule/PrivateFunctions.ps1

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,11 @@ function Test-CanUnravel {
3636
[CmdletBinding()]
3737
param($Object)
3838

39-
return !([object]::ReferenceEquals($Object, $null)) -and
40-
$Object.GetType().IsClass -and
39+
if ([object]::ReferenceEquals($Object, $null)) {
40+
return $false
41+
}
42+
43+
return $Object.GetType().IsClass -and
4144
!([object]::ReferenceEquals($Object, ($Object | ForEach-Object { $_ })))
4245
}
4346

powershell/VstsTaskSdk/LocalizationFunctions.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ function Get-LocString {
5050
if (!$ArgumentList.Count) { return $format }
5151

5252
try {
53-
[string]::Format($format, $ArgumentList)
53+
[string]::Format([System.Globalization.CultureInfo]::InvariantCulture, $format, $ArgumentList)
5454
} catch {
5555
Write-Warning (Get-LocString -Key 'PSLIB_StringFormatFailed')
5656
$OFS = " "

powershell/VstsTaskSdk/ToolFunctions.ps1

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,14 +208,21 @@ function Invoke-Process {
208208

209209
$procExitCode = $proc.ExitCode
210210
Write-Verbose "Exit code: $procExitCode"
211+
212+
# Handle case where exit code might be null
213+
if ($procExitCode -eq $null) {
214+
Write-Warning "Process exit code is null, defaulting to 0"
215+
$procExitCode = 0
216+
}
211217

212218
if ($RequireExitCodeZero -and $procExitCode -ne 0) {
213219
Write-Error (Get-LocString -Key PSLIB_Process0ExitedWithCode1 -ArgumentList ([System.IO.Path]::GetFileName($FileName)), $procExitCode)
214220
}
215221

216222
$global:LASTEXITCODE = $procExitCode
217223

218-
return $procExitCode
224+
# Ensure we return an integer
225+
return [int]$procExitCode
219226
}
220227
finally {
221228
Trace-LeavingInvocation $MyInvocation

powershell/make.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ target.build = async function () {
2525
util.cp('-r', path.join('VstsTaskSdk', '*'), path.join(buildPath, 'VstsTaskSdk'));
2626

2727
// download externals
28-
var minimatchPackage = await util.downloadArchiveAsync('https://www.nuget.org/api/v2/package/minimatch/1.1.0');
28+
var minimatchPackage = await util.downloadArchiveAsync('https://pkgs.dev.azure.com/mseng/PipelineTools/_packaging/PipelineTools_PublicNugetFeed/nuget/v3/flat2/minimatch/1.1.0/minimatch.1.1.0.nupkg') //('https://www.nuget.org/api/v3/package/minimatch/1.1.0');
2929
util.cp(path.join(minimatchPackage, 'lib', 'portable-net40%2Bsl50%2Bwin%2Bwp80', 'Minimatch.dll'), path.join(buildPath, 'VstsTaskSdk'));
3030

3131
var compiledHelperPackage = await util.downloadArchiveAsync('https://vstsagenttools.blob.core.windows.net/tools/VstsTaskSdkCompiledHelpers/3/VstsTaskSdk.zip');
@@ -61,8 +61,12 @@ target.build = async function () {
6161
}
6262

6363
target.test = async function () {
64-
util.ensureTool('tsc', '--version', 'Version 4.0.2');
65-
util.ensureTool('mocha', '--version', '5.2.0');
64+
util.ensureTool('tsc', '--version', function(version) {
65+
if (!version.startsWith('Version 5.')) {
66+
throw new Error('expected TypeScript 5.x, got: ' + version);
67+
}
68+
});
69+
util.ensureTool('mocha', '--version', '10.8.2');
6670
await target.build();
6771

6872
util.mkdir('-p', testPath);
@@ -94,9 +98,11 @@ target.loc = function () {
9498
process.on('uncaughtException', err => {
9599
console.error(`Uncaught exception: ${err.message}`);
96100
console.debug(err.stack);
101+
process.exit(1);
97102
});
98103

99104
process.on('unhandledRejection', err => {
100105
console.error(`Unhandled rejection: ${err.message}`);
101106
console.debug(err.stack);
107+
process.exit(1);
102108
});

0 commit comments

Comments
 (0)