@@ -6,50 +6,8 @@ import mockFS = require("mock-fs");
6
6
import FileSystem = require( "mock-fs/lib/filesystem" ) ;
7
7
import * as os from "os" ;
8
8
import * as path from "path" ;
9
- import rewire = require( "rewire" ) ;
10
9
import * as sinon from "sinon" ;
11
10
import * as platform from "../../src/platform" ;
12
- import * as fs from "fs" ; // NOTE: Necessary for mock-fs.
13
- import * as vscode from "vscode" ;
14
- import { stripQuotePair } from "../../src/utils" ;
15
-
16
- // We have to rewire the platform module so that mock-fs can be used, as it
17
- // overrides the fs module but not the vscode.workspace.fs module.
18
- const platformMock = rewire ( "../../src/platform" ) ;
19
-
20
- // eslint-disable-next-line @typescript-eslint/require-await
21
- async function fakeCheckIfFileExists ( targetPath : string | vscode . Uri ) : Promise < boolean > {
22
- try {
23
- const stat = fs . lstatSync ( targetPath instanceof vscode . Uri ? targetPath . fsPath : targetPath ) ;
24
- return stat . isFile ( ) ;
25
- } catch {
26
- return false ;
27
- }
28
- }
29
-
30
- // eslint-disable-next-line @typescript-eslint/require-await
31
- async function fakeCheckIfDirectoryExists ( targetPath : string | vscode . Uri ) : Promise < boolean > {
32
- try {
33
- const stat = fs . lstatSync ( targetPath instanceof vscode . Uri ? targetPath . fsPath : targetPath ) ;
34
- return stat . isDirectory ( ) ;
35
- } catch {
36
- return false ;
37
- }
38
- }
39
-
40
- // eslint-disable-next-line @typescript-eslint/require-await
41
- async function fakeReadDirectory ( targetPath : string | vscode . Uri ) : Promise < string [ ] > {
42
- return fs . readdirSync ( targetPath instanceof vscode . Uri ? targetPath . fsPath : targetPath ) ;
43
- }
44
-
45
- const utilsMock = {
46
- checkIfFileExists : fakeCheckIfFileExists ,
47
- checkIfDirectoryExists : fakeCheckIfDirectoryExists ,
48
- readDirectory : fakeReadDirectory ,
49
- stripQuotePair : stripQuotePair
50
- } ;
51
-
52
- platformMock . __set__ ( "utils" , utilsMock ) ;
53
11
54
12
/**
55
13
* Describes a platform on which the PowerShell extension should work,
@@ -847,8 +805,12 @@ function setupTestEnvironment(testPlatform: ITestPlatform): void {
847
805
}
848
806
849
807
describe ( "Platform module" , function ( ) {
808
+ afterEach ( function ( ) {
809
+ mockFS . restore ( ) ;
810
+ } ) ;
811
+
850
812
it ( "Gets the correct platform details" , function ( ) {
851
- const platformDetails : platform . IPlatformDetails = platformMock . getPlatformDetails ( ) ;
813
+ const platformDetails : platform . IPlatformDetails = platform . getPlatformDetails ( ) ;
852
814
switch ( process . platform ) {
853
815
case "darwin" :
854
816
assert . strictEqual (
@@ -901,31 +863,26 @@ describe("Platform module", function () {
901
863
} ) ;
902
864
903
865
describe ( "Default PowerShell installation" , function ( ) {
904
- afterEach ( function ( ) {
905
- sinon . restore ( ) ;
906
- mockFS . restore ( ) ;
907
- } ) ;
908
-
909
866
for ( const testPlatform of successTestCases ) {
910
867
it ( `Finds it on ${ testPlatform . name } ` , async function ( ) {
911
868
setupTestEnvironment ( testPlatform ) ;
912
869
913
- const powerShellExeFinder = new platformMock . PowerShellExeFinder ( testPlatform . platformDetails ) ;
870
+ const powerShellExeFinder = new platform . PowerShellExeFinder ( testPlatform . platformDetails , { } ) ;
914
871
915
872
const defaultPowerShell = await powerShellExeFinder . getFirstAvailablePowerShellInstallation ( ) ;
916
873
const expectedPowerShell = testPlatform . expectedPowerShellSequence [ 0 ] ;
917
874
918
- assert . strictEqual ( defaultPowerShell . exePath , expectedPowerShell . exePath ) ;
919
- assert . strictEqual ( defaultPowerShell . displayName , expectedPowerShell . displayName ) ;
920
- assert . strictEqual ( defaultPowerShell . supportsProperArguments , expectedPowerShell . supportsProperArguments ) ;
875
+ assert . strictEqual ( defaultPowerShell ! . exePath , expectedPowerShell . exePath ) ;
876
+ assert . strictEqual ( defaultPowerShell ! . displayName , expectedPowerShell . displayName ) ;
877
+ assert . strictEqual ( defaultPowerShell ! . supportsProperArguments , expectedPowerShell . supportsProperArguments ) ;
921
878
} ) ;
922
879
}
923
880
924
881
for ( const testPlatform of errorTestCases ) {
925
882
it ( `Fails gracefully on ${ testPlatform . name } ` , async function ( ) {
926
883
setupTestEnvironment ( testPlatform ) ;
927
884
928
- const powerShellExeFinder = new platformMock . PowerShellExeFinder ( testPlatform . platformDetails ) ;
885
+ const powerShellExeFinder = new platform . PowerShellExeFinder ( testPlatform . platformDetails , { } ) ;
929
886
930
887
const defaultPowerShell = await powerShellExeFinder . getFirstAvailablePowerShellInstallation ( ) ;
931
888
assert . strictEqual ( defaultPowerShell , undefined ) ;
@@ -934,26 +891,21 @@ describe("Platform module", function () {
934
891
} ) ;
935
892
936
893
describe ( "Expected PowerShell installation list" , function ( ) {
937
- afterEach ( function ( ) {
938
- sinon . restore ( ) ;
939
- mockFS . restore ( ) ;
940
- } ) ;
941
-
942
894
for ( const testPlatform of successTestCases ) {
943
895
it ( `Finds them on ${ testPlatform . name } ` , async function ( ) {
944
896
setupTestEnvironment ( testPlatform ) ;
945
897
946
- const powerShellExeFinder = new platformMock . PowerShellExeFinder ( testPlatform . platformDetails ) ;
898
+ const powerShellExeFinder = new platform . PowerShellExeFinder ( testPlatform . platformDetails , { } ) ;
947
899
948
900
const foundPowerShells = await powerShellExeFinder . getAllAvailablePowerShellInstallations ( ) ;
949
901
950
902
for ( let i = 0 ; i < testPlatform . expectedPowerShellSequence . length ; i ++ ) {
951
903
const foundPowerShell = foundPowerShells [ i ] ;
952
904
const expectedPowerShell = testPlatform . expectedPowerShellSequence [ i ] ;
953
905
954
- assert . strictEqual ( foundPowerShell ? .exePath , expectedPowerShell . exePath ) ;
955
- assert . strictEqual ( foundPowerShell ? .displayName , expectedPowerShell . displayName ) ;
956
- assert . strictEqual ( foundPowerShell ? .supportsProperArguments , expectedPowerShell . supportsProperArguments ) ;
906
+ assert . strictEqual ( foundPowerShell . exePath , expectedPowerShell . exePath ) ;
907
+ assert . strictEqual ( foundPowerShell . displayName , expectedPowerShell . displayName ) ;
908
+ assert . strictEqual ( foundPowerShell . supportsProperArguments , expectedPowerShell . supportsProperArguments ) ;
957
909
}
958
910
959
911
assert . strictEqual (
@@ -967,7 +919,7 @@ describe("Platform module", function () {
967
919
it ( `Fails gracefully on ${ testPlatform . name } ` , async function ( ) {
968
920
setupTestEnvironment ( testPlatform ) ;
969
921
970
- const powerShellExeFinder = new platformMock . PowerShellExeFinder ( testPlatform . platformDetails ) ;
922
+ const powerShellExeFinder = new platform . PowerShellExeFinder ( testPlatform . platformDetails , { } ) ;
971
923
972
924
const foundPowerShells = await powerShellExeFinder . getAllAvailablePowerShellInstallations ( ) ;
973
925
assert . strictEqual ( foundPowerShells . length , 0 ) ;
@@ -976,11 +928,6 @@ describe("Platform module", function () {
976
928
} ) ;
977
929
978
930
describe ( "Windows PowerShell path fix" , function ( ) {
979
- afterEach ( function ( ) {
980
- sinon . restore ( ) ;
981
- mockFS . restore ( ) ;
982
- } ) ;
983
-
984
931
for ( const testPlatform of successTestCases
985
932
. filter ( ( tp ) => tp . platformDetails . operatingSystem === platform . OperatingSystem . Windows ) ) {
986
933
@@ -1007,7 +954,7 @@ describe("Platform module", function () {
1007
954
altWinPSPath = null ;
1008
955
}
1009
956
1010
- const powerShellExeFinder = new platformMock . PowerShellExeFinder ( testPlatform . platformDetails ) ;
957
+ const powerShellExeFinder = new platform . PowerShellExeFinder ( testPlatform . platformDetails , { } ) ;
1011
958
1012
959
assert . strictEqual ( powerShellExeFinder . fixWindowsPowerShellPath ( winPSPath ) , winPSPath ) ;
1013
960
@@ -1019,16 +966,11 @@ describe("Platform module", function () {
1019
966
} ) ;
1020
967
1021
968
describe ( "PowerShell executables from 'powerShellAdditionalExePaths' are found" , function ( ) {
1022
- afterEach ( function ( ) {
1023
- sinon . restore ( ) ;
1024
- mockFS . restore ( ) ;
1025
- } ) ;
1026
-
1027
969
for ( const testPlatform of successAdditionalTestCases ) {
1028
970
it ( `Guesses for ${ testPlatform . name } ` , async function ( ) {
1029
971
setupTestEnvironment ( testPlatform ) ;
1030
972
1031
- const powerShellExeFinder = new platformMock . PowerShellExeFinder ( testPlatform . platformDetails , additionalPowerShellExes ) ;
973
+ const powerShellExeFinder = new platform . PowerShellExeFinder ( testPlatform . platformDetails , additionalPowerShellExes ) ;
1032
974
1033
975
let i = 0 ;
1034
976
for await ( const additionalPwsh of powerShellExeFinder . enumerateAdditionalPowerShellInstallations ( ) ) {
0 commit comments