mirror of
https://github.com/denoland/deno.git
synced 2024-11-26 16:09:27 -05:00
a21a5ad2fa
Resolves #1705 This PR adds the Deno APIs as a global namespace named `Deno`. For backwards compatibility, the ability to `import * from "deno"` is preserved. I have tried to convert every test and internal code the references the module to use the namespace instead, but because I didn't break compatibility I am not sure. On the REPL, `deno` no longer exists, replaced only with `Deno` to align with the regular runtime. The runtime type library includes both the namespace and module. This means it duplicates the whole type information. When we remove the functionality from the runtime, it will be a one line change to the library generator to remove the module definition from the type library. I marked a `TODO` in a couple places where to remove the `"deno"` module, but there are additional places I know I didn't mark.
43 lines
1.5 KiB
TypeScript
43 lines
1.5 KiB
TypeScript
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
|
|
import { test, testPerm, assert } from "./test_util.ts";
|
|
|
|
test(async function metrics() {
|
|
const m1 = Deno.metrics();
|
|
assert(m1.opsDispatched > 0);
|
|
assert(m1.opsCompleted > 0);
|
|
assert(m1.bytesSentControl > 0);
|
|
assert(m1.bytesSentData >= 0);
|
|
assert(m1.bytesReceived > 0);
|
|
|
|
// Write to stdout to ensure a "data" message gets sent instead of just
|
|
// control messages.
|
|
const dataMsg = new Uint8Array([41, 42, 43]);
|
|
await Deno.stdout.write(dataMsg);
|
|
|
|
const m2 = Deno.metrics();
|
|
assert(m2.opsDispatched > m1.opsDispatched);
|
|
assert(m2.opsCompleted > m1.opsCompleted);
|
|
assert(m2.bytesSentControl > m1.bytesSentControl);
|
|
assert(m2.bytesSentData >= m1.bytesSentData + dataMsg.byteLength);
|
|
assert(m2.bytesReceived > m1.bytesReceived);
|
|
});
|
|
|
|
testPerm({ write: true }, function metricsUpdatedIfNoResponseSync() {
|
|
const filename = Deno.makeTempDirSync() + "/test.txt";
|
|
|
|
const data = new Uint8Array([41, 42, 43]);
|
|
Deno.writeFileSync(filename, data, { perm: 0o666 });
|
|
|
|
const metrics = Deno.metrics();
|
|
assert(metrics.opsDispatched === metrics.opsCompleted);
|
|
});
|
|
|
|
testPerm({ write: true }, async function metricsUpdatedIfNoResponseAsync() {
|
|
const filename = Deno.makeTempDirSync() + "/test.txt";
|
|
|
|
const data = new Uint8Array([41, 42, 43]);
|
|
await Deno.writeFile(filename, data, { perm: 0o666 });
|
|
|
|
const metrics = Deno.metrics();
|
|
assert(metrics.opsDispatched === metrics.opsCompleted);
|
|
});
|