@@ -103,15 +103,82 @@ Deno.test("format() doesn't truncate long strings in object", () => {
103103 ) ;
104104} ) ;
105105
106- Deno . test ( "format() has fallback to String if Deno.inspect is not available" , ( ) => {
106+ Deno . test ( "format() has fallback to util.inspect if Deno.inspect is not available" , async ( t ) => {
107107 // Simulates the environment where Deno.inspect is not available
108108 const inspect = Deno . inspect ;
109109 // deno-lint-ignore no-explicit-any
110110 delete ( Deno as any ) . inspect ;
111+ try {
112+ assertEquals ( format ( [ ..."abcd" ] ) , `[\n 'a',\n 'b',\n 'c',\n 'd',\n]` ) ;
113+ assertEquals ( format ( { a : 1 , b : 2 } ) , `{\n a: 1,\n b: 2,\n}` ) ;
114+ await t . step ( "format() sorts properties" , ( ) =>
115+ assertEquals (
116+ format ( { b : 2 , a : 1 } ) ,
117+ format ( { a : 1 , b : 2 } ) ,
118+ ) ) ;
119+
120+ await t . step ( "format() wraps Object with getters" , ( ) =>
121+ assertEquals (
122+ format ( Object . defineProperty ( { } , "a" , {
123+ enumerable : true ,
124+ get ( ) {
125+ return 1 ;
126+ } ,
127+ } ) ) ,
128+ `{
129+ a: [Getter: 1],
130+ }` ,
131+ ) ) ;
132+
133+ await t . step ( "format() wraps nested small objects" , ( ) =>
134+ assertEquals (
135+ stripAnsiCode ( format ( [ { x : { a : 1 , b : 2 } , y : [ "a" , "b" ] } ] ) ) ,
136+ `[
137+ {
138+ x: {
139+ a: 1,
140+ b: 2,
141+ },
142+ y: [
143+ 'a',
144+ 'b',
145+ ],
146+ },
147+ ]` ,
148+ ) ) ;
149+
150+ // Grouping is disabled.
151+ await t . step ( "format() disables grouping" , ( ) =>
152+ assertEquals (
153+ stripAnsiCode ( format ( [ "i" , "i" , "i" , "i" , "i" , "i" , "i" ] ) ) ,
154+ `[
155+ 'i',
156+ 'i',
157+ 'i',
158+ 'i',
159+ 'i',
160+ 'i',
161+ 'i',
162+ ]` ,
163+ ) ) ;
164+ } finally {
165+ Deno . inspect = inspect ;
166+ }
167+ } ) ;
168+
169+ Deno . test ( "format() has fallback to String if util.inspect and Deno.inspect are not available" , ( ) => {
170+ // Simulates the environment where Deno.inspect and util.inspect are not available
171+ const inspect = Deno . inspect ;
172+ // deno-lint-ignore no-explicit-any
173+ delete ( Deno as any ) . inspect ;
174+ // deno-lint-ignore no-explicit-any
175+ const { process } = globalThis as any ;
176+ const getBuiltinModule = process . getBuiltinModule ;
111177 try {
112178 assertEquals ( format ( [ ..."abcd" ] ) , `"a,b,c,d"` ) ;
113179 assertEquals ( format ( { a : 1 , b : 2 } ) , `"[object Object]"` ) ;
114180 } finally {
115181 Deno . inspect = inspect ;
182+ process . getBuiltinModule = getBuiltinModule ;
116183 }
117184} ) ;
0 commit comments