This repository was archived by the owner on May 21, 2019. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +21
-5
lines changed Expand file tree Collapse file tree 3 files changed +21
-5
lines changed Original file line number Diff line number Diff line change 44
44
"devDependencies" : {
45
45
"@types/chai" : " 3.4.22-alpha" ,
46
46
"@types/mocha" : " 2.2.21-alpha" ,
47
+ "@types/mock-fs" : " 3.6.22-alpha" ,
47
48
"chai" : " 3.5.0" ,
48
49
"devtron" : " 1.2.1" ,
49
50
"electron-builder" : " 5.7.0" ,
50
51
"electron-prebuilt" : " 1.2.5" ,
51
52
"mocha" : " 2.5.3" ,
53
+ "mock-fs" : " 3.9.0" ,
52
54
"npm-check-updates" : " 2.6.7" ,
53
55
"spectron" : " 3.2.3" ,
54
56
"ts-node" : " 0.9.3" ,
Original file line number Diff line number Diff line change @@ -58,9 +58,9 @@ export function recursiveFilesIn(directoryPath: string): Promise<string[]> {
58
58
) ;
59
59
}
60
60
61
- export function stat ( filePath : string ) : Promise < fs . Stats > {
61
+ export function lstat ( filePath : string ) : Promise < fs . Stats > {
62
62
return new Promise ( ( resolve , reject ) => {
63
- fs . stat ( filePath , ( error : NodeJS . ErrnoException , pathStat : fs . Stats ) => {
63
+ fs . lstat ( filePath , ( error : NodeJS . ErrnoException , pathStat : fs . Stats ) => {
64
64
if ( error ) {
65
65
reject ( error ) ;
66
66
} else {
@@ -72,7 +72,7 @@ export function stat(filePath: string): Promise<fs.Stats> {
72
72
73
73
export async function statsIn ( directoryPath : FullPath ) : Promise < i . FileInfo [ ] > {
74
74
return Promise . all ( ( await filesIn ( directoryPath ) ) . map ( async ( fileName ) => {
75
- return { name : fileName , stat : await stat ( Path . join ( directoryPath , fileName ) ) } ;
75
+ return { name : fileName , stat : await lstat ( Path . join ( directoryPath , fileName ) ) } ;
76
76
} ) ) ;
77
77
}
78
78
@@ -86,7 +86,7 @@ export function exists(filePath: string): Promise<boolean> {
86
86
87
87
export async function isDirectory ( directoryPath : string ) : Promise < boolean > {
88
88
if ( await exists ( directoryPath ) ) {
89
- return ( await stat ( directoryPath ) ) . isDirectory ( ) ;
89
+ return ( await lstat ( directoryPath ) ) . isDirectory ( ) ;
90
90
} else {
91
91
return false ;
92
92
}
Original file line number Diff line number Diff line change 1
1
import "mocha" ;
2
2
import { expect } from "chai" ;
3
- import { commonPrefix } from "../../src/utils/Common" ;
3
+ import { commonPrefix , lstat , resolveFile } from "../../src/utils/Common" ;
4
+ import * as mockFs from "mock-fs" ;
5
+
4
6
5
7
describe ( "common utils" , ( ) => {
6
8
describe ( "commonPrefix" , ( ) => {
7
9
it ( "returns the whole string for the same strings" , async ( ) => {
8
10
expect ( commonPrefix ( "abc" , "abc" ) ) . to . eql ( "abc" ) ;
9
11
} ) ;
10
12
} ) ;
13
+
14
+ describe ( "lstat" , ( ) => {
15
+ it ( "returns stats even if the file is a borken symlink" , async ( ) => {
16
+ mockFs ( {
17
+ "/broken-symlink" : mockFs . symlink ( {
18
+ path : "non-existing-file"
19
+ } )
20
+ } ) ;
21
+ const stats = await lstat ( resolveFile ( "/" , "/broken-symlink" ) )
22
+ expect ( stats ) . to . exist ;
23
+ } ) ;
24
+ } ) ;
11
25
} ) ;
You can’t perform that action at this time.
0 commit comments