summaryrefslogtreecommitdiff
path: root/js
diff options
context:
space:
mode:
Diffstat (limited to 'js')
-rw-r--r--js/compiler_test.ts2
-rw-r--r--js/console.ts4
-rw-r--r--js/console_test.ts4
-rw-r--r--js/deno.ts7
-rw-r--r--js/dom_types.ts7
-rw-r--r--js/fetch_test.ts2
-rw-r--r--js/file.ts6
-rw-r--r--js/form_data_test.ts2
-rw-r--r--js/globals.ts10
-rw-r--r--js/libdeno.ts1
-rw-r--r--js/mixins/dom_iterable.ts1
-rw-r--r--js/mixins/dom_iterable_test.ts2
-rw-r--r--js/net_test.ts2
-rw-r--r--js/runner_test.ts2
-rw-r--r--js/testing/testing.ts62
-rw-r--r--js/testing/testing_test.ts (renamed from js/testing/util_test.ts)36
-rw-r--r--js/testing/util.ts74
-rw-r--r--js/unit_tests.ts10
-rw-r--r--js/util.ts6
19 files changed, 124 insertions, 116 deletions
diff --git a/js/compiler_test.ts b/js/compiler_test.ts
index 45c7f775c..8afe64d7f 100644
--- a/js/compiler_test.ts
+++ b/js/compiler_test.ts
@@ -1,5 +1,5 @@
// Copyright 2018 the Deno authors. All rights reserved. MIT license.
-import { test, assert, assertEqual } from "./test_util";
+import { test, assert, assertEqual } from "./test_util.ts";
import * as deno from "deno";
import * as ts from "typescript";
diff --git a/js/console.ts b/js/console.ts
index ca08330eb..396def545 100644
--- a/js/console.ts
+++ b/js/console.ts
@@ -322,7 +322,7 @@ function stringifyWithQuotes(
}
}
-// @internal
+/** TODO Do not expose this from "deno" namespace. */
export function stringifyArgs(
// tslint:disable-next-line:no-any
args: any[],
@@ -354,8 +354,8 @@ type PrintFunc = (x: string, isErr?: boolean) => void;
const countMap = new Map<string, number>();
const timerMap = new Map<string, number>();
+/** TODO Do not expose this from "deno". */
export class Console {
- // @internal
constructor(private printFunc: PrintFunc) {}
/** Writes the arguments to stdout */
diff --git a/js/console_test.ts b/js/console_test.ts
index b0fb9b5c4..e3349054b 100644
--- a/js/console_test.ts
+++ b/js/console_test.ts
@@ -1,9 +1,7 @@
// Copyright 2018 the Deno authors. All rights reserved. MIT license.
+import { Console, libdeno, stringifyArgs, inspect } from "deno";
import { test, assert, assertEqual } from "./test_util.ts";
-import { stringifyArgs, inspect } from "./console.ts";
-import { Console } from "./console.ts";
-import { libdeno } from "./libdeno";
const console = new Console(libdeno.print);
// tslint:disable-next-line:no-any
diff --git a/js/deno.ts b/js/deno.ts
index a03e41fe3..86a6990d6 100644
--- a/js/deno.ts
+++ b/js/deno.ts
@@ -55,6 +55,13 @@ export { run, RunOptions, Process, ProcessStatus } from "./process";
export { inspect } from "./console";
export const args: string[] = [];
+// TODO Don't expose Console nor stringifyArgs.
+export { Console, stringifyArgs } from "./console";
+// TODO Don't expose DomIterableMixin.
+export { DomIterableMixin } from "./mixins/dom_iterable";
+// TODO Don't expose deferred.
+export { deferred } from "./util";
+
// Provide the compiler API in an obfuscated way
import * as compiler from "./compiler";
// @internal
diff --git a/js/dom_types.ts b/js/dom_types.ts
index a033dc376..4bfb3e041 100644
--- a/js/dom_types.ts
+++ b/js/dom_types.ts
@@ -36,7 +36,7 @@ type ReferrerPolicy =
| "origin-when-cross-origin"
| "unsafe-url";
export type BlobPart = BufferSource | Blob | string;
-export type FormDataEntryValue = File | string;
+export type FormDataEntryValue = DomFile | string;
export type EventListenerOrEventListenerObject =
| EventListener
| EventListenerObject;
@@ -175,7 +175,10 @@ interface Event {
readonly NONE: number;
}
-export interface File extends Blob {
+/* TODO(ry) Re-expose this interface. There is currently some interference
+ * between deno's File and this one.
+ */
+export interface DomFile extends Blob {
readonly lastModified: number;
readonly name: string;
}
diff --git a/js/fetch_test.ts b/js/fetch_test.ts
index c631f2517..773b2eebd 100644
--- a/js/fetch_test.ts
+++ b/js/fetch_test.ts
@@ -66,8 +66,10 @@ testPerm({ net: true }, async function fetchMultipartFormDataSuccess() {
assert(formData.has("field_1"));
assertEqual(formData.get("field_1").toString(), "value_1 \r\n");
assert(formData.has("field_2"));
+ /* TODO(ry) Re-enable this test once we bring back the global File type.
const file = formData.get("field_2") as File;
assertEqual(file.name, "file.js");
+ */
// Currently we cannot read from file...
});
diff --git a/js/file.ts b/js/file.ts
index 8496d6edb..6b5a4fbd0 100644
--- a/js/file.ts
+++ b/js/file.ts
@@ -1,8 +1,12 @@
// Copyright 2018 the Deno authors. All rights reserved. MIT license.
+// TODO Rename this file to js/dom_file.ts it's currently too similarly named to
+// js/files.ts
+
import * as domTypes from "./dom_types";
import * as blob from "./blob";
-export class DenoFile extends blob.DenoBlob implements domTypes.File {
+// TODO Rename this to DomFileImpl
+export class DenoFile extends blob.DenoBlob implements domTypes.DomFile {
lastModified: number;
name: string;
diff --git a/js/form_data_test.ts b/js/form_data_test.ts
index 04a05acaf..fef61542e 100644
--- a/js/form_data_test.ts
+++ b/js/form_data_test.ts
@@ -69,10 +69,12 @@ test(function formDataSetEmptyBlobSuccess() {
const formData = new FormData();
formData.set("a", new Blob([]), "blank.txt");
const file = formData.get("a");
+ /* TODO Fix this test.
assert(file instanceof File);
if (typeof file !== "string") {
assertEqual(file.name, "blank.txt");
}
+ */
});
test(function formDataParamsForEachSuccess() {
diff --git a/js/globals.ts b/js/globals.ts
index ac66f77e6..efa377e9b 100644
--- a/js/globals.ts
+++ b/js/globals.ts
@@ -10,7 +10,6 @@
import * as blob from "./blob";
import * as consoleTypes from "./console";
import * as domTypes from "./dom_types";
-import * as file from "./file";
import * as formData from "./form_data";
import * as fetchTypes from "./fetch";
import * as headers from "./headers";
@@ -55,8 +54,13 @@ window.setInterval = timers.setInterval;
// being used, which it cannot statically determine within this module.
window.Blob = blob.DenoBlob;
export type Blob = blob.DenoBlob;
-window.File = file.DenoFile;
-export type File = file.DenoFile;
+
+// TODO(ry) Do not export a class implementing the DOM, export the DOM
+// interface. See this comment for implementation hint:
+// https://github.com/denoland/deno/pull/1396#discussion_r243711502
+// window.File = file.DenoFile;
+// export type File = file.DenoFile;
+
window.URL = url.URL;
export type URL = url.URL;
window.URLSearchParams = urlSearchParams.URLSearchParams;
diff --git a/js/libdeno.ts b/js/libdeno.ts
index 5448165a1..e67a021c7 100644
--- a/js/libdeno.ts
+++ b/js/libdeno.ts
@@ -41,5 +41,4 @@ interface Libdeno {
}
const window = globalEval("this");
-// @internal
export const libdeno = window.libdeno as Libdeno;
diff --git a/js/mixins/dom_iterable.ts b/js/mixins/dom_iterable.ts
index eb5d08d13..2daf80b71 100644
--- a/js/mixins/dom_iterable.ts
+++ b/js/mixins/dom_iterable.ts
@@ -11,6 +11,7 @@ type Constructor<T = {}> = new (...args: any[]) => T;
/** Mixes in a DOM iterable methods into a base class, assumes that there is
* a private data iterable that is part of the base class, located at
* `[dataSymbol]`.
+ * TODO Don't expose DomIterableMixin from "deno" namespace.
*/
export function DomIterableMixin<K, V, TBase extends Constructor>(
// tslint:disable-next-line:variable-name
diff --git a/js/mixins/dom_iterable_test.ts b/js/mixins/dom_iterable_test.ts
index a4791c1b8..ad14dbe60 100644
--- a/js/mixins/dom_iterable_test.ts
+++ b/js/mixins/dom_iterable_test.ts
@@ -1,6 +1,6 @@
// Copyright 2018 the Deno authors. All rights reserved. MIT license.
import { test, assert, assertEqual } from "../test_util.ts";
-import { DomIterableMixin } from "./dom_iterable.ts";
+import { DomIterableMixin } from "deno";
function setup() {
const dataSymbol = Symbol("data symbol");
diff --git a/js/net_test.ts b/js/net_test.ts
index 999cea9b6..bf48b3448 100644
--- a/js/net_test.ts
+++ b/js/net_test.ts
@@ -1,7 +1,7 @@
// Copyright 2018 the Deno authors. All rights reserved. MIT license.
import * as deno from "deno";
import { testPerm, assert, assertEqual } from "./test_util.ts";
-import { deferred } from "./util.ts";
+import { deferred } from "deno";
testPerm({ net: true }, function netListenClose() {
const listener = deno.listen("tcp", "127.0.0.1:4500");
diff --git a/js/runner_test.ts b/js/runner_test.ts
index adfb8bc58..5444f31f9 100644
--- a/js/runner_test.ts
+++ b/js/runner_test.ts
@@ -1,4 +1,4 @@
-import { test, assert, assertEqual } from "./test_util";
+import { test, assert, assertEqual } from "./test_util.ts";
import * as deno from "deno";
// tslint:disable-next-line:no-any
diff --git a/js/testing/testing.ts b/js/testing/testing.ts
index 437cb0f38..4cf7ea27f 100644
--- a/js/testing/testing.ts
+++ b/js/testing/testing.ts
@@ -13,7 +13,67 @@
limitations under the License.
*/
-export { assert, assertEqual, equal } from "./util";
+// Do not add imports in this file in order to be compatible with Node.
+
+export function assertEqual(actual: unknown, expected: unknown, msg?: string) {
+ if (!equal(actual, expected)) {
+ let actualString: string;
+ let expectedString: string;
+ try {
+ actualString = String(actual);
+ } catch (e) {
+ actualString = "[Cannot display]";
+ }
+ try {
+ expectedString = String(expected);
+ } catch (e) {
+ expectedString = "[Cannot display]";
+ }
+ console.error(
+ "assertEqual failed. actual =",
+ actualString,
+ "expected =",
+ expectedString
+ );
+ if (!msg) {
+ msg = `actual: ${actualString} expected: ${expectedString}`;
+ }
+ throw new Error(msg);
+ }
+}
+
+export function assert(expr: boolean, msg = "") {
+ if (!expr) {
+ throw new Error(msg);
+ }
+}
+
+// TODO(ry) Use unknown here for parameters types.
+// tslint:disable-next-line:no-any
+export function equal(c: any, d: any): boolean {
+ const seen = new Map();
+ return (function compare(a, b) {
+ if (Object.is(a, b)) {
+ return true;
+ }
+ if (a && typeof a === "object" && b && typeof b === "object") {
+ if (seen.get(a) === b) {
+ return true;
+ }
+ if (Object.keys(a).length !== Object.keys(b).length) {
+ return false;
+ }
+ for (const key in { ...a, ...b }) {
+ if (!compare(a[key], b[key])) {
+ return false;
+ }
+ }
+ seen.set(a, b);
+ return true;
+ }
+ return false;
+ })(c, d);
+}
export type TestFunction = () => void | Promise<void>;
diff --git a/js/testing/util_test.ts b/js/testing/testing_test.ts
index 25f0b2c45..9b32884eb 100644
--- a/js/testing/util_test.ts
+++ b/js/testing/testing_test.ts
@@ -13,43 +13,41 @@
limitations under the License.
*/
-import { test } from "./testing.ts";
-import { assert } from "./util.ts";
-import * as util from "./util.ts";
+import { test, assert, assertEqual, equal } from "./testing.ts";
-test(function util_equal() {
- assert(util.equal("world", "world"));
- assert(!util.equal("hello", "world"));
- assert(util.equal(5, 5));
- assert(!util.equal(5, 6));
- assert(util.equal(NaN, NaN));
- assert(util.equal({ hello: "world" }, { hello: "world" }));
- assert(!util.equal({ world: "hello" }, { hello: "world" }));
+test(function testingEqual() {
+ assert(equal("world", "world"));
+ assert(!equal("hello", "world"));
+ assert(equal(5, 5));
+ assert(!equal(5, 6));
+ assert(equal(NaN, NaN));
+ assert(equal({ hello: "world" }, { hello: "world" }));
+ assert(!equal({ world: "hello" }, { hello: "world" }));
assert(
- util.equal(
+ equal(
{ hello: "world", hi: { there: "everyone" } },
{ hello: "world", hi: { there: "everyone" } }
)
);
assert(
- !util.equal(
+ !equal(
{ hello: "world", hi: { there: "everyone" } },
{ hello: "world", hi: { there: "everyone else" } }
)
);
});
-test(function util_assertEqual() {
+test(function testingAssertEqual() {
const a = Object.create(null);
a.b = "foo";
- util.assertEqual(a, a);
+ assertEqual(a, a);
});
-test(function util_assertEqualActualUncoercable() {
+test(function testingAssertEqualActualUncoercable() {
let didThrow = false;
const a = Object.create(null);
try {
- util.assertEqual(a, "bar");
+ assertEqual(a, "bar");
} catch (e) {
didThrow = true;
console.log(e.message);
@@ -58,11 +56,11 @@ test(function util_assertEqualActualUncoercable() {
assert(didThrow);
});
-test(function util_assertEqualExpectedUncoercable() {
+test(function testingAssertEqualExpectedUncoercable() {
let didThrow = false;
const a = Object.create(null);
try {
- util.assertEqual("bar", a);
+ assertEqual("bar", a);
} catch (e) {
didThrow = true;
console.log(e.message);
diff --git a/js/testing/util.ts b/js/testing/util.ts
deleted file mode 100644
index 096b184b8..000000000
--- a/js/testing/util.ts
+++ /dev/null
@@ -1,74 +0,0 @@
-/*!
- Copyright 2018 Propel http://propel.site/. All rights reserved.
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
- */
-
-export function assertEqual(actual: unknown, expected: unknown, msg?: string) {
- if (!equal(actual, expected)) {
- let actualString: string;
- let expectedString: string;
- try {
- actualString = String(actual);
- } catch (e) {
- actualString = "[Cannot display]";
- }
- try {
- expectedString = String(expected);
- } catch (e) {
- expectedString = "[Cannot display]";
- }
- console.error(
- "assertEqual failed. actual =",
- actualString,
- "expected =",
- expectedString
- );
- if (!msg) {
- msg = `actual: ${actualString} expected: ${expectedString}`;
- }
- throw new Error(msg);
- }
-}
-
-export function assert(expr: boolean, msg = "") {
- if (!expr) {
- throw new Error(msg);
- }
-}
-
-// TODO(ry) Use unknown here for parameters types.
-// tslint:disable-next-line:no-any
-export function equal(c: any, d: any): boolean {
- const seen = new Map();
- return (function compare(a, b) {
- if (Object.is(a, b)) {
- return true;
- }
- if (a && typeof a === "object" && b && typeof b === "object") {
- if (seen.get(a) === b) {
- return true;
- }
- if (Object.keys(a).length !== Object.keys(b).length) {
- return false;
- }
- for (const key in { ...a, ...b }) {
- if (!compare(a[key], b[key])) {
- return false;
- }
- }
- seen.set(a, b);
- return true;
- }
- return false;
- })(c, d);
-}
diff --git a/js/unit_tests.ts b/js/unit_tests.ts
index 6ac071d3e..b24a156d5 100644
--- a/js/unit_tests.ts
+++ b/js/unit_tests.ts
@@ -2,16 +2,18 @@
// This test is executed as part of tools/test.py
// But it can also be run manually: ./target/debug/deno js/unit_tests.ts
-import "../website/app_test.js";
+
import "./blob_test.ts";
import "./buffer_test.ts";
import "./chmod_test.ts";
import "./compiler_test.ts";
import "./console_test.ts";
import "./copy_file_test.ts";
-import "./dir_test";
+import "./dir_test.ts";
import "./fetch_test.ts";
-import "./file_test.ts";
+// TODO The global "File" has been temporarily disabled. See the note in
+// js/globals.ts
+// import "./file_test.ts";
import "./files_test.ts";
import "./form_data_test.ts";
import "./headers_test.ts";
@@ -37,3 +39,5 @@ import "./truncate_test.ts";
import "./url_test.ts";
import "./url_search_params_test.ts";
import "./write_file_test.ts";
+
+// TODO import "../website/app_test.js";
diff --git a/js/util.ts b/js/util.ts
index c5197164e..53de68c30 100644
--- a/js/util.ts
+++ b/js/util.ts
@@ -103,15 +103,15 @@ export function containsOnlyASCII(str: string): boolean {
return /^[\x00-\x7F]*$/.test(str);
}
-// @internal
export interface Deferred {
promise: Promise<void>;
resolve: Function;
reject: Function;
}
-/** Create a wrapper around a promise that could be resolved externally. */
-// @internal
+/** Create a wrapper around a promise that could be resolved externally.
+ * TODO Do not expose this from "deno" namespace.
+ */
export function deferred(): Deferred {
let resolve: Function | undefined;
let reject: Function | undefined;