aboutsummaryrefslogtreecommitdiff
path: root/integration/bunjs-only-snippets/fs.test.js
diff options
context:
space:
mode:
authorGravatar Jarred Sumner <jarred@jarredsumner.com> 2022-01-20 16:19:07 -0800
committerGravatar Jarred Sumner <jarred@jarredsumner.com> 2022-01-20 16:19:07 -0800
commit97f0cef391bd4837b2591a2a0a529be476798683 (patch)
tree18fe7b294a4dc56f89b98f2d80e0cff39149c636 /integration/bunjs-only-snippets/fs.test.js
parent85084c6db9a35cc9b605c5015aab9fca74bc611c (diff)
downloadbun-97f0cef391bd4837b2591a2a0a529be476798683.tar.gz
bun-97f0cef391bd4837b2591a2a0a529be476798683.tar.zst
bun-97f0cef391bd4837b2591a2a0a529be476798683.zip
[Bun.js] Fix TypedArray/ArrayBuffer <> Zig interop
Diffstat (limited to 'integration/bunjs-only-snippets/fs.test.js')
-rw-r--r--integration/bunjs-only-snippets/fs.test.js38
1 files changed, 38 insertions, 0 deletions
diff --git a/integration/bunjs-only-snippets/fs.test.js b/integration/bunjs-only-snippets/fs.test.js
index 513132450..b831fb00b 100644
--- a/integration/bunjs-only-snippets/fs.test.js
+++ b/integration/bunjs-only-snippets/fs.test.js
@@ -17,6 +17,17 @@ describe("readFileSync", () => {
const text = readFileSync(import.meta.dir + "/readFileSync.txt", "utf8");
expect(text).toBe("File read successfully");
});
+
+ it("returning Uint8Array works", () => {
+ const text = readFileSync(import.meta.dir + "/readFileSync.txt");
+ const encoded = [
+ 70, 105, 108, 101, 32, 114, 101, 97, 100, 32, 115, 117, 99, 99, 101, 115,
+ 115, 102, 117, 108, 108, 121,
+ ];
+ for (let i = 0; i < encoded.length; i++) {
+ expect(text[i]).toBe(encoded[i]);
+ }
+ });
});
describe("writeFileSync", () => {
@@ -26,4 +37,31 @@ describe("writeFileSync", () => {
expect(readFileSync(path, "utf8")).toBe("File written successfully");
});
+
+ it("returning Uint8Array works", () => {
+ const buffer = new Uint8Array([
+ 70, 105, 108, 101, 32, 119, 114, 105, 116, 116, 101, 110, 32, 115, 117,
+ 99, 99, 101, 115, 115, 102, 117, 108, 108, 121,
+ ]);
+ const path = `/tmp/${Date.now()}.blob.writeFileSync.txt`;
+ writeFileSync(path, buffer);
+ const out = readFileSync(path);
+
+ for (let i = 0; i < buffer.length; i++) {
+ expect(buffer[i]).toBe(out[i]);
+ }
+ });
+ it("returning ArrayBuffer works", () => {
+ const buffer = new Uint8Array([
+ 70, 105, 108, 101, 32, 119, 114, 105, 116, 116, 101, 110, 32, 115, 117,
+ 99, 99, 101, 115, 115, 102, 117, 108, 108, 121,
+ ]);
+ const path = `/tmp/${Date.now()}.blob2.writeFileSync.txt`;
+ writeFileSync(path, buffer.buffer);
+ const out = readFileSync(path);
+
+ for (let i = 0; i < buffer.length; i++) {
+ expect(buffer[i]).toBe(out[i]);
+ }
+ });
});