diff options
author | Ian Sutherland <ian@iansutherland.ca> | 2020-10-16 20:50:00 +0300 |
---|---|---|
committer | Antoine du Hamel <duhamelantoine1995@gmail.com> | 2020-10-24 17:18:07 +0300 |
commit | c5b9b5b28ff3804811b50df12459ff134887a82b (patch) | |
tree | 8e2e07832075bf8ec02e9a4f1a25054a9ab1e7dd | |
parent | 440edaa6881bc6e4966558a10152b41838f9f28a (diff) |
test: add additional deprecation warning tests for rmdir recursive
PR-URL: https://github.com/nodejs/node/pull/35683
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Ben Coe <bencoe@gmail.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
4 files changed, 41 insertions, 2 deletions
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 00000000000..449ae0b448b --- /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 00000000000..96b9875416f --- /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 c87a2095604..9f733b47d15 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 96b9875416f..0d8e2e61bcb 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()); } |