4
4
const fs = require ( 'fs' )
5
5
const { expect } = require ( 'interface-ipfs-core/src/utils/mocha' )
6
6
const path = require ( 'path' )
7
- const rimraf = require ( 'rimraf' ) . sync
7
+ const clean = require ( '../utils/clean' )
8
8
const CID = require ( 'cids' )
9
9
const cli = require ( '../utils/cli' )
10
10
const sinon = require ( 'sinon' )
@@ -33,15 +33,15 @@ describe('get', () => {
33
33
} ] )
34
34
35
35
const outPath = path . join ( process . cwd ( ) , cid . toString ( ) )
36
- rimraf ( outPath )
36
+ await clean ( outPath )
37
37
38
38
const out = await cli ( `get ${ cid } ` , { ipfs } )
39
39
expect ( out )
40
40
. to . equal ( `Saving file(s) ${ cid } \n` )
41
41
42
42
expect ( fs . readFileSync ( outPath ) ) . to . deep . equal ( buf )
43
43
44
- rimraf ( outPath )
44
+ await clean ( outPath )
45
45
} )
46
46
47
47
it ( 'get file with output option' , async ( ) => {
@@ -53,15 +53,15 @@ describe('get', () => {
53
53
} ] )
54
54
55
55
const outPath = path . join ( process . cwd ( ) , 'derp' )
56
- rimraf ( outPath )
56
+ await clean ( outPath )
57
57
58
58
const out = await cli ( `get ${ cid } --output ${ outPath } ` , { ipfs } )
59
59
expect ( out )
60
60
. to . equal ( `Saving file(s) ${ cid } \n` )
61
61
62
62
expect ( fs . readFileSync ( path . join ( outPath , cid . toString ( ) ) ) ) . to . deep . equal ( buf )
63
63
64
- rimraf ( outPath )
64
+ await clean ( outPath )
65
65
} )
66
66
67
67
it ( 'get file with short output option' , async ( ) => {
@@ -73,15 +73,15 @@ describe('get', () => {
73
73
} ] )
74
74
75
75
const outPath = path . join ( process . cwd ( ) , 'herp' )
76
- rimraf ( outPath )
76
+ await clean ( outPath )
77
77
78
78
const out = await cli ( `get ${ cid } -o ${ outPath } ` , { ipfs } )
79
79
expect ( out )
80
80
. to . equal ( `Saving file(s) ${ cid } \n` )
81
81
82
82
expect ( fs . readFileSync ( path . join ( outPath , cid . toString ( ) ) ) ) . to . deep . equal ( buf )
83
83
84
- rimraf ( outPath )
84
+ await clean ( outPath )
85
85
} )
86
86
87
87
it ( 'get directory' , async ( ) => {
@@ -90,15 +90,15 @@ describe('get', () => {
90
90
} ] )
91
91
92
92
const outPath = path . join ( process . cwd ( ) , cid . toString ( ) )
93
- rimraf ( outPath )
93
+ await clean ( outPath )
94
94
95
95
const out = await cli ( `get ${ cid } ` , { ipfs } )
96
96
expect ( out )
97
97
. to . equal ( `Saving file(s) ${ cid } \n` )
98
98
99
99
expect ( fs . statSync ( outPath ) . isDirectory ( ) ) . to . be . true ( )
100
100
101
- rimraf ( outPath )
101
+ await clean ( outPath )
102
102
} )
103
103
104
104
it ( 'get recursively' , async ( ) => {
@@ -112,7 +112,7 @@ describe('get', () => {
112
112
} ] )
113
113
114
114
const outPath = path . join ( process . cwd ( ) , cid . toString ( ) )
115
- rimraf ( outPath )
115
+ await clean ( outPath )
116
116
117
117
const out = await cli ( `get ${ cid } ` , { ipfs } )
118
118
expect ( out ) . to . eql (
@@ -123,7 +123,7 @@ describe('get', () => {
123
123
expect ( fs . statSync ( path . join ( outPath , 'foo.txt' ) ) . isFile ( ) ) . to . be . true ( )
124
124
expect ( fs . readFileSync ( path . join ( outPath , 'foo.txt' ) ) ) . to . deep . equal ( buf )
125
125
126
- rimraf ( outPath )
126
+ await clean ( outPath )
127
127
} )
128
128
129
129
it ( 'should get file with a timeout' , async ( ) => {
@@ -138,14 +138,14 @@ describe('get', () => {
138
138
} ] )
139
139
140
140
const outPath = path . join ( process . cwd ( ) , cid . toString ( ) )
141
- rimraf ( outPath )
141
+ await clean ( outPath )
142
142
143
143
const out = await cli ( `get ${ cid } --timeout=1s` , { ipfs } )
144
144
expect ( out )
145
145
. to . equal ( `Saving file(s) ${ cid } \n` )
146
146
147
147
expect ( fs . readFileSync ( outPath ) ) . to . deep . equal ( buf )
148
148
149
- rimraf ( outPath )
149
+ await clean ( outPath )
150
150
} )
151
151
} )
0 commit comments