@@ -5,6 +5,7 @@ const tmpdir = require('../common/tmpdir');
55const assert = require ( 'assert' ) ;
66const fs = require ( 'fs' ) ;
77const path = require ( 'path' ) ;
8+ const { pathToFileURL } = require ( 'url' ) ;
89const { execSync } = require ( 'child_process' ) ;
910
1011const { validateRmOptionsSync } = require ( 'internal/fs/utils' ) ;
@@ -97,6 +98,11 @@ function removeAsync(dir) {
9798 makeNonEmptyDirectory ( 2 , 10 , 2 , dir , false ) ;
9899 removeAsync ( dir ) ;
99100
101+ // Same test using URL instead of a path
102+ dir = nextDirPath ( ) ;
103+ makeNonEmptyDirectory ( 2 , 10 , 2 , dir , false ) ;
104+ removeAsync ( pathToFileURL ( dir ) ) ;
105+
100106 // Create a flat folder including symlinks
101107 dir = nextDirPath ( ) ;
102108 makeNonEmptyDirectory ( 1 , 10 , 2 , dir , true ) ;
@@ -156,6 +162,16 @@ function removeAsync(dir) {
156162 fs . rmSync ( filePath , { force : true } ) ;
157163 }
158164
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+
159175 // Recursive removal should succeed.
160176 fs . rmSync ( dir , { recursive : true } ) ;
161177
@@ -202,6 +218,16 @@ function removeAsync(dir) {
202218 } finally {
203219 fs . rmSync ( filePath , { force : true } ) ;
204220 }
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+ }
205231} ) ( ) . then ( common . mustCall ( ) ) ;
206232
207233// Test input validation.
0 commit comments