@@ -11,47 +11,19 @@ let failRm = false
11
11
let failRename = null
12
12
let failRenameOnce = null
13
13
let failMkdir = null
14
- const { rename : realRename , rm : realRm , mkdir : realMkdir } = fs
15
- const fsMock = {
16
- ...fs ,
17
- mkdir ( ...args ) {
18
- if ( failMkdir ) {
19
- process . nextTick ( ( ) => args . pop ( ) ( failMkdir ) )
20
- return
21
- }
22
-
23
- return realMkdir ( ...args )
24
- } ,
25
- rename ( ...args ) {
26
- if ( failRename ) {
27
- process . nextTick ( ( ) => args . pop ( ) ( failRename ) )
28
- } else if ( failRenameOnce ) {
29
- const er = failRenameOnce
30
- failRenameOnce = null
31
- process . nextTick ( ( ) => args . pop ( ) ( er ) )
32
- } else {
33
- return realRename ( ...args )
34
- }
35
- } ,
36
- rm ( ...args ) {
37
- if ( failRm ) {
38
- process . nextTick ( ( ) => args . pop ( ) ( new Error ( 'rm fail' ) ) )
39
- return
40
- }
41
14
42
- realRm ( ...args )
43
- } ,
44
- }
45
15
const fspMock = {
46
16
...fsp ,
47
17
mkdir : async ( ...args ) => {
18
+ fs . appendFileSync ( 'reggi-log.txt' , 'fspNodeMock.mkdir\n' )
48
19
if ( failMkdir ) {
49
20
throw failMkdir
50
21
}
51
22
52
23
return fsp . mkdir ( ...args )
53
24
} ,
54
25
rename : async ( ...args ) => {
26
+ fs . appendFileSync ( 'reggi-log.txt' , 'fspNodeMock.rename\n' )
55
27
if ( failRename ) {
56
28
throw failRename
57
29
} else if ( failRenameOnce ) {
@@ -63,19 +35,19 @@ const fspMock = {
63
35
}
64
36
} ,
65
37
rm : async ( ...args ) => {
38
+ fs . appendFileSync ( 'reggi-log.txt' , 'fspNodeMock.rm\n' )
66
39
if ( failRm ) {
67
40
throw new Error ( 'rm fail' )
68
41
}
69
42
70
43
return fsp . rm ( ...args )
71
44
} ,
72
45
}
46
+
73
47
// need this to be injected so that it doesn't pull from main cache
74
- const { moveFile } = t . mock ( '@npmcli/fs' , { 'node:fs/promises' : fspMock , ' fs/promises' : fspMock } )
48
+ const { moveFile } = t . mock ( '@npmcli/fs' , { 'fs/promises' : fspMock } )
75
49
const mocks = {
76
- fs : fsMock ,
77
50
'node:fs/promises' : fspMock ,
78
- 'fs/promises' : fspMock ,
79
51
'@npmcli/fs' : { ...npmFs , moveFile } ,
80
52
}
81
53
0 commit comments