@@ -6,50 +6,8 @@ import mockFS = require("mock-fs");
66import FileSystem = require( "mock-fs/lib/filesystem" ) ;
77import * as os from "os" ;
88import * as path from "path" ;
9- import rewire = require( "rewire" ) ;
109import * as sinon from "sinon" ;
1110import * 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 ) ;
5311
5412/**
5513 * Describes a platform on which the PowerShell extension should work,
@@ -847,8 +805,12 @@ function setupTestEnvironment(testPlatform: ITestPlatform): void {
847805}
848806
849807describe ( "Platform module" , function ( ) {
808+ afterEach ( function ( ) {
809+ mockFS . restore ( ) ;
810+ } ) ;
811+ 850812 it ( "Gets the correct platform details" , function ( ) {
851- const platformDetails : platform . IPlatformDetails = platformMock . getPlatformDetails ( ) ;
813+ const platformDetails : platform . IPlatformDetails = platform . getPlatformDetails ( ) ;
852814 switch ( process . platform ) {
853815 case "darwin" :
854816 assert . strictEqual (
@@ -901,31 +863,26 @@ describe("Platform module", function () {
901863 } ) ;
902864
903865 describe ( "Default PowerShell installation" , function ( ) {
904- afterEach ( function ( ) {
905- sinon . restore ( ) ;
906- mockFS . restore ( ) ;
907- } ) ;
908- 909866 for ( const testPlatform of successTestCases ) {
910867 it ( `Finds it on ${ testPlatform . name } ` , async function ( ) {
911868 setupTestEnvironment ( testPlatform ) ;
912869
913- const powerShellExeFinder = new platformMock . PowerShellExeFinder ( testPlatform . platformDetails ) ;
870+ const powerShellExeFinder = new platform . PowerShellExeFinder ( testPlatform . platformDetails , { } ) ;
914871
915872 const defaultPowerShell = await powerShellExeFinder . getFirstAvailablePowerShellInstallation ( ) ;
916873 const expectedPowerShell = testPlatform . expectedPowerShellSequence [ 0 ] ;
917874
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 ) ;
921878 } ) ;
922879 }
923880
924881 for ( const testPlatform of errorTestCases ) {
925882 it ( `Fails gracefully on ${ testPlatform . name } ` , async function ( ) {
926883 setupTestEnvironment ( testPlatform ) ;
927884
928- const powerShellExeFinder = new platformMock . PowerShellExeFinder ( testPlatform . platformDetails ) ;
885+ const powerShellExeFinder = new platform . PowerShellExeFinder ( testPlatform . platformDetails , { } ) ;
929886
930887 const defaultPowerShell = await powerShellExeFinder . getFirstAvailablePowerShellInstallation ( ) ;
931888 assert . strictEqual ( defaultPowerShell , undefined ) ;
@@ -934,26 +891,21 @@ describe("Platform module", function () {
934891 } ) ;
935892
936893 describe ( "Expected PowerShell installation list" , function ( ) {
937- afterEach ( function ( ) {
938- sinon . restore ( ) ;
939- mockFS . restore ( ) ;
940- } ) ;
941- 942894 for ( const testPlatform of successTestCases ) {
943895 it ( `Finds them on ${ testPlatform . name } ` , async function ( ) {
944896 setupTestEnvironment ( testPlatform ) ;
945897
946- const powerShellExeFinder = new platformMock . PowerShellExeFinder ( testPlatform . platformDetails ) ;
898+ const powerShellExeFinder = new platform . PowerShellExeFinder ( testPlatform . platformDetails , { } ) ;
947899
948900 const foundPowerShells = await powerShellExeFinder . getAllAvailablePowerShellInstallations ( ) ;
949901
950902 for ( let i = 0 ; i < testPlatform . expectedPowerShellSequence . length ; i ++ ) {
951903 const foundPowerShell = foundPowerShells [ i ] ;
952904 const expectedPowerShell = testPlatform . expectedPowerShellSequence [ i ] ;
953905
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 ) ;
957909 }
958910
959911 assert . strictEqual (
@@ -967,7 +919,7 @@ describe("Platform module", function () {
967919 it ( `Fails gracefully on ${ testPlatform . name } ` , async function ( ) {
968920 setupTestEnvironment ( testPlatform ) ;
969921
970- const powerShellExeFinder = new platformMock . PowerShellExeFinder ( testPlatform . platformDetails ) ;
922+ const powerShellExeFinder = new platform . PowerShellExeFinder ( testPlatform . platformDetails , { } ) ;
971923
972924 const foundPowerShells = await powerShellExeFinder . getAllAvailablePowerShellInstallations ( ) ;
973925 assert . strictEqual ( foundPowerShells . length , 0 ) ;
@@ -976,11 +928,6 @@ describe("Platform module", function () {
976928 } ) ;
977929
978930 describe ( "Windows PowerShell path fix" , function ( ) {
979- afterEach ( function ( ) {
980- sinon . restore ( ) ;
981- mockFS . restore ( ) ;
982- } ) ;
983- 984931 for ( const testPlatform of successTestCases
985932 . filter ( ( tp ) => tp . platformDetails . operatingSystem === platform . OperatingSystem . Windows ) ) {
986933
@@ -1007,7 +954,7 @@ describe("Platform module", function () {
1007954 altWinPSPath = null ;
1008955 }
1009956
1010- const powerShellExeFinder = new platformMock . PowerShellExeFinder ( testPlatform . platformDetails ) ;
957+ const powerShellExeFinder = new platform . PowerShellExeFinder ( testPlatform . platformDetails , { } ) ;
1011958
1012959 assert . strictEqual ( powerShellExeFinder . fixWindowsPowerShellPath ( winPSPath ) , winPSPath ) ;
1013960
@@ -1019,16 +966,11 @@ describe("Platform module", function () {
1019966 } ) ;
1020967
1021968 describe ( "PowerShell executables from 'powerShellAdditionalExePaths' are found" , function ( ) {
1022- afterEach ( function ( ) {
1023- sinon . restore ( ) ;
1024- mockFS . restore ( ) ;
1025- } ) ;
1026- 1027969 for ( const testPlatform of successAdditionalTestCases ) {
1028970 it ( `Guesses for ${ testPlatform . name } ` , async function ( ) {
1029971 setupTestEnvironment ( testPlatform ) ;
1030972
1031- const powerShellExeFinder = new platformMock . PowerShellExeFinder ( testPlatform . platformDetails , additionalPowerShellExes ) ;
973+ const powerShellExeFinder = new platform . PowerShellExeFinder ( testPlatform . platformDetails , additionalPowerShellExes ) ;
1032974
1033975 let i = 0 ;
1034976 for await ( const additionalPwsh of powerShellExeFinder . enumerateAdditionalPowerShellInstallations ( ) ) {
0 commit comments