This repository was archived by the owner on Feb 26, 2024. It is now read-only.
File tree 4 files changed +72
-1
lines changed
4 files changed +72
-1
lines changed Original file line number Diff line number Diff line change
1
+ import { bindArguments } from '../common/utils' ;
2
+
3
+ let fs ;
4
+ try {
5
+ fs = require ( 'fs' ) ;
6
+ } catch ( err ) { }
7
+
8
+ // TODO(alxhub): Patch `watch` and `unwatchFile`.
9
+ const TO_PATCH = [
10
+ 'access' ,
11
+ 'appendFile' ,
12
+ 'chmod' ,
13
+ 'chown' ,
14
+ 'close' ,
15
+ 'exists' ,
16
+ 'fchmod' ,
17
+ 'fchown' ,
18
+ 'fdatasync' ,
19
+ 'fstat' ,
20
+ 'fsync' ,
21
+ 'ftruncate' ,
22
+ 'futimes' ,
23
+ 'lchmod' ,
24
+ 'lchown' ,
25
+ 'link' ,
26
+ 'lstat' ,
27
+ 'mkdir' ,
28
+ 'mkdtemp' ,
29
+ 'open' ,
30
+ 'read' ,
31
+ 'readdir' ,
32
+ 'readFile' ,
33
+ 'readlink' ,
34
+ 'realpath' ,
35
+ 'rename' ,
36
+ 'rmdir' ,
37
+ 'stat' ,
38
+ 'symlink' ,
39
+ 'truncate' ,
40
+ 'unlink' ,
41
+ 'utimes' ,
42
+ 'write' ,
43
+ 'writeFile' ,
44
+ ] ;
45
+
46
+ if ( fs ) {
47
+ TO_PATCH
48
+ . filter ( name => ! ! fs [ name ] && typeof fs [ name ] === 'function' )
49
+ . forEach ( name => {
50
+ fs [ name ] = ( ( delegate : Function ) => {
51
+ return function ( ) {
52
+ return delegate . apply ( this , bindArguments ( < any > arguments , 'fs.' + name ) ) ;
53
+ } ;
54
+ } ) ( fs [ name ] ) ;
55
+ } ) ;
56
+ }
Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ import '../zone';
2
2
import { patchTimer } from '../common/timers' ;
3
3
4
4
import './events' ;
5
+ import './fs' ;
5
6
6
7
const set = 'set' ;
7
8
const clear = 'clear' ;
Original file line number Diff line number Diff line change
1
+ import { exists } from 'fs' ;
2
+
3
+ describe ( 'nodejs file system' , ( ) => {
4
+ it ( 'has patched exists()' , ( done ) => {
5
+ const zoneA = Zone . current . fork ( { name : 'A' } ) ;
6
+ zoneA . run ( ( ) => {
7
+ exists ( 'testfile' , ( _ ) => {
8
+ expect ( Zone . current . name ) . toBe ( zoneA . name ) ;
9
+ done ( ) ;
10
+ } ) ;
11
+ } ) ;
12
+ } ) ;
13
+ } ) ;
Original file line number Diff line number Diff line change 1
- import './node/events.spec' ;
1
+ import './node/events.spec' ;
2
+ import './node/fs.spec' ;
You can’t perform that action at this time.
0 commit comments