From b633573ad0904c1caaea4d867174695e7bd5fd19 Mon Sep 17 00:00:00 2001 From: Jarred Sumner Date: Wed, 16 Mar 2022 05:05:37 -0700 Subject: [bun.js] Bun.unsafe test should check the gc --- integration/bunjs-only-snippets/unsafe.test.js | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) (limited to 'integration/bunjs-only-snippets/unsafe.test.js') diff --git a/integration/bunjs-only-snippets/unsafe.test.js b/integration/bunjs-only-snippets/unsafe.test.js index c8c241020..1ce0935d6 100644 --- a/integration/bunjs-only-snippets/unsafe.test.js +++ b/integration/bunjs-only-snippets/unsafe.test.js @@ -1,17 +1,26 @@ import { test, expect, it, describe } from "bun:test"; -it("arrayBufferToString u8", () => { +it("arrayBufferToString u8", async () => { var encoder = new TextEncoder(); const bytes = encoder.encode("hello world"); Bun.gc(true); expect(Bun.unsafe.arrayBufferToString(bytes)).toBe("hello world"); + Bun.gc(true); + await new Promise((resolve) => setTimeout(resolve, 0)); + Bun.gc(true); }); -it("arrayBufferToString ArrayBuffer", () => { +it("arrayBufferToString ArrayBuffer", async () => { var encoder = new TextEncoder(); - const bytes = encoder.encode("hello world"); + var bytes = encoder.encode("hello world"); Bun.gc(true); - expect(Bun.unsafe.arrayBufferToString(bytes.buffer)).toBe("hello world"); + const out = Bun.unsafe.arrayBufferToString(bytes.buffer); + expect(out).toBe("hello world"); + Bun.gc(true); + await new Promise((resolve) => setTimeout(resolve, 0)); + globalThis.bytes = bytes; + Bun.gc(true); + expect(out).toBe("hello world"); }); it("arrayBufferToString u16", () => { @@ -29,4 +38,5 @@ it("arrayBufferToString u16", () => { } Bun.gc(true); expect(charCodes.length).toBe("hello world".length); + Bun.gc(true); }); -- cgit v1.2.3