Skip to content

Commit

Permalink
refactor: use inspect and update comment
Browse files Browse the repository at this point in the history
  • Loading branch information
gagik committed Feb 19, 2025
1 parent 1c528e9 commit 81b2194
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 16 deletions.
14 changes: 6 additions & 8 deletions packages/cli-repl/src/mongosh-repl.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import type { Duplex } from 'stream';
import { PassThrough } from 'stream';
import type { StubbedInstance } from 'ts-sinon';
import { stubInterface } from 'ts-sinon';
import { promisify } from 'util';
import { inspect, promisify } from 'util';
import {
expect,
fakeTTYProps,
Expand Down Expand Up @@ -547,13 +547,11 @@ describe('MongoshNodeRepl', function () {
input.write('history()\n');
await waitEval(bus);
expect(output).includes(
formatOutput(
{
value: getAllHistoryItems()
.slice(1, getAllHistoryItems().length)
.reverse(),
},
{ colors: true, maxArrayLength: Infinity }
inspect(
getAllHistoryItems()
.slice(1, getAllHistoryItems().length)
.reverse(),
{ maxArrayLength: Infinity }
)
);
});
Expand Down
20 changes: 12 additions & 8 deletions packages/cli-repl/src/mongosh-repl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -403,14 +403,18 @@ class MongoshNodeRepl implements EvaluationListener {
replHistory.slice(1).reverse();

// eslint-disable-next-line @typescript-eslint/no-explicit-any
formattedHistory[util.inspect.custom as any] = (() => {
return formatOutput(
{
// Providing a copy of the history avoids a circular reference.
value: formattedHistory.concat(),
},
{ colors: true, maxArrayLength: Infinity }
);
formattedHistory[util.inspect.custom as any] = ((
depth: number | null,
options: util.InspectOptions,
inspect: typeof util.inspect
) => {
// We pass a copy of the array without the util.inspect.custom set
// to prevent infinite recursion.
return inspect(formattedHistory.concat(), {
...options,
depth,
maxArrayLength: Infinity,
});
// eslint-disable-next-line @typescript-eslint/no-explicit-any
}) as any;
return formattedHistory;
Expand Down

0 comments on commit 81b2194

Please sign in to comment.