Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/src/vs/base/test/node/powershell.test.ts
3296 views
1
/*---------------------------------------------------------------------------------------------
2
* Copyright (c) Microsoft Corporation. All rights reserved.
3
* Licensed under the MIT License. See License.txt in the project root for license information.
4
*--------------------------------------------------------------------------------------------*/
5
import assert from 'assert';
6
import * as fs from 'fs';
7
import * as platform from '../../common/platform.js';
8
import { enumeratePowerShellInstallations, getFirstAvailablePowerShellInstallation, IPowerShellExeDetails } from '../../node/powershell.js';
9
import { ensureNoDisposablesAreLeakedInTestSuite } from '../common/utils.js';
10
11
function checkPath(exePath: string) {
12
// Check to see if the path exists
13
let pathCheckResult = false;
14
try {
15
const stat = fs.statSync(exePath);
16
pathCheckResult = stat.isFile();
17
} catch {
18
// fs.exists throws on Windows with SymbolicLinks so we
19
// also use lstat to try and see if the file exists.
20
try {
21
pathCheckResult = fs.statSync(fs.readlinkSync(exePath)).isFile();
22
} catch {
23
24
}
25
}
26
27
assert.strictEqual(pathCheckResult, true);
28
}
29
30
if (platform.isWindows) {
31
suite('PowerShell finder', () => {
32
ensureNoDisposablesAreLeakedInTestSuite();
33
test('Can find first available PowerShell', async () => {
34
const pwshExe = await getFirstAvailablePowerShellInstallation();
35
const exePath = pwshExe?.exePath;
36
assert.notStrictEqual(exePath, null);
37
assert.notStrictEqual(pwshExe?.displayName, null);
38
39
checkPath(exePath!);
40
});
41
42
test('Can enumerate PowerShells', async () => {
43
const pwshs = new Array<IPowerShellExeDetails>();
44
for await (const p of enumeratePowerShellInstallations()) {
45
pwshs.push(p);
46
}
47
48
const powershellLog = 'Found these PowerShells:\n' + pwshs.map(p => `${p.displayName}: ${p.exePath}`).join('\n');
49
assert.strictEqual(pwshs.length >= 1, true, powershellLog);
50
51
for (const pwsh of pwshs) {
52
checkPath(pwsh.exePath);
53
}
54
55
// The last one should always be Windows PowerShell.
56
assert.strictEqual(pwshs[pwshs.length - 1].displayName, 'Windows PowerShell', powershellLog);
57
});
58
});
59
}
60
61