aboutsummaryrefslogtreecommitdiff
path: root/test/js
diff options
context:
space:
mode:
authorGravatar Jarred Sumner <jarred@jarredsumner.com> 2023-08-19 17:46:59 -0700
committerGravatar GitHub <noreply@github.com> 2023-08-19 17:46:59 -0700
commit196620183fd20ca42b363c5f947af1dc979f888f (patch)
tree2413e721e515588eb743358df6a4a4f3750572d8 /test/js
parent86ad0151479c96314233c2d7dfbf7ed83b57feab (diff)
downloadbun-196620183fd20ca42b363c5f947af1dc979f888f.tar.gz
bun-196620183fd20ca42b363c5f947af1dc979f888f.tar.zst
bun-196620183fd20ca42b363c5f947af1dc979f888f.zip
Fixes #172 (#4220)
Co-authored-by: Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com>
Diffstat (limited to 'test/js')
-rw-r--r--test/js/third_party/resvg/bbox.test.js53
-rw-r--r--test/js/third_party/resvg/package.json6
2 files changed, 59 insertions, 0 deletions
diff --git a/test/js/third_party/resvg/bbox.test.js b/test/js/third_party/resvg/bbox.test.js
new file mode 100644
index 000000000..d80e99cdd
--- /dev/null
+++ b/test/js/third_party/resvg/bbox.test.js
@@ -0,0 +1,53 @@
+import { test, expect } from "bun:test";
+import { Resvg } from "@resvg/resvg-js";
+
+const svg = `<svg viewBox="-40 0 180 260" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
+<g fill="green" transform="rotate(-10 50 100) translate(-36 45.5) skewX(40) scale(1 0.5)">
+ <path id="heart" d="M 10,30 A 20,20 0,0,1 50,30 A 20,20 0,0,1 90,30 Q 90,60 50,90 Q 10,60 10,30 z" />
+</g>
+<use xlink:href="#heart" fill="none" stroke="red" stroke-width="1" />
+</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 opts = {
+ fitTo: {
+ mode: "width",
+ value: 500,
+ },
+ font: {
+ loadSystemFonts: false,
+ },
+ };
+
+ 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);
+ const pngData = resvg.render();
+
+ expect(bbox.width).toBe(112.20712208389321);
+ expect(bbox.height).toBe(81);
+
+ expect(pngData.width).toBe(500);
+ expect(pngData.height).toBe(362);
+
+ if (Class !== Resvg) {
+ expect(resvg).toHaveProperty("iShouldExist");
+ expect(resvg.iShouldExist()).toBeTrue();
+ }
+ });
+}
diff --git a/test/js/third_party/resvg/package.json b/test/js/third_party/resvg/package.json
new file mode 100644
index 000000000..932f36221
--- /dev/null
+++ b/test/js/third_party/resvg/package.json
@@ -0,0 +1,6 @@
+{
+ "name": "bun-integration-test-resvg",
+ "dependencies": {
+ "@resvg/resvg-js": "2.4.1"
+ }
+}