summaryrefslogtreecommitdiff
path: root/std/node
diff options
context:
space:
mode:
authorecyrbe <ecyrbe@gmail.com>2020-02-23 00:46:52 +0100
committerGitHub <noreply@github.com>2020-02-22 18:46:52 -0500
commitfb98556d56d0defa325fab1296077627cce31aab (patch)
treec5589b7cdc21d56d440ab13a1abc527cf072b103 /std/node
parentc34d96d86557d434bdf124063e4eec4662067c1e (diff)
feat(std/node): add os.loadavg() (#4075)
Diffstat (limited to 'std/node')
-rw-r--r--std/node/os.ts4
-rw-r--r--std/node/os_test.ts29
2 files changed, 8 insertions, 25 deletions
diff --git a/std/node/os.ts b/std/node/os.ts
index 8facde292..51e5bbd93 100644
--- a/std/node/os.ts
+++ b/std/node/os.ts
@@ -133,12 +133,12 @@ export function hostname(): string {
return Deno.hostname();
}
-/** Not yet implemented */
+/** Returns an array containing the 1, 5, and 15 minute load averages */
export function loadavg(): number[] {
if (Deno.build.os == "win") {
return [0, 0, 0];
}
- notImplemented(SEE_GITHUB_ISSUE);
+ return Deno.loadavg();
}
/** Not yet implemented */
diff --git a/std/node/os_test.ts b/std/node/os_test.ts
index f13589a4b..f825ae192 100644
--- a/std/node/os_test.ts
+++ b/std/node/os_test.ts
@@ -1,10 +1,5 @@
const { test } = Deno;
-import {
- assert,
- assertThrows,
- assertEquals,
- AssertionError
-} from "../testing/asserts.ts";
+import { assert, assertThrows, assertEquals } from "../testing/asserts.ts";
import * as os from "./os.ts";
test({
@@ -168,26 +163,14 @@ test({
}
});
-// Method is currently implemented correctly for windows but not for any other os
test({
name: "Load average is an array of 3 numbers",
fn() {
- try {
- const result = os.loadavg();
- assert(result.length == 3);
- assertEquals(typeof result[0], "number");
- assertEquals(typeof result[1], "number");
- assertEquals(typeof result[2], "number");
- } catch (error) {
- if (!(Object.getPrototypeOf(error) === Error.prototype)) {
- const errMsg = `Unexpected error class: ${error.name}`;
- throw new AssertionError(errMsg);
- } else if (!error.message.includes("Not implemented")) {
- throw new AssertionError(
- "Expected this error to contain 'Not implemented'"
- );
- }
- }
+ const result = os.loadavg();
+ assert(result.length == 3);
+ assertEquals(typeof result[0], "number");
+ assertEquals(typeof result[1], "number");
+ assertEquals(typeof result[2], "number");
}
});