diff --git a/test/parallel/test-fs-rmdir-recursive-sync-warns-not-found.js b/test/parallel/test-fs-rmdir-recursive-sync-warns-not-found.js new file mode 100644 index 00000000000000..449ae0b448b353 --- /dev/null +++ b/test/parallel/test-fs-rmdir-recursive-sync-warns-not-found.js @@ -0,0 +1,19 @@ +'use strict'; +const common = require('../common'); +const tmpdir = require('../common/tmpdir'); +const fs = require('fs'); +const path = require('path'); + +tmpdir.refresh(); + +{ + // Should warn when trying to delete a nonexistent path + common.expectWarning( + 'DeprecationWarning', + 'In future versions of Node.js, fs.rmdir(path, { recursive: true }) ' + + 'will throw if path does not exist or is a file. Use fs.rm(path, ' + + '{ recursive: true, force: true }) instead', + 'DEP0147' + ); + fs.rmdirSync(path.join(tmpdir.path, 'noexist.txt'), { recursive: true }); +} diff --git a/test/parallel/test-fs-rmdir-recursive-sync-warns-on-file.js b/test/parallel/test-fs-rmdir-recursive-sync-warns-on-file.js new file mode 100644 index 00000000000000..96b9875416f962 --- /dev/null +++ b/test/parallel/test-fs-rmdir-recursive-sync-warns-on-file.js @@ -0,0 +1,21 @@ +'use strict'; +const common = require('../common'); +const tmpdir = require('../common/tmpdir'); +const fs = require('fs'); +const path = require('path'); + +tmpdir.refresh(); + +{ + // Should warn when trying to delete a file + common.expectWarning( + 'DeprecationWarning', + 'In future versions of Node.js, fs.rmdir(path, { recursive: true }) ' + + 'will throw if path does not exist or is a file. Use fs.rm(path, ' + + '{ recursive: true, force: true }) instead', + 'DEP0147' + ); + const filePath = path.join(tmpdir.path, 'rmdir-recursive.txt'); + fs.writeFileSync(filePath, ''); + fs.rmdirSync(filePath, { recursive: true }); +} diff --git a/test/parallel/test-fs-rmdir-recursive-warns-not-found.js b/test/parallel/test-fs-rmdir-recursive-warns-not-found.js index c87a20956041ce..9f733b47d156ba 100644 --- a/test/parallel/test-fs-rmdir-recursive-warns-not-found.js +++ b/test/parallel/test-fs-rmdir-recursive-warns-not-found.js @@ -6,7 +6,6 @@ const path = require('path'); tmpdir.refresh(); - { // Should warn when trying to delete a nonexistent path common.expectWarning( diff --git a/test/parallel/test-fs-rmdir-recursive-warns-on-file.js b/test/parallel/test-fs-rmdir-recursive-warns-on-file.js index 96b9875416f962..0d8e2e61bcbe85 100644 --- a/test/parallel/test-fs-rmdir-recursive-warns-on-file.js +++ b/test/parallel/test-fs-rmdir-recursive-warns-on-file.js @@ -17,5 +17,5 @@ tmpdir.refresh(); ); const filePath = path.join(tmpdir.path, 'rmdir-recursive.txt'); fs.writeFileSync(filePath, ''); - fs.rmdirSync(filePath, { recursive: true }); + fs.rmdir(filePath, { recursive: true }, common.mustSucceed()); }