1
1
import * as cp from "child_process"
2
+ import * as path from "path"
3
+ import { promises as fs } from "fs"
2
4
import { generateUuid } from "../../../src/common/util"
3
5
import * as util from "../../../src/node/util"
6
+ import { tmpdir } from "../../../src/node/constants"
4
7
5
8
describe ( "getEnvPaths" , ( ) => {
6
9
describe ( "on darwin" , ( ) => {
@@ -464,20 +467,6 @@ describe("pathToFsPath", () => {
464
467
it ( "should keep drive letter casing when set to true" , ( ) => {
465
468
expect ( util . pathToFsPath ( "/C:/far/bo" , true ) ) . toBe ( "C:/far/bo" )
466
469
} )
467
- it ( "should throw an error if a non-string is passed in for path" , ( ) => {
468
- expect ( ( ) =>
469
- util
470
- // @ts -expect-error We need to check other types
471
- . pathToFsPath ( { } ) ,
472
- ) . toThrow ( `Could not compute fsPath from given uri. Expected path to be of type string, but was of type undefined.` )
473
- } )
474
- it ( "should not throw an error for a string array" , ( ) => {
475
- // @ts -expect-error We need to check other types
476
- expect ( ( ) => util . pathToFsPath ( [ "/hello/foo" , "/hello/bar" ] ) . not . toThrow ( ) )
477
- } )
478
- it ( "should use the first string in a string array" , ( ) => {
479
- expect ( util . pathToFsPath ( [ "/hello/foo" , "/hello/bar" ] ) ) . toBe ( "/hello/foo" )
480
- } )
481
470
it ( "should replace / with \\ on Windows" , ( ) => {
482
471
let ORIGINAL_PLATFORM = process . platform
483
472
@@ -492,3 +481,23 @@ describe("pathToFsPath", () => {
492
481
} )
493
482
} )
494
483
} )
484
+
485
+ describe ( "isFile" , ( ) => {
486
+ const testDir = path . join ( tmpdir , "tests" , "isFile" )
487
+ let pathToFile = ""
488
+
489
+ beforeEach ( async ( ) => {
490
+ pathToFile = path . join ( testDir , "foo.txt" )
491
+ await fs . mkdir ( testDir , { recursive : true } )
492
+ await fs . writeFile ( pathToFile , "hello" )
493
+ } )
494
+ afterEach ( async ( ) => {
495
+ await fs . rm ( testDir , { recursive : true , force : true } )
496
+ } )
497
+ it ( "should return false if the path doesn't exist" , async ( ) => {
498
+ expect ( await util . isFile ( testDir ) ) . toBe ( false )
499
+ } )
500
+ it ( "should return true if is file" , async ( ) => {
501
+ expect ( await util . isFile ( pathToFile ) ) . toBe ( true )
502
+ } )
503
+ } )
0 commit comments