@@ -8,45 +8,33 @@ import * as os from "os";
8
8
import * as path from "path" ;
9
9
import * as sinon from "sinon" ;
10
10
import * as platform from "../../src/platform" ;
11
+ import * as utils from "../../src/utils" ;
11
12
import * as fs from "fs" ; // NOTE: Necessary for mock-fs.
12
13
import * as vscode from "vscode" ;
13
- import * as utils from "../../src/utils" ;
14
14
15
15
// eslint-disable-next-line @typescript-eslint/require-await
16
- async function fakeCheckIfFileExists (
17
- targetPath : string | vscode . Uri ,
18
- ) : Promise < boolean > {
19
- try {
20
- const stat = fs . lstatSync (
21
- targetPath instanceof vscode . Uri ? targetPath . fsPath : targetPath ,
22
- ) ;
23
- return stat . isFile ( ) ;
24
- } catch {
25
- return false ;
26
- }
16
+ async function fakeCheckIfFileExists ( targetPath : string | vscode . Uri ) : Promise < boolean > {
17
+ try {
18
+ const stat = fs . lstatSync ( targetPath instanceof vscode . Uri ? targetPath . fsPath : targetPath ) ;
19
+ return stat . isFile ( ) ;
20
+ } catch {
21
+ return false ;
22
+ }
27
23
}
28
24
29
25
// eslint-disable-next-line @typescript-eslint/require-await
30
- async function fakeCheckIfDirectoryExists (
31
- targetPath : string | vscode . Uri ,
32
- ) : Promise < boolean > {
33
- try {
34
- const stat = fs . lstatSync (
35
- targetPath instanceof vscode . Uri ? targetPath . fsPath : targetPath ,
36
- ) ;
37
- return stat . isDirectory ( ) ;
38
- } catch {
39
- return false ;
40
- }
26
+ async function fakeCheckIfDirectoryExists ( targetPath : string | vscode . Uri ) : Promise < boolean > {
27
+ try {
28
+ const stat = fs . lstatSync ( targetPath instanceof vscode . Uri ? targetPath . fsPath : targetPath ) ;
29
+ return stat . isDirectory ( ) ;
30
+ } catch {
31
+ return false ;
32
+ }
41
33
}
42
34
43
35
// eslint-disable-next-line @typescript-eslint/require-await
44
- async function fakeReadDirectory (
45
- targetPath : string | vscode . Uri ,
46
- ) : Promise < string [ ] > {
47
- return fs . readdirSync (
48
- targetPath instanceof vscode . Uri ? targetPath . fsPath : targetPath ,
49
- ) ;
36
+ async function fakeReadDirectory ( targetPath : string | vscode . Uri ) : Promise < string [ ] > {
37
+ return fs . readdirSync ( targetPath instanceof vscode . Uri ? targetPath . fsPath : targetPath ) ;
50
38
}
51
39
52
40
/**
@@ -845,22 +833,22 @@ function setupTestEnvironment(testPlatform: ITestPlatform): void {
845
833
}
846
834
847
835
describe ( "Platform module" , function ( ) {
848
- beforeEach ( function ( ) {
836
+ before ( function ( ) {
849
837
sinon . stub ( utils , "checkIfFileExists" ) . callsFake ( fakeCheckIfFileExists ) ;
850
- sinon
851
- . stub ( utils , "checkIfDirectoryExists" )
852
- . callsFake ( fakeCheckIfDirectoryExists ) ;
838
+ sinon . stub ( utils , "checkIfDirectoryExists" ) . callsFake ( fakeCheckIfDirectoryExists ) ;
853
839
sinon . stub ( utils , "readDirectory" ) . callsFake ( fakeReadDirectory ) ;
854
840
} ) ;
855
841
856
- afterEach ( function ( ) {
842
+ after ( function ( ) {
857
843
sinon . restore ( ) ;
844
+ } )
845
+
846
+ afterEach ( function ( ) {
858
847
mockFS . restore ( ) ;
859
848
} ) ;
860
849
861
850
it ( "Gets the correct platform details" , function ( ) {
862
- const platformDetails : platform . IPlatformDetails =
863
- platform . getPlatformDetails ( ) ;
851
+ const platformDetails : platform . IPlatformDetails = platform . getPlatformDetails ( ) ;
864
852
switch ( process . platform ) {
865
853
case "darwin" :
866
854
assert . strictEqual (
@@ -913,181 +901,124 @@ describe("Platform module", function () {
913
901
} ) ;
914
902
915
903
describe ( "Default PowerShell installation" , function ( ) {
916
- for ( const testPlatform of successTestCases ) {
917
- it ( `Finds it on ${ testPlatform . name } ` , async function ( ) {
918
- setupTestEnvironment ( testPlatform ) ;
904
+ for ( const testPlatform of successTestCases ) {
905
+ it ( `Finds it on ${ testPlatform . name } ` , async function ( ) {
906
+ setupTestEnvironment ( testPlatform ) ;
919
907
920
- const powerShellExeFinder = new platform . PowerShellExeFinder (
921
- testPlatform . platformDetails , { }
922
- ) ;
908
+ const powerShellExeFinder = new platform . PowerShellExeFinder ( testPlatform . platformDetails , { } ) ;
923
909
924
- const defaultPowerShell =
925
- await powerShellExeFinder . getFirstAvailablePowerShellInstallation ( ) ;
926
- const expectedPowerShell = testPlatform . expectedPowerShellSequence [ 0 ] ;
910
+ const defaultPowerShell = await powerShellExeFinder . getFirstAvailablePowerShellInstallation ( ) ;
911
+ const expectedPowerShell = testPlatform . expectedPowerShellSequence [ 0 ] ;
927
912
928
- assert . strictEqual (
929
- defaultPowerShell ! . exePath ,
930
- expectedPowerShell . exePath ,
931
- ) ;
932
- assert . strictEqual (
933
- defaultPowerShell ! . displayName ,
934
- expectedPowerShell . displayName ,
935
- ) ;
936
- assert . strictEqual (
937
- defaultPowerShell ! . supportsProperArguments ,
938
- expectedPowerShell . supportsProperArguments ,
939
- ) ;
940
- } ) ;
941
- }
913
+ assert . strictEqual ( defaultPowerShell ! . exePath , expectedPowerShell . exePath ) ;
914
+ assert . strictEqual ( defaultPowerShell ! . displayName , expectedPowerShell . displayName ) ;
915
+ assert . strictEqual ( defaultPowerShell ! . supportsProperArguments , expectedPowerShell . supportsProperArguments ) ;
916
+ } ) ;
917
+ }
942
918
943
- for ( const testPlatform of errorTestCases ) {
944
- it ( `Fails gracefully on ${ testPlatform . name } ` , async function ( ) {
945
- setupTestEnvironment ( testPlatform ) ;
919
+ for ( const testPlatform of errorTestCases ) {
920
+ it ( `Fails gracefully on ${ testPlatform . name } ` , async function ( ) {
921
+ setupTestEnvironment ( testPlatform ) ;
946
922
947
- const powerShellExeFinder = new platform . PowerShellExeFinder (
948
- testPlatform . platformDetails , { }
949
- ) ;
923
+ const powerShellExeFinder = new platform . PowerShellExeFinder ( testPlatform . platformDetails , { } ) ;
950
924
951
- const defaultPowerShell =
952
- await powerShellExeFinder . getFirstAvailablePowerShellInstallation ( ) ;
953
- assert . strictEqual ( defaultPowerShell , undefined ) ;
954
- } ) ;
955
- }
925
+ const defaultPowerShell = await powerShellExeFinder . getFirstAvailablePowerShellInstallation ( ) ;
926
+ assert . strictEqual ( defaultPowerShell , undefined ) ;
927
+ } ) ;
928
+ }
956
929
} ) ;
957
930
958
931
describe ( "Expected PowerShell installation list" , function ( ) {
959
- for ( const testPlatform of successTestCases ) {
960
- it ( `Finds them on ${ testPlatform . name } ` , async function ( ) {
961
- setupTestEnvironment ( testPlatform ) ;
932
+ for ( const testPlatform of successTestCases ) {
933
+ it ( `Finds them on ${ testPlatform . name } ` , async function ( ) {
934
+ setupTestEnvironment ( testPlatform ) ;
962
935
963
- const powerShellExeFinder = new platform . PowerShellExeFinder (
964
- testPlatform . platformDetails , { }
965
- ) ;
936
+ const powerShellExeFinder = new platform . PowerShellExeFinder ( testPlatform . platformDetails , { } ) ;
966
937
967
- const foundPowerShells =
968
- await powerShellExeFinder . getAllAvailablePowerShellInstallations ( ) ;
938
+ const foundPowerShells = await powerShellExeFinder . getAllAvailablePowerShellInstallations ( ) ;
969
939
970
- for (
971
- let i = 0 ;
972
- i < testPlatform . expectedPowerShellSequence . length ;
973
- i ++
974
- ) {
975
- const foundPowerShell = foundPowerShells [ i ] ;
976
- const expectedPowerShell =
977
- testPlatform . expectedPowerShellSequence [ i ] ;
940
+ for ( let i = 0 ; i < testPlatform . expectedPowerShellSequence . length ; i ++ ) {
941
+ const foundPowerShell = foundPowerShells [ i ] ;
942
+ const expectedPowerShell = testPlatform . expectedPowerShellSequence [ i ] ;
978
943
979
- assert . strictEqual (
980
- foundPowerShell . exePath ,
981
- expectedPowerShell . exePath ,
982
- ) ;
983
- assert . strictEqual (
984
- foundPowerShell . displayName ,
985
- expectedPowerShell . displayName ,
986
- ) ;
987
- assert . strictEqual (
988
- foundPowerShell . supportsProperArguments ,
989
- expectedPowerShell . supportsProperArguments ,
990
- ) ;
991
- }
944
+ assert . strictEqual ( foundPowerShell . exePath , expectedPowerShell . exePath ) ;
945
+ assert . strictEqual ( foundPowerShell . displayName , expectedPowerShell . displayName ) ;
946
+ assert . strictEqual ( foundPowerShell . supportsProperArguments , expectedPowerShell . supportsProperArguments ) ;
947
+ }
992
948
993
- assert . strictEqual (
994
- foundPowerShells . length ,
995
- testPlatform . expectedPowerShellSequence . length ,
996
- "Number of expected PowerShells found does not match" ,
997
- ) ;
998
- } ) ;
999
- }
949
+ assert . strictEqual (
950
+ foundPowerShells . length ,
951
+ testPlatform . expectedPowerShellSequence . length ,
952
+ "Number of expected PowerShells found does not match" ) ;
953
+ } ) ;
954
+ }
1000
955
1001
- for ( const testPlatform of errorTestCases ) {
1002
- it ( `Fails gracefully on ${ testPlatform . name } ` , async function ( ) {
1003
- setupTestEnvironment ( testPlatform ) ;
956
+ for ( const testPlatform of errorTestCases ) {
957
+ it ( `Fails gracefully on ${ testPlatform . name } ` , async function ( ) {
958
+ setupTestEnvironment ( testPlatform ) ;
1004
959
1005
- const powerShellExeFinder = new platform . PowerShellExeFinder (
1006
- testPlatform . platformDetails , { }
1007
- ) ;
960
+ const powerShellExeFinder = new platform . PowerShellExeFinder ( testPlatform . platformDetails , { } ) ;
1008
961
1009
- const foundPowerShells =
1010
- await powerShellExeFinder . getAllAvailablePowerShellInstallations ( ) ;
1011
- assert . strictEqual ( foundPowerShells . length , 0 ) ;
1012
- } ) ;
1013
- }
962
+ const foundPowerShells = await powerShellExeFinder . getAllAvailablePowerShellInstallations ( ) ;
963
+ assert . strictEqual ( foundPowerShells . length , 0 ) ;
964
+ } ) ;
965
+ }
1014
966
} ) ;
1015
967
1016
968
describe ( "Windows PowerShell path fix" , function ( ) {
1017
- for ( const testPlatform of successTestCases . filter (
1018
- ( tp ) =>
1019
- tp . platformDetails . operatingSystem ===
1020
- platform . OperatingSystem . Windows ,
1021
- ) ) {
1022
- it ( `Corrects the Windows PowerShell path on ${ testPlatform . name } ` , function ( ) {
1023
- setupTestEnvironment ( testPlatform ) ;
969
+ for ( const testPlatform of successTestCases
970
+ . filter ( ( tp ) => tp . platformDetails . operatingSystem === platform . OperatingSystem . Windows ) ) {
971
+
972
+ it ( `Corrects the Windows PowerShell path on ${ testPlatform . name } ` , function ( ) {
973
+ setupTestEnvironment ( testPlatform ) ;
1024
974
1025
- function getWinPSPath ( systemDir : string ) : string {
1026
- return path . join (
1027
- testPlatform . environmentVars . windir ,
1028
- systemDir ,
1029
- "WindowsPowerShell" ,
1030
- "v1.0" ,
1031
- "powershell.exe" ,
1032
- ) ;
1033
- }
975
+ function getWinPSPath ( systemDir : string ) : string {
976
+ return path . join (
977
+ testPlatform . environmentVars . windir ,
978
+ systemDir ,
979
+ "WindowsPowerShell" ,
980
+ "v1.0" ,
981
+ "powershell.exe" ) ;
982
+ }
1034
983
1035
- const winPSPath = getWinPSPath ( "System32" ) ;
984
+ const winPSPath = getWinPSPath ( "System32" ) ;
1036
985
1037
- let altWinPSPath ;
1038
- if ( testPlatform . platformDetails . isProcess64Bit ) {
1039
- altWinPSPath = getWinPSPath ( "SysWOW64" ) ;
1040
- } else if ( testPlatform . platformDetails . isOS64Bit ) {
1041
- altWinPSPath = getWinPSPath ( "Sysnative" ) ;
1042
- } else {
1043
- altWinPSPath = null ;
1044
- }
986
+ let altWinPSPath ;
987
+ if ( testPlatform . platformDetails . isProcess64Bit ) {
988
+ altWinPSPath = getWinPSPath ( "SysWOW64" ) ;
989
+ } else if ( testPlatform . platformDetails . isOS64Bit ) {
990
+ altWinPSPath = getWinPSPath ( "Sysnative" ) ;
991
+ } else {
992
+ altWinPSPath = null ;
993
+ }
1045
994
1046
- const powerShellExeFinder = new platform . PowerShellExeFinder (
1047
- testPlatform . platformDetails , { }
1048
- ) ;
995
+ const powerShellExeFinder = new platform . PowerShellExeFinder ( testPlatform . platformDetails , { } ) ;
1049
996
1050
- assert . strictEqual (
1051
- powerShellExeFinder . fixWindowsPowerShellPath ( winPSPath ) ,
1052
- winPSPath ,
1053
- ) ;
997
+ assert . strictEqual ( powerShellExeFinder . fixWindowsPowerShellPath ( winPSPath ) , winPSPath ) ;
1054
998
1055
- if ( altWinPSPath ) {
1056
- assert . strictEqual (
1057
- powerShellExeFinder . fixWindowsPowerShellPath ( altWinPSPath ) ,
1058
- winPSPath ,
1059
- ) ;
1060
- }
1061
- } ) ;
1062
- }
999
+ if ( altWinPSPath ) {
1000
+ assert . strictEqual ( powerShellExeFinder . fixWindowsPowerShellPath ( altWinPSPath ) , winPSPath ) ;
1001
+ }
1002
+ } ) ;
1003
+ }
1063
1004
} ) ;
1064
1005
1065
1006
describe ( "PowerShell executables from 'powerShellAdditionalExePaths' are found" , function ( ) {
1066
- for ( const testPlatform of successAdditionalTestCases ) {
1067
- it ( `Guesses for ${ testPlatform . name } ` , async function ( ) {
1068
- setupTestEnvironment ( testPlatform ) ;
1007
+ for ( const testPlatform of successAdditionalTestCases ) {
1008
+ it ( `Guesses for ${ testPlatform . name } ` , async function ( ) {
1009
+ setupTestEnvironment ( testPlatform ) ;
1069
1010
1070
- const powerShellExeFinder = new platform . PowerShellExeFinder (
1071
- testPlatform . platformDetails ,
1072
- additionalPowerShellExes ,
1073
- ) ;
1011
+ const powerShellExeFinder = new platform . PowerShellExeFinder ( testPlatform . platformDetails , additionalPowerShellExes ) ;
1074
1012
1075
- let i = 0 ;
1076
- for await ( const additionalPwsh of powerShellExeFinder . enumerateAdditionalPowerShellInstallations ( ) ) {
1077
- const expectedPowerShell =
1078
- testPlatform . expectedPowerShellSequence [ i ] ;
1079
- i ++ ;
1013
+ let i = 0 ;
1014
+ for await ( const additionalPwsh of powerShellExeFinder . enumerateAdditionalPowerShellInstallations ( ) ) {
1015
+ const expectedPowerShell = testPlatform . expectedPowerShellSequence [ i ] ;
1016
+ i ++ ;
1080
1017
1081
- assert . strictEqual (
1082
- additionalPwsh . exePath ,
1083
- expectedPowerShell . exePath ,
1084
- ) ;
1085
- assert . strictEqual (
1086
- additionalPwsh . displayName ,
1087
- expectedPowerShell . displayName ,
1088
- ) ;
1089
- }
1090
- } ) ;
1091
- }
1018
+ assert . strictEqual ( additionalPwsh . exePath , expectedPowerShell . exePath ) ;
1019
+ assert . strictEqual ( additionalPwsh . displayName , expectedPowerShell . displayName ) ;
1020
+ }
1021
+ } ) ;
1022
+ }
1092
1023
} ) ;
1093
1024
} ) ;
0 commit comments