aboutsummaryrefslogtreecommitdiff
path: root/integration/bunjs-only-snippets/unsafe.test.js
diff options
context:
space:
mode:
authorGravatar Jarred Sumner <jarred@jarredsumner.com> 2022-03-16 05:05:37 -0700
committerGravatar Jarred Sumner <jarred@jarredsumner.com> 2022-03-16 05:05:37 -0700
commitb633573ad0904c1caaea4d867174695e7bd5fd19 (patch)
tree1b4a12ae46466fb58a2fd5cc48146f4b4b1458c1 /integration/bunjs-only-snippets/unsafe.test.js
parentc97ca4830ee7163f7ac6e691953a90be9d9e9792 (diff)
downloadbun-b633573ad0904c1caaea4d867174695e7bd5fd19.tar.gz
bun-b633573ad0904c1caaea4d867174695e7bd5fd19.tar.zst
bun-b633573ad0904c1caaea4d867174695e7bd5fd19.zip
[bun.js] Bun.unsafe test should check the gc
Diffstat (limited to 'integration/bunjs-only-snippets/unsafe.test.js')
-rw-r--r--integration/bunjs-only-snippets/unsafe.test.js18
1 files changed, 14 insertions, 4 deletions
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);
});