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