Skip to content

Commit 6c89abb

Browse files
committed
test: render image snapshots with Sharp
1 parent f28ffbd commit 6c89abb

4 files changed

Lines changed: 2 additions & 2 deletions
11.7 KB
Loading
-1.82 KB
Loading
-554 Bytes
Loading

test/utils.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ export async function toImageWithSharp(svg: string, width = 100) {
6262
const webpDataUris = svg.match(/data:image\/webp;base64,[^"']+/g) || []
6363

6464
for (const dataUri of webpDataUris) {
65-
// Resvg cannot decode embedded WebP, so transcode only the image payload.
65+
// Sharp's SVG decoder cannot decode embedded WebP, so transcode the payload.
6666
const webp = Buffer.from(dataUri.slice(dataUri.indexOf(',') + 1), 'base64')
6767
const png = await Sharp(webp).png().toBuffer()
6868
svg = svg.replace(
@@ -71,7 +71,7 @@ export async function toImageWithSharp(svg: string, width = 100) {
7171
)
7272
}
7373

74-
return toImage(svg, width)
74+
return Sharp(Buffer.from(svg)).resize({ width }).png().toBuffer()
7575
}
7676

7777
declare global {

0 commit comments

Comments
 (0)