@@ -103,15 +103,82 @@ Deno.test("format() doesn't truncate long strings in object", () => {
103
103
) ;
104
104
} ) ;
105
105
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 ) => {
107
107
// Simulates the environment where Deno.inspect is not available
108
108
const inspect = Deno . inspect ;
109
109
// deno-lint-ignore no-explicit-any
110
110
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 ;
111
177
try {
112
178
assertEquals ( format ( [ ..."abcd" ] ) , `"a,b,c,d"` ) ;
113
179
assertEquals ( format ( { a : 1 , b : 2 } ) , `"[object Object]"` ) ;
114
180
} finally {
115
181
Deno . inspect = inspect ;
182
+ process . getBuiltinModule = getBuiltinModule ;
116
183
}
117
184
} ) ;
0 commit comments