From dda63287456aae5cd4f7f428e23b52cb8c0005e5 Mon Sep 17 00:00:00 2001 From: Yoshiya Hinosawa Date: Thu, 5 Sep 2024 21:21:29 +0900 Subject: [PATCH] fix(ext/node): stub `process.cpuUsage()` (#25462) closes #23401 --- ext/node/polyfills/process.ts | 8 ++++++++ tests/unit_node/process_test.ts | 6 ++++++ 2 files changed, 14 insertions(+) diff --git a/ext/node/polyfills/process.ts b/ext/node/polyfills/process.ts index f09d7ceede..f84255814e 100644 --- a/ext/node/polyfills/process.ts +++ b/ext/node/polyfills/process.ts @@ -430,6 +430,14 @@ Process.prototype.config = { }, }; +Process.prototype.cpuUsage = function () { + warnNotImplemented("process.cpuUsage()"); + return { + user: 0, + system: 0, + }; +}; + /** https://nodejs.org/api/process.html#process_process_cwd */ Process.prototype.cwd = cwd; diff --git a/tests/unit_node/process_test.ts b/tests/unit_node/process_test.ts index 962877935b..b3db9753e2 100644 --- a/tests/unit_node/process_test.ts +++ b/tests/unit_node/process_test.ts @@ -1131,3 +1131,9 @@ Deno.test(function importedExecArgvTest() { Deno.test(function importedExecPathTest() { assertEquals(importedExecPath, Deno.execPath()); }); + +Deno.test("process.cpuUsage()", () => { + const cpuUsage = process.cpuUsage(); + assert(typeof cpuUsage.user === "number"); + assert(typeof cpuUsage.system === "number"); +});