From 232d2916ac5e44db55c2ffbd2f3b37ad70037b7b Mon Sep 17 00:00:00 2001 From: Koichi ITO Date: Tue, 11 Oct 2022 05:02:22 +0900 Subject: [PATCH] chore: suppress a Node.js deprecation warning (#16398) Follow up https://github.com/nodejs/node/pull/37302. This PR suppress the following Node.js warning. ```console % node -v v18.10.0 % cd path/to/eslint % node Makefile mocha Running unit tests (snip) (node:63796) [DEP0147] DeprecationWarning: In future versions of Node.js, fs.rmdir(path, { recursive: true }) will be removed. Use fs.rm(path, { recursive: true }) instead (Use `node --trace-deprecation ...` to show where the warning was created) ``` And added compatibility condition to prevent the following error when using Node.js 14.13.1 or lower. ```console % node -v v14.13.1 % npx mocha tests/lib/eslint/flat-eslint.js (snip) 1) FlatESLint lintFiles() multiple processors "after each" hook for "should lint only JavaScript blocks.": TypeError: fsp.rm is not a function ``` --- tests/lib/eslint/flat-eslint.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/tests/lib/eslint/flat-eslint.js b/tests/lib/eslint/flat-eslint.js index f3f8b06dc01..6db10be8b23 100644 --- a/tests/lib/eslint/flat-eslint.js +++ b/tests/lib/eslint/flat-eslint.js @@ -2607,7 +2607,17 @@ describe("FlatESLint", () => { let id; beforeEach(() => (id = Date.now().toString())); - afterEach(async () => fsp.rmdir(root, { recursive: true, force: true })); + + /* + * `fs.rmdir(path, { recursive: true })` is deprecated and will be removed. + * Use `fs.rm(path, { recursive: true })` instead. + * When supporting Node.js 14.14.0+, the compatibility condition can be removed for `fs.rmdir`. + */ + if (typeof fsp.rm === "function") { + afterEach(async () => fsp.rm(root, { recursive: true, force: true })); + } else { + afterEach(async () => fsp.rmdir(root, { recursive: true, force: true })); + } it("should lint only JavaScript blocks.", async () => { const teardown = createCustomTeardown({