summaryrefslogtreecommitdiff
path: root/js/net_test.ts
diff options
context:
space:
mode:
authorKitson Kelly <me@kitsonkelly.com>2019-02-13 02:08:56 +1100
committerRyan Dahl <ry@tinyclouds.org>2019-02-12 10:08:56 -0500
commita21a5ad2fa4dcbad58fe63c298c69f8607705bf4 (patch)
tree03e0092f46813ffdf84f53ab58f71b8a0276207e /js/net_test.ts
parent1e5e091cb074896c7550b1b6f802582f12629048 (diff)
Add Deno global namespace (#1748)
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.
Diffstat (limited to 'js/net_test.ts')
-rw-r--r--js/net_test.ts38
1 files changed, 18 insertions, 20 deletions
diff --git a/js/net_test.ts b/js/net_test.ts
index 90a6a3753..f20bb9ddb 100644
--- a/js/net_test.ts
+++ b/js/net_test.ts
@@ -1,15 +1,13 @@
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
-import * as deno from "deno";
import { testPerm, assert, assertEqual } from "./test_util.ts";
-import { deferred } from "deno";
testPerm({ net: true }, function netListenClose() {
- const listener = deno.listen("tcp", "127.0.0.1:4500");
+ const listener = Deno.listen("tcp", "127.0.0.1:4500");
listener.close();
});
testPerm({ net: true }, async function netCloseWhileAccept() {
- const listener = deno.listen("tcp", ":4501");
+ const listener = Deno.listen("tcp", ":4501");
const p = listener.accept();
listener.close();
let err;
@@ -19,15 +17,15 @@ testPerm({ net: true }, async function netCloseWhileAccept() {
err = e;
}
assert(!!err);
- assertEqual(err.kind, deno.ErrorKind.Other);
+ assertEqual(err.kind, Deno.ErrorKind.Other);
assertEqual(err.message, "Listener has been closed");
});
testPerm({ net: true }, async function netConcurrentAccept() {
- const listener = deno.listen("tcp", ":4502");
+ const listener = Deno.listen("tcp", ":4502");
let acceptErrCount = 0;
const checkErr = e => {
- assertEqual(e.kind, deno.ErrorKind.Other);
+ assertEqual(e.kind, Deno.ErrorKind.Other);
if (e.message === "Listener has been closed") {
assertEqual(acceptErrCount, 1);
} else if (e.message === "Another accept task is ongoing") {
@@ -45,12 +43,12 @@ testPerm({ net: true }, async function netConcurrentAccept() {
});
testPerm({ net: true }, async function netDialListen() {
- const listener = deno.listen("tcp", ":4500");
+ const listener = Deno.listen("tcp", ":4500");
listener.accept().then(async conn => {
await conn.write(new Uint8Array([1, 2, 3]));
conn.close();
});
- const conn = await deno.dial("tcp", "127.0.0.1:4500");
+ const conn = await Deno.dial("tcp", "127.0.0.1:4500");
const buf = new Uint8Array(1024);
const readResult = await conn.read(buf);
assertEqual(3, readResult.nread);
@@ -75,7 +73,7 @@ testPerm({ net: true }, async function netDialListen() {
/* TODO Fix broken test.
testPerm({ net: true }, async function netCloseReadSuccess() {
const addr = "127.0.0.1:4500";
- const listener = deno.listen("tcp", addr);
+ const listener = Deno.listen("tcp", addr);
const closeDeferred = deferred();
const closeReadDeferred = deferred();
listener.accept().then(async conn => {
@@ -90,7 +88,7 @@ testPerm({ net: true }, async function netCloseReadSuccess() {
conn.close();
closeDeferred.resolve();
});
- const conn = await deno.dial("tcp", addr);
+ const conn = await Deno.dial("tcp", addr);
conn.closeRead(); // closing read
closeReadDeferred.resolve();
const buf = new Uint8Array(1024);
@@ -108,14 +106,14 @@ testPerm({ net: true }, async function netCloseReadSuccess() {
/* TODO Fix broken test.
testPerm({ net: true }, async function netDoubleCloseRead() {
const addr = "127.0.0.1:4500";
- const listener = deno.listen("tcp", addr);
+ const listener = Deno.listen("tcp", addr);
const closeDeferred = deferred();
listener.accept().then(async conn => {
await conn.write(new Uint8Array([1, 2, 3]));
await closeDeferred.promise;
conn.close();
});
- const conn = await deno.dial("tcp", addr);
+ const conn = await Deno.dial("tcp", addr);
conn.closeRead(); // closing read
let err;
try {
@@ -125,7 +123,7 @@ testPerm({ net: true }, async function netDoubleCloseRead() {
err = e;
}
assert(!!err);
- assertEqual(err.kind, deno.ErrorKind.NotConnected);
+ assertEqual(err.kind, Deno.ErrorKind.NotConnected);
assertEqual(err.name, "NotConnected");
closeDeferred.resolve();
listener.close();
@@ -136,14 +134,14 @@ testPerm({ net: true }, async function netDoubleCloseRead() {
/* TODO Fix broken test.
testPerm({ net: true }, async function netCloseWriteSuccess() {
const addr = "127.0.0.1:4500";
- const listener = deno.listen("tcp", addr);
+ const listener = Deno.listen("tcp", addr);
const closeDeferred = deferred();
listener.accept().then(async conn => {
await conn.write(new Uint8Array([1, 2, 3]));
await closeDeferred.promise;
conn.close();
});
- const conn = await deno.dial("tcp", addr);
+ const conn = await Deno.dial("tcp", addr);
conn.closeWrite(); // closing write
const buf = new Uint8Array(1024);
// Check read not impacted
@@ -160,7 +158,7 @@ testPerm({ net: true }, async function netCloseWriteSuccess() {
err = e;
}
assert(!!err);
- assertEqual(err.kind, deno.ErrorKind.BrokenPipe);
+ assertEqual(err.kind, Deno.ErrorKind.BrokenPipe);
assertEqual(err.name, "BrokenPipe");
closeDeferred.resolve();
listener.close();
@@ -171,13 +169,13 @@ testPerm({ net: true }, async function netCloseWriteSuccess() {
/* TODO Fix broken test.
testPerm({ net: true }, async function netDoubleCloseWrite() {
const addr = "127.0.0.1:4500";
- const listener = deno.listen("tcp", addr);
+ const listener = Deno.listen("tcp", addr);
const closeDeferred = deferred();
listener.accept().then(async conn => {
await closeDeferred.promise;
conn.close();
});
- const conn = await deno.dial("tcp", addr);
+ const conn = await Deno.dial("tcp", addr);
conn.closeWrite(); // closing write
let err;
try {
@@ -187,7 +185,7 @@ testPerm({ net: true }, async function netDoubleCloseWrite() {
err = e;
}
assert(!!err);
- assertEqual(err.kind, deno.ErrorKind.NotConnected);
+ assertEqual(err.kind, Deno.ErrorKind.NotConnected);
assertEqual(err.name, "NotConnected");
closeDeferred.resolve();
listener.close();