@@ -5,6 +5,8 @@ const tmpdir = require('../common/tmpdir');
55const assert = require ( 'assert' ) ;
66const fs = require ( 'fs' ) ;
77const path = require ( 'path' ) ;
8+ const { pathToFileURL } = require ( 'url' ) ;
9+
810const { validateRmOptionsSync } = require ( 'internal/fs/utils' ) ;
911
1012tmpdir . refresh ( ) ;
@@ -95,6 +97,11 @@ function removeAsync(dir) {
9597 makeNonEmptyDirectory ( 2 , 10 , 2 , dir , false ) ;
9698 removeAsync ( dir ) ;
9799
100+ // Same test using URL instead of a path
101+ dir = nextDirPath ( ) ;
102+ makeNonEmptyDirectory ( 2 , 10 , 2 , dir , false ) ;
103+ removeAsync ( pathToFileURL ( dir ) ) ;
104+
98105 // Create a flat folder including symlinks
99106 dir = nextDirPath ( ) ;
100107 makeNonEmptyDirectory ( 1 , 10 , 2 , dir , true ) ;
@@ -154,6 +161,16 @@ function removeAsync(dir) {
154161 fs . rmSync ( filePath , { force : true } ) ;
155162 }
156163
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+
157174 // Recursive removal should succeed.
158175 fs . rmSync ( dir , { recursive : true } ) ;
159176
@@ -200,6 +217,16 @@ function removeAsync(dir) {
200217 } finally {
201218 fs . rmSync ( filePath , { force : true } ) ;
202219 }
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+ }
203230} ) ( ) . then ( common . mustCall ( ) ) ;
204231
205232// Test input validation.
0 commit comments