summaryrefslogtreecommitdiff
path: root/cli/tests
diff options
context:
space:
mode:
Diffstat (limited to 'cli/tests')
-rw-r--r--cli/tests/integration/node_unit_tests.rs1
-rw-r--r--cli/tests/unit/console_test.ts35
-rw-r--r--cli/tests/unit_node/console_test.ts28
-rw-r--r--cli/tests/unit_node/util_test.ts45
4 files changed, 97 insertions, 12 deletions
diff --git a/cli/tests/integration/node_unit_tests.rs b/cli/tests/integration/node_unit_tests.rs
index 1508ad9ac..273066b09 100644
--- a/cli/tests/integration/node_unit_tests.rs
+++ b/cli/tests/integration/node_unit_tests.rs
@@ -52,6 +52,7 @@ util::unit_test_factory!(
assertion_error_test,
buffer_test,
child_process_test,
+ console_test,
crypto_cipher_test = crypto / crypto_cipher_test,
crypto_cipher_gcm_test = crypto / crypto_cipher_gcm_test,
crypto_hash_test = crypto / crypto_hash_test,
diff --git a/cli/tests/unit/console_test.ts b/cli/tests/unit/console_test.ts
index 7d4675976..031512f79 100644
--- a/cli/tests/unit/console_test.ts
+++ b/cli/tests/unit/console_test.ts
@@ -1845,18 +1845,36 @@ Deno.test(function consoleLogShouldNotThrowErrorWhenInvalidDateIsPassed() {
// console.log(new Proxy(new Set(), {}))
Deno.test(function consoleLogShouldNotThrowErrorWhenInputIsProxiedSet() {
mockConsole((console, out) => {
- const proxiedSet = new Proxy(new Set(), {});
+ const proxiedSet = new Proxy(new Set([1, 2]), {});
console.log(proxiedSet);
- assertEquals(stripColor(out.toString()), "Set {}\n");
+ assertEquals(stripColor(out.toString()), "Set(2) { 1, 2 }\n");
});
});
// console.log(new Proxy(new Map(), {}))
Deno.test(function consoleLogShouldNotThrowErrorWhenInputIsProxiedMap() {
mockConsole((console, out) => {
- const proxiedMap = new Proxy(new Map(), {});
+ const proxiedMap = new Proxy(new Map([[1, 1], [2, 2]]), {});
console.log(proxiedMap);
- assertEquals(stripColor(out.toString()), "Map {}\n");
+ assertEquals(stripColor(out.toString()), "Map(2) { 1 => 1, 2 => 2 }\n");
+ });
+});
+
+// console.log(new Proxy(new Uint8Array(), {}))
+Deno.test(function consoleLogShouldNotThrowErrorWhenInputIsProxiedTypedArray() {
+ mockConsole((console, out) => {
+ const proxiedUint8Array = new Proxy(new Uint8Array([1, 2]), {});
+ console.log(proxiedUint8Array);
+ assertEquals(stripColor(out.toString()), "Uint8Array(2) [ 1, 2 ]\n");
+ });
+});
+
+// console.log(new Proxy(new RegExp(), {}))
+Deno.test(function consoleLogShouldNotThrowErrorWhenInputIsProxiedRegExp() {
+ mockConsole((console, out) => {
+ const proxiedRegExp = new Proxy(/aaaa/, {});
+ console.log(proxiedRegExp);
+ assertEquals(stripColor(out.toString()), "/aaaa/\n");
});
});
@@ -1869,6 +1887,15 @@ Deno.test(function consoleLogShouldNotThrowErrorWhenInputIsProxiedDate() {
});
});
+// console.log(new Proxy(new Error(), {}))
+Deno.test(function consoleLogShouldNotThrowErrorWhenInputIsProxiedError() {
+ mockConsole((console, out) => {
+ const proxiedError = new Proxy(new Error("message"), {});
+ console.log(proxiedError);
+ assertStringIncludes(stripColor(out.toString()), "Error: message\n");
+ });
+});
+
// console.dir test
Deno.test(function consoleDir() {
mockConsole((console, out) => {
diff --git a/cli/tests/unit_node/console_test.ts b/cli/tests/unit_node/console_test.ts
new file mode 100644
index 000000000..583e98e22
--- /dev/null
+++ b/cli/tests/unit_node/console_test.ts
@@ -0,0 +1,28 @@
+// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
+
+import vm from "node:vm";
+import { stripColor } from "../../../test_util/std/fmt/colors.ts";
+import { assertStringIncludes } from "../../../test_util/std/assert/mod.ts";
+
+Deno.test(function inspectCrossRealmObjects() {
+ assertStringIncludes(
+ stripColor(
+ Deno.inspect(vm.runInNewContext(`new Error("This is an error")`)),
+ ),
+ "Error: This is an error",
+ );
+ assertStringIncludes(
+ stripColor(
+ Deno.inspect(
+ vm.runInNewContext(`new AggregateError([], "This is an error")`),
+ ),
+ ),
+ "AggregateError: This is an error",
+ );
+ assertStringIncludes(
+ stripColor(
+ Deno.inspect(vm.runInNewContext(`new Date("2018-12-10T02:26:59.002Z")`)),
+ ),
+ "2018-12-10T02:26:59.002Z",
+ );
+});
diff --git a/cli/tests/unit_node/util_test.ts b/cli/tests/unit_node/util_test.ts
index 3cb5e4366..2e2bb0021 100644
--- a/cli/tests/unit_node/util_test.ts
+++ b/cli/tests/unit_node/util_test.ts
@@ -8,6 +8,7 @@ import {
} from "../../../test_util/std/assert/mod.ts";
import { stripColor } from "../../../test_util/std/fmt/colors.ts";
import * as util from "node:util";
+import { Buffer } from "node:buffer";
Deno.test({
name: "[util] format",
@@ -130,9 +131,11 @@ Deno.test({
fn() {
const java = new Error();
const nodejs = Reflect.construct(Error, [], Object);
+ const bun = new DOMException();
const deno = "Future";
assert(util.isError(java));
assert(util.isError(nodejs));
+ assert(util.isError(bun));
assert(!util.isError(deno));
},
});
@@ -191,6 +194,40 @@ Deno.test({
});
Deno.test({
+ name: "[util] isDate",
+ fn() {
+ // Test verifies the method is exposed. See _util/_util_types_test for details
+ assert(util.isDate(new Date()));
+ },
+});
+
+Deno.test({
+ name: "[util] isBuffer",
+ fn() {
+ assert(util.isBuffer(new Buffer(4)));
+ assert(!util.isBuffer(new Uint8Array(4)));
+ },
+});
+
+Deno.test({
+ name: "[util] types.isTypedArray",
+ fn() {
+ assert(util.types.isTypedArray(new Buffer(4)));
+ assert(util.types.isTypedArray(new Uint8Array(4)));
+ assert(!util.types.isTypedArray(new DataView(new ArrayBuffer(4))));
+ },
+});
+
+Deno.test({
+ name: "[util] types.isNativeError",
+ fn() {
+ assert(util.types.isNativeError(new Error()));
+ assert(util.types.isNativeError(new TypeError()));
+ assert(!util.types.isNativeError(new DOMException()));
+ },
+});
+
+Deno.test({
name: "[util] TextDecoder",
fn() {
assert(util.TextDecoder === TextDecoder);
@@ -217,14 +254,6 @@ Deno.test({
});
Deno.test({
- name: "[util] isDate",
- fn() {
- // Test verifies the method is exposed. See _util/_util_types_test for details
- assert(util.types.isDate(new Date()));
- },
-});
-
-Deno.test({
name: "[util] getSystemErrorName()",
fn() {
type FnTestInvalidArg = (code?: unknown) => void;