@@ -12,10 +12,10 @@ import {
12
12
shouldOpenInExistingInstance ,
13
13
shouldRunVsCodeCli ,
14
14
splitOnFirstEquals ,
15
+ readSocketPath ,
15
16
} from "../../../src/node/cli"
16
- import { tmpdir } from "../../../src/node/constants"
17
17
import { generatePassword , paths } from "../../../src/node/util"
18
- import { useEnv } from "../../utils/helpers"
18
+ import { useEnv , tmpdir } from "../../utils/helpers"
19
19
20
20
type Mutable < T > = {
21
21
- readonly [ P in keyof T ] : T [ P ]
@@ -378,10 +378,11 @@ describe("parser", () => {
378
378
379
379
describe ( "cli" , ( ) => {
380
380
let args : Mutable < Args > = { _ : [ ] }
381
- const testDir = path . join ( tmpdir , "tests/cli" )
381
+ let testDir : string
382
382
const vscodeIpcPath = path . join ( os . tmpdir ( ) , "vscode-ipc" )
383
383
384
384
beforeAll ( async ( ) => {
385
+ testDir = await tmpdir ( "cli" )
385
386
await fs . rmdir ( testDir , { recursive : true } )
386
387
await fs . mkdir ( testDir , { recursive : true } )
387
388
} )
@@ -655,3 +656,40 @@ password: ${password}
655
656
cert: false` )
656
657
} )
657
658
} )
659
+
660
+ describe ( "readSocketPath" , ( ) => {
661
+ const fileContents = "readSocketPath file contents"
662
+ let tmpDirPath : string
663
+ let tmpFilePath : string
664
+
665
+ beforeEach ( async ( ) => {
666
+ tmpDirPath = await tmpdir ( "readSocketPath" )
667
+ tmpFilePath = path . join ( tmpDirPath , "readSocketPath.txt" )
668
+ await fs . writeFile ( tmpFilePath , fileContents )
669
+ } )
670
+
671
+ afterEach ( async ( ) => {
672
+ await fs . rmdir ( tmpDirPath , { recursive : true } )
673
+ } )
674
+
675
+ it ( "should throw an error if it can't read the file" , async ( ) => {
676
+ // TODO@jsjoeio - implement
677
+ // Test it on a directory.... ESDIR
678
+ // TODO@jsjoeio - implement
679
+ expect ( ( ) => readSocketPath ( tmpDirPath ) ) . rejects . toThrow ( "EISDIR" )
680
+ } )
681
+ it ( "should return undefined if it can't read the file" , async ( ) => {
682
+ // TODO@jsjoeio - implement
683
+ const socketPath = await readSocketPath ( path . join ( tmpDirPath , "not-a-file" ) )
684
+ expect ( socketPath ) . toBeUndefined ( )
685
+ } )
686
+ it ( "should return the file contents" , async ( ) => {
687
+ const contents = await readSocketPath ( tmpFilePath )
688
+ expect ( contents ) . toBe ( fileContents )
689
+ } )
690
+ it ( "should return the same file contents for two different calls" , async ( ) => {
691
+ const contents1 = await readSocketPath ( tmpFilePath )
692
+ const contents2 = await readSocketPath ( tmpFilePath )
693
+ expect ( contents2 ) . toBe ( contents1 )
694
+ } )
695
+ } )
0 commit comments