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.
42 lines
1.3 KiB
TypeScript
42 lines
1.3 KiB
TypeScript
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
|
|
import { test, testPerm, assertEqual } from "./test_util.ts";
|
|
|
|
test(function resourcesStdio() {
|
|
const res = Deno.resources();
|
|
|
|
assertEqual(res[0], "stdin");
|
|
assertEqual(res[1], "stdout");
|
|
assertEqual(res[2], "stderr");
|
|
});
|
|
|
|
testPerm({ net: true }, async function resourcesNet() {
|
|
const addr = "127.0.0.1:4501";
|
|
const listener = Deno.listen("tcp", addr);
|
|
|
|
const dialerConn = await Deno.dial("tcp", addr);
|
|
const listenerConn = await listener.accept();
|
|
|
|
const res = Deno.resources();
|
|
assertEqual(Object.values(res).filter(r => r === "tcpListener").length, 1);
|
|
assertEqual(Object.values(res).filter(r => r === "tcpStream").length, 2);
|
|
|
|
listenerConn.close();
|
|
dialerConn.close();
|
|
listener.close();
|
|
});
|
|
|
|
testPerm({ read: true }, async function resourcesFile() {
|
|
const resourcesBefore = Deno.resources();
|
|
await Deno.open("tests/hello.txt");
|
|
const resourcesAfter = Deno.resources();
|
|
|
|
// check that exactly one new resource (file) was added
|
|
assertEqual(
|
|
Object.keys(resourcesAfter).length,
|
|
Object.keys(resourcesBefore).length + 1
|
|
);
|
|
const newRid = Object.keys(resourcesAfter).find(rid => {
|
|
return !resourcesBefore.hasOwnProperty(rid);
|
|
});
|
|
assertEqual(resourcesAfter[newRid], "fsFile");
|
|
});
|