From 6bac34d2ff8cbd254d19ea44618a86ff368d6c9b Mon Sep 17 00:00:00 2001 From: Quinn Turner Date: Wed, 13 Dec 2023 16:33:14 -0400 Subject: [PATCH] Add coverage to dom utilities --- bun.lockb | Bin 51962 -> 55331 bytes bunfig.toml | 3 ++- happydom.ts | 3 +++ package.json | 3 ++- src/dom/popup.test.ts | 54 ++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 61 insertions(+), 2 deletions(-) create mode 100644 happydom.ts create mode 100644 src/dom/popup.test.ts diff --git a/bun.lockb b/bun.lockb index 544f60c500ba1b224da4bcdc84e8d5c65df53672..24fb1cc7d2e460eb00b8a0ebb25060ee9024b33a 100755 GIT binary patch delta 8801 zcmeHMX;c)~wytWrgM3bYLZqB7a7Og4hhI6O5NFyJ+4;?zO|tqjVb@oMbO)i|LB zI0}k_5=R_Ej8il>dNnalxoQ%9nm8oU7>pB|XkwJyZ&!8Eyt`ak$$MGv$6N2Lwd*_k z?0xn*XP>F6_Tyy^Yu|P#(}m=l)(>4hy1DkjcbV@f(|v0;L{Gl4;qnEav+ssf1wHNG zi=F4h#LCnC;*OR}jP!KlIBOEJ&cJ>^0a#pAGMS_$yu=rkWE2{UOk7TRgO_En1IM|L zQjRI#oHd>6Y2#yoWGr35aUQ_z+=2;Y#ciPQ`KU zfU#|)PV@k_1#iyJF%_DNi_H01x#sMg;*-!vyB2E-8lZ}Lpck;a6UV86Eur{z#0@@&!>4xZMBD|sO@n;nuSW#qS?wc7mC%wyd`Vf(F?L>dexL+MBjSA z0Z_FDFb@YWOGj{IWwNn2M?1+hU9j=wChE%rSRvOo0;vy|fn;r3jyWR-*33n)3%mih zP%qwtn@HbOG@-ud$(HU*0$uuig-j{suC)_yiV z6i92NgRPtglHuE!a5DS_kQzK{;~RifzZOV(3xKq?N<_H}{AW`b%EFaFmh;`Dxj1IS z_1&dCVa%VNXDrUh$uMSMv>X?K8K*hh5+sc`24&Hk;y#KD8;piDCnFVH^jaTT6j7jzS>j#`+47{4l^K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Xt;4j)^y8&dMfQzxqLv=o7-uswg<~gOx%1PC?CY?CjRQ*~n>KA!kb!x1 zqhe}qPbW9_vl;0@zxC%%Kh^qtoMs%$#tGDAQwAK*+@zSUcci78tTrQCm}(z7an7n? z!#)17r2^^oO-e$eRX?ys&nr6c+1|R{(DVFYd`1Q^`rFU1mW6)vM`$n?JR2ve&1NOB zC1W^p$o8+7pNrRqq3MmB;t}7=-G+@k{GM0yqm{;Q?kCK&e6u2gXy@j9ahO83WQg^Y zwM9vAXgNB`eW>;5HA5~AC?!mO9y}~0xwtF?>XwMeKW@PzlY%vYT zFXuk$)mPHFEeig${|#0~j_^&X>49#SO#{7FuTkGxCDF(!o|!*oNbK{c8@+lX>$rL6 zys1sTQ6G6VHzH_Wt<`3vDUWRmj(9uz@+hxCSK3>vh$K2vtJsVrXHLhPa*)0Kb+1(p z-KkX)jHKuy^X`JIkd)b8y^%Jh)GJ-4KD&02S5r+HTNRs;XFYV?ZGWP6EP3^fRJm0V zC#ZUBzRk!q*F62|pdGgYx0%Ge1V^j`t6?`qY>UG&F=kta>8p0Maho;KNQF*b`iF-L zKdWi-PNR`DeWKNb>H$l)7DE%KFAX$p+GZ8YsP*=^a3j~b`*g>I#_J=GnMJGvhXS^9 zX*3PoVNEoWqe0i!Ja13?aHH42NS_|uJyZ?POxobpG(^*~9oDW!zE$nB(|79W`>uKo z_In=svp3-4Y)_x>a8U5h7~!P!o%YCjILD53AHKF`z`RD+)%U>jd3?jUVq1@GO5Dd( zxznC<0H-wH;%CPGzBcp4PRhIB`9!S@9UFM3ef;Og!3TqXCpqgO^|6#sc5Fa5C^?7e S^v?9Uq+PeV*Iho5;`4WX49#)? diff --git a/bunfig.toml b/bunfig.toml index 614d182..9d8bbbe 100644 --- a/bunfig.toml +++ b/bunfig.toml @@ -1,3 +1,4 @@ [test] coverage = true -coverageThreshold = 1.0 \ No newline at end of file +coverageThreshold = 1.0 +preload = "./happydom.ts" \ No newline at end of file diff --git a/happydom.ts b/happydom.ts new file mode 100644 index 0000000..7f712d0 --- /dev/null +++ b/happydom.ts @@ -0,0 +1,3 @@ +import { GlobalRegistrator } from "@happy-dom/global-registrator"; + +GlobalRegistrator.register(); diff --git a/package.json b/package.json index 9b55b5b..f07664d 100644 --- a/package.json +++ b/package.json @@ -48,10 +48,11 @@ }, "devDependencies": { "@biomejs/biome": "^1.4.1", + "@happy-dom/global-registrator": "^12.10.3", "bun-types": "^1.0.17", "tsup": "^8.0.1", "type-fest": "^4.8.3", "typescript": "^5.3.3" }, - "packageManager": "bun@1.0.14" + "packageManager": "bun@1.0.17" } diff --git a/src/dom/popup.test.ts b/src/dom/popup.test.ts new file mode 100644 index 0000000..a79e8b4 --- /dev/null +++ b/src/dom/popup.test.ts @@ -0,0 +1,54 @@ +import { beforeEach, describe, expect, it, jest } from "bun:test"; +import { openPopup } from "./popup.js"; + +const window = globalThis.window as Window | undefined; +if (!window) { + throw new Error("window is not defined"); +} + +describe("openPopup", () => { + beforeEach(() => { + jest.restoreAllMocks(); + }); + it("should return a new window object with the correct properties", () => { + const url = "https://example.com"; + const name = "popup"; + const updatedWindow = { + ...window, + location: { + ...window.location, + href: url, + }, + name, + }; + window.open = jest.fn().mockReturnValue(updatedWindow); + + const windowFeatures = "width=500,height=500"; + const newWindow = openPopup(url, name, windowFeatures); + + expect(window.open).toHaveBeenCalledWith( + url, + name, + `noopener,noreferrer,${windowFeatures}`, + ); + expect(newWindow).not.toBeNull(); + expect(newWindow?.location.href).toBe(url); + expect(newWindow?.name).toBe(name); + expect(newWindow?.opener).toBeNull(); + }); + it("should not return a new window object if the browser fails to open the new browsing context", () => { + window.open = jest.fn().mockReturnValue(null); + + const url = "https://example.com"; + const name = "popup"; + const windowFeatures = "width=500,height=500"; + const newWindow = openPopup(url, name, windowFeatures); + + expect(window.open).toHaveBeenCalledWith( + url, + name, + `noopener,noreferrer,${windowFeatures}`, + ); + expect(newWindow).toBeNull(); + }); +});