import { test, expect } from "bun:test"; import { Resvg } from "@resvg/resvg-js"; const opts = { fitTo: { mode: "width", value: 500, }, font: { loadSystemFonts: false, }, }; const svg = ` `; for (let Class of [ Resvg, // Test that subclasses work as well. class ResvgSubclass extends Resvg { constructor(...args) { super(...args); } iShouldExist() { return true; } }, ]) { test(`bbox ${Class.name}`, () => { const resvg = new Class(svg, opts); const bbox = resvg.getBBox(); expect(resvg.width).toBe(180); expect(resvg.height).toBe(260); if (bbox) resvg.cropByBBox(bbox); expect(bbox.width).toBe(112.20712208389321); expect(bbox.height).toBe(81); const pngData = resvg.render(); expect(pngData.width).toBe(500); expect(pngData.height).toBe(362); if (Class !== Resvg) { expect(resvg).toHaveProperty("iShouldExist"); expect(resvg.iShouldExist()).toBeTrue(); } }); } test("napi_create_external_buffer", () => { const resvg = new Resvg(svg, opts); for (let i = 0; i < 10; i++) { resvg.render().asPng(); Bun.gc(); } });