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