@@ -11,11 +11,11 @@ import {
11
11
setDefaults ,
12
12
shouldOpenInExistingInstance ,
13
13
splitOnFirstEquals ,
14
+ readSocketPath ,
14
15
} from "../../../src/node/cli"
15
- import { tmpdir } from "../../../src/node/constants"
16
16
import { shouldSpawnCliProcess } from "../../../src/node/main"
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 ]
@@ -390,10 +390,11 @@ describe("parser", () => {
390
390
391
391
describe ( "cli" , ( ) => {
392
392
let args : Mutable < Args > = { _ : [ ] }
393
- const testDir = path . join ( tmpdir , "tests/cli" )
393
+ let testDir : string
394
394
const vscodeIpcPath = path . join ( os . tmpdir ( ) , "vscode-ipc" )
395
395
396
396
beforeAll ( async ( ) => {
397
+ testDir = await tmpdir ( "cli" )
397
398
await fs . rmdir ( testDir , { recursive : true } )
398
399
await fs . mkdir ( testDir , { recursive : true } )
399
400
} )
@@ -667,3 +668,40 @@ password: ${password}
667
668
cert: false` )
668
669
} )
669
670
} )
671
+
672
+ describe ( "readSocketPath" , ( ) => {
673
+ const fileContents = "readSocketPath file contents"
674
+ let tmpDirPath : string
675
+ let tmpFilePath : string
676
+
677
+ beforeEach ( async ( ) => {
678
+ tmpDirPath = await tmpdir ( "readSocketPath" )
679
+ tmpFilePath = path . join ( tmpDirPath , "readSocketPath.txt" )
680
+ await fs . writeFile ( tmpFilePath , fileContents )
681
+ } )
682
+
683
+ afterEach ( async ( ) => {
684
+ await fs . rmdir ( tmpDirPath , { recursive : true } )
685
+ } )
686
+
687
+ it ( "should throw an error if it can't read the file" , async ( ) => {
688
+ // TODO@jsjoeio - implement
689
+ // Test it on a directory.... ESDIR
690
+ // TODO@jsjoeio - implement
691
+ expect ( ( ) => readSocketPath ( tmpDirPath ) ) . rejects . toThrow ( "EISDIR" )
692
+ } )
693
+ it ( "should return undefined if it can't read the file" , async ( ) => {
694
+ // TODO@jsjoeio - implement
695
+ const socketPath = await readSocketPath ( path . join ( tmpDirPath , "not-a-file" ) )
696
+ expect ( socketPath ) . toBeUndefined ( )
697
+ } )
698
+ it ( "should return the file contents" , async ( ) => {
699
+ const contents = await readSocketPath ( tmpFilePath )
700
+ expect ( contents ) . toBe ( fileContents )
701
+ } )
702
+ it ( "should return the same file contents for two different calls" , async ( ) => {
703
+ const contents1 = await readSocketPath ( tmpFilePath )
704
+ const contents2 = await readSocketPath ( tmpFilePath )
705
+ expect ( contents2 ) . toBe ( contents1 )
706
+ } )
707
+ } )
0 commit comments