Skip to content

Commit

Permalink
feat(std/node): add os.totalmem, os.freemem (denoland/deno#8317)
Browse files Browse the repository at this point in the history
  • Loading branch information
jopemachine committed Nov 19, 2020
1 parent b2d50ff commit d2c4ea1
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 18 deletions.
8 changes: 4 additions & 4 deletions node/_os.ts
Expand Up @@ -123,9 +123,9 @@ export function endianness(): "BE" | "LE" {
return new Int16Array(buffer)[0] === 256 ? "LE" : "BE";
}

/** Not yet implemented */
/** Return free memory amount */
export function freemem(): number {
notImplemented(SEE_GITHUB_ISSUE);
return Deno.systemMemoryInfo().free;
}

/** Not yet implemented */
Expand Down Expand Up @@ -185,9 +185,9 @@ export function tmpdir(): string | null {
notImplemented(SEE_GITHUB_ISSUE);
}

/** Not yet implemented */
/** Return total physical memory amount */
export function totalmem(): number {
notImplemented(SEE_GITHUB_ISSUE);
return Deno.systemMemoryInfo().total;
}

/** Not yet implemented */
Expand Down
28 changes: 14 additions & 14 deletions node/os_test.ts
Expand Up @@ -200,6 +200,20 @@ Deno.test({
},
});

Deno.test({
name: "Total memory amount should be greater than 0",
fn() {
assert(os.totalmem() > 0);
},
});

Deno.test({
name: "Free memory amount should be greater than 0",
fn() {
assert(os.freemem() > 0);
},
});

Deno.test({
name: "APIs not yet implemented",
fn() {
Expand All @@ -210,13 +224,6 @@ Deno.test({
Error,
"Not implemented",
);
assertThrows(
() => {
os.freemem();
},
Error,
"Not implemented",
);
assertThrows(
() => {
os.getPriority();
Expand All @@ -238,13 +245,6 @@ Deno.test({
Error,
"Not implemented",
);
assertThrows(
() => {
os.totalmem();
},
Error,
"Not implemented",
);
assertThrows(
() => {
os.type();
Expand Down

0 comments on commit d2c4ea1

Please sign in to comment.