Skip to content
This repository was archived by the owner on Dec 30, 2023. It is now read-only.

Commit 85cc906

Browse files
committed
refactor(test/unit): ♻️ Improve truncation print
1 parent 40625dc commit 85cc906

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

packages/test/source/unit/unit.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -111,11 +111,12 @@ function jsonReplacer(_key: string, value: unknown) {
111111

112112
function getStringifiedAndTruncatedArray(array: Array<unknown>): string {
113113
const { length } = array;
114+
const maxLength = 4;
114115

115-
if (length > 6) {
116-
const firstItems = array.slice(0, 3);
117-
const middle = ` ... truncated ${length - 6} samples ...`;
118-
const lastItems = array.slice(-4, length);
116+
if (length > maxLength) {
117+
const firstItems = array.slice(0, maxLength / 2);
118+
const middle = `\n... ${length - maxLength} items ...`;
119+
const lastItems = array.slice(-(maxLength / 2), length);
119120

120121
return JSON.stringify([...firstItems, "%mid%", ...lastItems], jsonReplacer, 1).replace(/,\n "%mid%",?/, middle);
121122
} else {

0 commit comments

Comments
 (0)