You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/__tests__/volume/rmSync.test.ts
+94Lines changed: 94 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -14,4 +14,98 @@ describe('rmSync', () => {
14
14
'/oof': 'zab',
15
15
});
16
16
});
17
+
18
+
it('removes a single file',()=>{
19
+
constvol=create({
20
+
'/a/b/c.txt': 'content',
21
+
});
22
+
23
+
vol.rmSync('/a/b/c.txt');
24
+
25
+
expect(vol.toJSON()).toEqual({
26
+
'/a/b': null,
27
+
});
28
+
});
29
+
30
+
describe('when file does not exist',()=>{
31
+
it('throws by default',()=>{
32
+
constvol=create({
33
+
'/foo.txt': 'content',
34
+
});
35
+
36
+
expect(()=>vol.rmSync('/bar.txt')).toThrowError(newError("ENOENT: no such file or directory, stat '/bar.txt'"));
37
+
});
38
+
39
+
it('does not throw if "force" is set to true',()=>{
40
+
constvol=create({
41
+
'/foo.txt': 'content',
42
+
});
43
+
44
+
vol.rmSync('/bar.txt',{force: true});
45
+
});
46
+
});
47
+
48
+
describe('when deleting a directory',()=>{
49
+
it('throws by default',()=>{
50
+
constvol=create({
51
+
'/usr/bin/bash': '...',
52
+
});
53
+
54
+
expect(()=>vol.rmSync('/usr/bin')).toThrowError(newError("[ERR_FS_EISDIR]: Path is a directory: rm returned EISDIR (is a directory) /usr/bin"));
55
+
});
56
+
57
+
it('throws by when force flag is set',()=>{
58
+
constvol=create({
59
+
'/usr/bin/bash': '...',
60
+
});
61
+
62
+
expect(()=>vol.rmSync('/usr/bin',{force: true})).toThrowError(newError("[ERR_FS_EISDIR]: Path is a directory: rm returned EISDIR (is a directory) /usr/bin"));
63
+
});
64
+
65
+
it('deletes all directory contents when recursive flag is set',()=>{
66
+
constvol=create({
67
+
'/usr/bin/bash': '...',
68
+
});
69
+
70
+
vol.rmSync('/usr/bin',{recursive: true});
71
+
72
+
expect(vol.toJSON()).toEqual({'/usr': null});
73
+
});
74
+
75
+
it('deletes all directory contents recursively when recursive flag is set',()=>{
0 commit comments