mirror of
https://github.com/denoland/deno.git
synced 2025-08-03 18:38:33 +00:00
feat(ext/console): better circular information in object inspection (#13555)
This commit is contained in:
parent
3ec07f4e06
commit
2f438f4106
2 changed files with 98 additions and 31 deletions
|
@ -225,7 +225,7 @@ Deno.test(function consoleTestStringifyCircular() {
|
|||
};
|
||||
|
||||
nestedObj.o = circularObj;
|
||||
const nestedObjExpected = `{
|
||||
const nestedObjExpected = `<ref *1> {
|
||||
num: 1,
|
||||
bool: true,
|
||||
str: "a",
|
||||
|
@ -245,9 +245,9 @@ Deno.test(function consoleTestStringifyCircular() {
|
|||
method: [Function: method],
|
||||
un: undefined,
|
||||
nu: null,
|
||||
nested: [Circular],
|
||||
nested: [Circular *1],
|
||||
emptyObj: {},
|
||||
arr: [ 1, "s", false, null, [Circular] ],
|
||||
arr: [ 1, "s", false, null, [Circular *1] ],
|
||||
baseClass: Base { a: 1 }
|
||||
}
|
||||
}`;
|
||||
|
@ -350,12 +350,23 @@ Deno.test(function consoleTestStringifyCircular() {
|
|||
return Deno.inspect(this);
|
||||
},
|
||||
}),
|
||||
"[Circular]",
|
||||
"[Circular *1]",
|
||||
);
|
||||
// test inspect is working the same
|
||||
assertEquals(stripColor(Deno.inspect(nestedObj)), nestedObjExpected);
|
||||
});
|
||||
|
||||
Deno.test(function consoleTestStringifyMultipleCircular() {
|
||||
const y = { a: { b: {} }, foo: { bar: {} } };
|
||||
y.a.b = y.a;
|
||||
y.foo.bar = y.foo;
|
||||
console.log(y);
|
||||
assertEquals(
|
||||
stringify(y),
|
||||
"{ a: <ref *1> { b: [Circular *1] }, foo: <ref *2> { bar: [Circular *2] } }",
|
||||
);
|
||||
});
|
||||
|
||||
Deno.test(function consoleTestStringifyFunctionWithPrototypeRemoved() {
|
||||
const f = function f() {};
|
||||
Reflect.setPrototypeOf(f, null);
|
||||
|
@ -392,14 +403,14 @@ Deno.test(function consoleTestStringifyFunctionWithProperties() {
|
|||
assertEquals(
|
||||
stringify({ f }),
|
||||
`{
|
||||
f: [Function: f] {
|
||||
f: <ref *1> [Function: f] {
|
||||
x: [Function],
|
||||
y: 3,
|
||||
z: [Function],
|
||||
b: [Function: bar],
|
||||
a: Map {},
|
||||
s: [Circular],
|
||||
t: [Function: t] { x: [Circular] }
|
||||
s: [Circular *1],
|
||||
t: [Function: t] { x: [Circular *1] }
|
||||
}
|
||||
}`,
|
||||
);
|
||||
|
@ -1864,12 +1875,16 @@ Deno.test(function inspectErrorCircular() {
|
|||
);
|
||||
assertStringIncludes(
|
||||
stripColor(Deno.inspect(error2)),
|
||||
"Error: This is an error",
|
||||
"<ref *1> Error: This is an error",
|
||||
);
|
||||
assertStringIncludes(
|
||||
stripColor(Deno.inspect(error2)),
|
||||
"Caused by Error: This is a cause error",
|
||||
);
|
||||
assertStringIncludes(
|
||||
stripColor(Deno.inspect(error2)),
|
||||
"Caused by [Circular *1]",
|
||||
);
|
||||
});
|
||||
|
||||
Deno.test(function inspectColors() {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue