Path: blob/main/src/vs/base/test/node/powershell.test.ts
3296 views
/*---------------------------------------------------------------------------------------------1* Copyright (c) Microsoft Corporation. All rights reserved.2* Licensed under the MIT License. See License.txt in the project root for license information.3*--------------------------------------------------------------------------------------------*/4import assert from 'assert';5import * as fs from 'fs';6import * as platform from '../../common/platform.js';7import { enumeratePowerShellInstallations, getFirstAvailablePowerShellInstallation, IPowerShellExeDetails } from '../../node/powershell.js';8import { ensureNoDisposablesAreLeakedInTestSuite } from '../common/utils.js';910function checkPath(exePath: string) {11// Check to see if the path exists12let pathCheckResult = false;13try {14const stat = fs.statSync(exePath);15pathCheckResult = stat.isFile();16} catch {17// fs.exists throws on Windows with SymbolicLinks so we18// also use lstat to try and see if the file exists.19try {20pathCheckResult = fs.statSync(fs.readlinkSync(exePath)).isFile();21} catch {2223}24}2526assert.strictEqual(pathCheckResult, true);27}2829if (platform.isWindows) {30suite('PowerShell finder', () => {31ensureNoDisposablesAreLeakedInTestSuite();32test('Can find first available PowerShell', async () => {33const pwshExe = await getFirstAvailablePowerShellInstallation();34const exePath = pwshExe?.exePath;35assert.notStrictEqual(exePath, null);36assert.notStrictEqual(pwshExe?.displayName, null);3738checkPath(exePath!);39});4041test('Can enumerate PowerShells', async () => {42const pwshs = new Array<IPowerShellExeDetails>();43for await (const p of enumeratePowerShellInstallations()) {44pwshs.push(p);45}4647const powershellLog = 'Found these PowerShells:\n' + pwshs.map(p => `${p.displayName}: ${p.exePath}`).join('\n');48assert.strictEqual(pwshs.length >= 1, true, powershellLog);4950for (const pwsh of pwshs) {51checkPath(pwsh.exePath);52}5354// The last one should always be Windows PowerShell.55assert.strictEqual(pwshs[pwshs.length - 1].displayName, 'Windows PowerShell', powershellLog);56});57});58}596061