@@ -12,10 +12,10 @@ import {
1212 shouldOpenInExistingInstance ,
1313 shouldRunVsCodeCli ,
1414 splitOnFirstEquals ,
15+ readSocketPath ,
1516} from "../../../src/node/cli"
16- import { tmpdir } from "../../../src/node/constants"
1717import { generatePassword , paths } from "../../../src/node/util"
18- import { useEnv } from "../../utils/helpers"
18+ import { useEnv , tmpdir } from "../../utils/helpers"
1919
2020type Mutable < T > = {
2121 - readonly [ P in keyof T ] : T [ P ]
@@ -378,10 +378,11 @@ describe("parser", () => {
378378
379379describe ( "cli" , ( ) => {
380380 let args : Mutable < Args > = { _ : [ ] }
381- const testDir = path . join ( tmpdir , "tests/cli" )
381+ let testDir : string
382382 const vscodeIpcPath = path . join ( os . tmpdir ( ) , "vscode-ipc" )
383383
384384 beforeAll ( async ( ) => {
385+ testDir = await tmpdir ( "cli" )
385386 await fs . rmdir ( testDir , { recursive : true } )
386387 await fs . mkdir ( testDir , { recursive : true } )
387388 } )
@@ -655,3 +656,40 @@ password: ${password}
655656cert: false` )
656657 } )
657658} )
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