@@ -5,6 +5,8 @@ const tmpdir = require('../common/tmpdir');
5
5
const assert = require ( 'assert' ) ;
6
6
const fs = require ( 'fs' ) ;
7
7
const path = require ( 'path' ) ;
8
+ const { pathToFileURL } = require ( 'url' ) ;
9
+
8
10
const { validateRmOptionsSync } = require ( 'internal/fs/utils' ) ;
9
11
10
12
tmpdir . refresh ( ) ;
@@ -95,6 +97,11 @@ function removeAsync(dir) {
95
97
makeNonEmptyDirectory ( 2 , 10 , 2 , dir , false ) ;
96
98
removeAsync ( dir ) ;
97
99
100
+ // Same test using URL instead of a path
101
+ dir = nextDirPath ( ) ;
102
+ makeNonEmptyDirectory ( 2 , 10 , 2 , dir , false ) ;
103
+ removeAsync ( pathToFileURL ( dir ) ) ;
104
+
98
105
// Create a flat folder including symlinks
99
106
dir = nextDirPath ( ) ;
100
107
makeNonEmptyDirectory ( 1 , 10 , 2 , dir , true ) ;
@@ -154,6 +161,16 @@ function removeAsync(dir) {
154
161
fs . rmSync ( filePath , { force : true } ) ;
155
162
}
156
163
164
+ // Should accept URL
165
+ const fileURL = pathToFileURL ( path . join ( tmpdir . path , 'rm-file.txt' ) ) ;
166
+ fs . writeFileSync ( fileURL , '' ) ;
167
+
168
+ try {
169
+ fs . rmSync ( fileURL , { recursive : true } ) ;
170
+ } finally {
171
+ fs . rmSync ( fileURL , { force : true } ) ;
172
+ }
173
+
157
174
// Recursive removal should succeed.
158
175
fs . rmSync ( dir , { recursive : true } ) ;
159
176
@@ -200,6 +217,16 @@ function removeAsync(dir) {
200
217
} finally {
201
218
fs . rmSync ( filePath , { force : true } ) ;
202
219
}
220
+
221
+ // Should accept URL
222
+ const fileURL = pathToFileURL ( path . join ( tmpdir . path , 'rm-promises-file.txt' ) ) ;
223
+ fs . writeFileSync ( fileURL , '' ) ;
224
+
225
+ try {
226
+ await fs . promises . rm ( fileURL , { recursive : true } ) ;
227
+ } finally {
228
+ fs . rmSync ( fileURL , { force : true } ) ;
229
+ }
203
230
} ) ( ) . then ( common . mustCall ( ) ) ;
204
231
205
232
// Test input validation.
0 commit comments