diff options
author | 2022-03-13 16:16:27 -0700 | |
---|---|---|
committer | 2022-03-13 16:16:27 -0700 | |
commit | 13cd18e614a6d2519da43c4165a2e5ae9128b349 (patch) | |
tree | 1ebdc9a510e8798a679c42f5f41de055e8caa72c /integration/bunjs-only-snippets/html-rewriter.test.js | |
parent | 0a8976c1e05498c86998f44b3bc6a8c2f88ec3c8 (diff) | |
download | bun-13cd18e614a6d2519da43c4165a2e5ae9128b349.tar.gz bun-13cd18e614a6d2519da43c4165a2e5ae9128b349.tar.zst bun-13cd18e614a6d2519da43c4165a2e5ae9128b349.zip |
make headers a ptrjarred/htmlrewriter
Diffstat (limited to 'integration/bunjs-only-snippets/html-rewriter.test.js')
-rw-r--r-- | integration/bunjs-only-snippets/html-rewriter.test.js | 48 |
1 files changed, 34 insertions, 14 deletions
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("<span>replace</span>", { html: true }); + }, 5); + }, + }) + .transform(new Response("<div>example.com</div>")); + expect(await res.text()).toBe("<div><span>replace</span></div>"); + }); + it("exists globally", async () => { expect(typeof HTMLRewriter).toBe("function"); expect(typeof HTMLRewriter.constructor).toBe("function"); @@ -131,26 +156,21 @@ describe("HTMLRewriter", () => { remove: "<p></p>", }; - 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("<p><!--test--></p>")); - t.is(await res.text(), "<p><!--new--></p>"); + expect(await res.text()).toBe("<p><!--new--></p>"); }; - 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) => { |