From 13cd18e614a6d2519da43c4165a2e5ae9128b349 Mon Sep 17 00:00:00 2001 From: Jarred Sumner Date: Sun, 13 Mar 2022 16:16:27 -0700 Subject: make headers a ptr --- .../bunjs-only-snippets/html-rewriter.test.js | 48 +++++++++++++++------- 1 file changed, 34 insertions(+), 14 deletions(-) (limited to 'integration/bunjs-only-snippets/html-rewriter.test.js') diff --git a/integration/bunjs-only-snippets/html-rewriter.test.js b/integration/bunjs-only-snippets/html-rewriter.test.js index 8990bf959..bb63d8d25 100644 --- a/integration/bunjs-only-snippets/html-rewriter.test.js +++ b/integration/bunjs-only-snippets/html-rewriter.test.js @@ -1,6 +1,31 @@ import { describe, it, expect } from "bun:test"; +var setTimeoutAsync = (fn, delay) => { + return new Promise((resolve, reject) => { + setTimeout(() => { + try { + resolve(fn()); + } catch (e) { + reject(e); + } + }, delay); + }); +}; + describe("HTMLRewriter", () => { + it("HTMLRewriter: async replacement", async () => { + const res = new HTMLRewriter() + .on("div", { + async element(element) { + await setTimeoutAsync(() => { + element.setInnerContent("replace", { html: true }); + }, 5); + }, + }) + .transform(new Response("
example.com
")); + expect(await res.text()).toBe("
replace
"); + }); + it("exists globally", async () => { expect(typeof HTMLRewriter).toBe("function"); expect(typeof HTMLRewriter.constructor).toBe("function"); @@ -131,26 +156,21 @@ describe("HTMLRewriter", () => { remove: "

", }; - const commentPropertiesMacro = async (t, func) => { + const commentPropertiesMacro = async (func) => { const res = func(new HTMLRewriter(), (comment) => { expect(comment.removed).toBe(false); expect(comment.text).toBe("test"); comment.text = "new"; + expect(comment.text).toBe("new"); }).transform(new Response("

")); - t.is(await res.text(), "

"); + expect(await res.text()).toBe("

"); }; - test( - "HTMLRewriter: handles comment properties", - commentPropertiesMacro, - (rw, comments) => rw.on("p", { comments }) - ); - test( - "HTMLRewriter: handles comment mutations", - mutationsMacro, - (rw, comments) => rw.on("p", { comments }), - commentsMutationsInput, - commentsMutationsExpected - ); + + it("HTMLRewriter: handles comment properties", () => + commentPropertiesMacro((rw, comments) => { + rw.on("p", { comments }); + return rw; + })); it("selector tests", async () => { const checkSelector = async (selector, input, expected) => { -- cgit v1.2.3