Skip to content

Commit 59c70c3

Browse files
committed
don't run util.inspect tests in deno 1.x
1 parent de91221 commit 59c70c3

File tree

1 file changed

+52
-49
lines changed

1 file changed

+52
-49
lines changed

internal/format_test.ts

+52-49
Original file line numberDiff line numberDiff line change
@@ -105,37 +105,39 @@ if (typeof Deno.inspect === "function") {
105105
});
106106
}
107107

108-
Deno.test("format() has fallback to util.inspect if Deno.inspect is not available", async (t) => {
109-
// Simulates the environment where Deno.inspect is not available
110-
const inspect = Deno.inspect;
111-
// deno-lint-ignore no-explicit-any
112-
delete (Deno as any).inspect;
113-
try {
114-
assertEquals(format([..."abcd"]), `[\n 'a',\n 'b',\n 'c',\n 'd'\n]`);
115-
assertEquals(format({ a: 1, b: 2 }), `{\n a: 1,\n b: 2\n}`);
116-
await t.step("format() sorts properties", () =>
117-
assertEquals(
118-
format({ b: 2, a: 1 }),
119-
format({ a: 1, b: 2 }),
120-
));
108+
// deno-lint-ignore no-explicit-any
109+
if (typeof (globalThis as any).process?.getBuiltinModule === "function") {
110+
Deno.test("format() has fallback to util.inspect if Deno.inspect is not available", async (t) => {
111+
// Simulates the environment where Deno.inspect is not available
112+
const inspect = Deno.inspect;
113+
// deno-lint-ignore no-explicit-any
114+
delete (Deno as any).inspect;
115+
try {
116+
assertEquals(format([..."abcd"]), `[\n 'a',\n 'b',\n 'c',\n 'd'\n]`);
117+
assertEquals(format({ a: 1, b: 2 }), `{\n a: 1,\n b: 2\n}`);
118+
await t.step("format() sorts properties", () =>
119+
assertEquals(
120+
format({ b: 2, a: 1 }),
121+
format({ a: 1, b: 2 }),
122+
));
121123

122-
await t.step("format() wraps Object with getters", () =>
123-
assertEquals(
124-
format(Object.defineProperty({}, "a", {
125-
enumerable: true,
126-
get() {
127-
return 1;
128-
},
129-
})),
130-
`{
124+
await t.step("format() wraps Object with getters", () =>
125+
assertEquals(
126+
format(Object.defineProperty({}, "a", {
127+
enumerable: true,
128+
get() {
129+
return 1;
130+
},
131+
})),
132+
`{
131133
a: [Getter: 1]
132134
}`,
133-
));
135+
));
134136

135-
await t.step("format() wraps nested small objects", () =>
136-
assertEquals(
137-
stripAnsiCode(format([{ x: { a: 1, b: 2 }, y: ["a", "b"] }])),
138-
`[
137+
await t.step("format() wraps nested small objects", () =>
138+
assertEquals(
139+
stripAnsiCode(format([{ x: { a: 1, b: 2 }, y: ["a", "b"] }])),
140+
`[
139141
{
140142
x: {
141143
a: 1,
@@ -147,13 +149,13 @@ Deno.test("format() has fallback to util.inspect if Deno.inspect is not availabl
147149
]
148150
}
149151
]`,
150-
));
152+
));
151153

152-
// Grouping is disabled.
153-
await t.step("format() disables grouping", () =>
154-
assertEquals(
155-
stripAnsiCode(format(["i", "i", "i", "i", "i", "i", "i"])),
156-
`[
154+
// Grouping is disabled.
155+
await t.step("format() disables grouping", () =>
156+
assertEquals(
157+
stripAnsiCode(format(["i", "i", "i", "i", "i", "i", "i"])),
158+
`[
157159
'i',
158160
'i',
159161
'i',
@@ -162,23 +164,24 @@ Deno.test("format() has fallback to util.inspect if Deno.inspect is not availabl
162164
'i',
163165
'i'
164166
]`,
165-
));
166-
await t.step("format() doesn't truncate long strings in object", () => {
167-
const str = format({
168-
foo:
169-
"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.",
170-
});
171-
assertEquals(
172-
str,
173-
`{
167+
));
168+
await t.step("format() doesn't truncate long strings in object", () => {
169+
const str = format({
170+
foo:
171+
"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.",
172+
});
173+
assertEquals(
174+
str,
175+
`{
174176
foo: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.'
175177
}`,
176-
);
177-
});
178-
} finally {
179-
Deno.inspect = inspect;
180-
}
181-
});
178+
);
179+
});
180+
} finally {
181+
Deno.inspect = inspect;
182+
}
183+
});
184+
}
182185

183186
Deno.test("format() has fallback to String if util.inspect and Deno.inspect are not available", () => {
184187
// Simulates the environment where Deno.inspect and util.inspect are not available
@@ -187,7 +190,7 @@ Deno.test("format() has fallback to String if util.inspect and Deno.inspect are
187190
delete (Deno as any).inspect;
188191
// deno-lint-ignore no-explicit-any
189192
const { process } = globalThis as any;
190-
const getBuiltinModule = process.getBuiltinModule;
193+
const getBuiltinModule = process?.getBuiltinModule;
191194
delete process.getBuiltinModule;
192195
try {
193196
assertEquals(format([..."abcd"]), `"a,b,c,d"`);

0 commit comments

Comments
 (0)