From 0c5e8ed6510b5b19b739877c017108bcd8690f57 Mon Sep 17 00:00:00 2001 From: Ian Sutherland Date: Fri, 16 Oct 2020 11:50:00 -0600 Subject: [PATCH] test: add additional deprecation warning tests for rmdir recursive PR-URL: https://github.com/nodejs/node/pull/35683 Reviewed-By: Rich Trott Reviewed-By: Ben Coe Reviewed-By: Antoine du Hamel --- ...fs-rmdir-recursive-sync-warns-not-found.js | 19 +++++++++++++++++ ...t-fs-rmdir-recursive-sync-warns-on-file.js | 21 +++++++++++++++++++ ...test-fs-rmdir-recursive-warns-not-found.js | 1 - .../test-fs-rmdir-recursive-warns-on-file.js | 2 +- 4 files changed, 41 insertions(+), 2 deletions(-) create mode 100644 test/parallel/test-fs-rmdir-recursive-sync-warns-not-found.js create mode 100644 test/parallel/test-fs-rmdir-recursive-sync-warns-on-file.js 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()); }