fix(assert): fix diff of long string in objects (#3867)

This commit is contained in:
Yoshiya Hinosawa 2023-11-28 15:46:01 +09:00 committed by GitHub
parent a8ccae3957
commit 4b0eac0d1a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 0 deletions

View File

@ -18,6 +18,7 @@ export function format(v: unknown): string {
iterableLimit: Infinity,
// getters should be true in assertEquals.
getters: true,
strAbbreviateSize: Infinity,
})
: `"${String(v).replace(/(?=["\\])/g, "\\")}"`;
}

View File

@ -78,3 +78,16 @@ Deno.test("assert diff formatting", () => {
]`,
);
});
Deno.test("format() doesn't truncate long strings in object", () => {
const str = format({
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.",
});
assertEquals(
str,
`{
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.",
}`,
);
});