summaryrefslogtreecommitdiff
path: root/cli/tests/unit/console_test.ts
diff options
context:
space:
mode:
authorKenta Moriuchi <moriken@kimamass.com>2023-12-19 15:05:49 +0900
committerGitHub <noreply@github.com>2023-12-19 15:05:49 +0900
commit68241234faa4715708010b75744bbfa2bb0cc40a (patch)
treef3d50b8456b66097905ea14a69246873b690d920 /cli/tests/unit/console_test.ts
parent476f5d3deb2f1f4cba5371fdc803540cca47ea11 (diff)
fix(console): inspect for `{Set,Map}Iterator` and `Weak{Set,Map}` (#21554)
Diffstat (limited to 'cli/tests/unit/console_test.ts')
-rw-r--r--cli/tests/unit/console_test.ts47
1 files changed, 43 insertions, 4 deletions
diff --git a/cli/tests/unit/console_test.ts b/cli/tests/unit/console_test.ts
index d6e2a5263..2c8021c51 100644
--- a/cli/tests/unit/console_test.ts
+++ b/cli/tests/unit/console_test.ts
@@ -269,6 +269,14 @@ Deno.test(function consoleTestStringifyCircular() {
);
assertEquals(stringify(new Set([1, 2, 3])), "Set(3) { 1, 2, 3 }");
assertEquals(
+ stringify(new Set([1, 2, 3]).values()),
+ "[Set Iterator] { 1, 2, 3 }",
+ );
+ assertEquals(
+ stringify(new Set([1, 2, 3]).entries()),
+ "[Set Entries] { [ 1, 1 ], [ 2, 2 ], [ 3, 3 ] }",
+ );
+ assertEquals(
stringify(
new Map([
[1, "one"],
@@ -277,6 +285,14 @@ Deno.test(function consoleTestStringifyCircular() {
),
`Map(2) { 1 => "one", 2 => "two" }`,
);
+ assertEquals(
+ stringify(new Map([[1, "one"], [2, "two"]]).values()),
+ `[Map Iterator] { "one", "two" }`,
+ );
+ assertEquals(
+ stringify(new Map([[1, "one"], [2, "two"]]).entries()),
+ `[Map Entries] { [ 1, "one" ], [ 2, "two" ] }`,
+ );
assertEquals(stringify(new WeakSet()), "WeakSet { <items unknown> }");
assertEquals(stringify(new WeakMap()), "WeakMap { <items unknown> }");
assertEquals(stringify(Symbol(1)), `Symbol("1")`);
@@ -378,13 +394,16 @@ Deno.test(function consoleTestStringifyFunctionWithPrototypeRemoved() {
assertEquals(stringify(f), "[Function (null prototype): f]");
const af = async function af() {};
Reflect.setPrototypeOf(af, null);
- assertEquals(stringify(af), "[Function (null prototype): af]");
+ assertEquals(stringify(af), "[AsyncFunction (null prototype): af]");
const gf = function* gf() {};
Reflect.setPrototypeOf(gf, null);
- assertEquals(stringify(gf), "[Function (null prototype): gf]");
+ assertEquals(stringify(gf), "[GeneratorFunction (null prototype): gf]");
const agf = async function* agf() {};
Reflect.setPrototypeOf(agf, null);
- assertEquals(stringify(agf), "[Function (null prototype): agf]");
+ assertEquals(
+ stringify(agf),
+ "[AsyncGeneratorFunction (null prototype): agf]",
+ );
});
Deno.test(function consoleTestStringifyFunctionWithProperties() {
@@ -1002,6 +1021,26 @@ Deno.test(function consoleTestStringifyIterableWhenGrouped() {
);
});
+Deno.test(function consoleTestIteratorValueAreNotConsumed() {
+ const setIterator = new Set([1, 2, 3]).values();
+ assertEquals(
+ stringify(setIterator),
+ "[Set Iterator] { 1, 2, 3 }",
+ );
+ assertEquals([...setIterator], [1, 2, 3]);
+});
+
+Deno.test(function consoleTestWeakSetAndWeakMapWithShowHidden() {
+ assertEquals(
+ stripColor(Deno.inspect(new WeakSet([{}]), { showHidden: true })),
+ "WeakSet { {} }",
+ );
+ assertEquals(
+ stripColor(Deno.inspect(new WeakMap([[{}, "foo"]]), { showHidden: true })),
+ 'WeakMap { {} => "foo" }',
+ );
+});
+
Deno.test(async function consoleTestStringifyPromises() {
const pendingPromise = new Promise((_res, _rej) => {});
assertEquals(stringify(pendingPromise), "Promise { <pending> }");
@@ -2279,7 +2318,7 @@ Deno.test(function inspectWithPrototypePollution() {
Deno.test(function inspectPromiseLike() {
assertEquals(
Deno.inspect(Object.create(Promise.prototype)),
- "Promise { <unknown> }",
+ "Promise {}",
);
});