diff options
author | 2022-02-17 03:49:28 -0800 | |
---|---|---|
committer | 2022-02-17 03:49:28 -0800 | |
commit | 32eb20702e283c4b47db3a42b43051949321e308 (patch) | |
tree | d4d2cc27e8cf6afb7365a57da7341d16465ac308 /integration/bunjs-only-snippets/fs.test.js | |
parent | 17a7e2b241332eb186d4c8848d3ad631ff50c3d3 (diff) | |
download | bun-32eb20702e283c4b47db3a42b43051949321e308.tar.gz bun-32eb20702e283c4b47db3a42b43051949321e308.tar.zst bun-32eb20702e283c4b47db3a42b43051949321e308.zip |
improve test coverage
Diffstat (limited to 'integration/bunjs-only-snippets/fs.test.js')
-rw-r--r-- | integration/bunjs-only-snippets/fs.test.js | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/integration/bunjs-only-snippets/fs.test.js b/integration/bunjs-only-snippets/fs.test.js index b831fb00b..c4d937ca3 100644 --- a/integration/bunjs-only-snippets/fs.test.js +++ b/integration/bunjs-only-snippets/fs.test.js @@ -1,6 +1,12 @@ -import { describe, it, expect } from "bun:test"; +import { describe, it, expect } from "vitest"; import { mkdirSync, existsSync, readFileSync, writeFileSync } from "node:fs"; +const Buffer = globalThis.Buffer || Uint8Array; + +if (!import.meta.dir) { + import.meta.dir = "."; +} + describe("mkdirSync", () => { it("should create a directory", () => { const tempdir = `/tmp/fs.test.js/${Date.now()}/1234/hi`; @@ -18,7 +24,7 @@ describe("readFileSync", () => { expect(text).toBe("File read successfully"); }); - it("returning Uint8Array works", () => { + it("returning Buffer 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, @@ -38,8 +44,8 @@ describe("writeFileSync", () => { expect(readFileSync(path, "utf8")).toBe("File written successfully"); }); - it("returning Uint8Array works", () => { - const buffer = new Uint8Array([ + it("returning Buffer works", () => { + const buffer = new Buffer([ 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, ]); @@ -52,12 +58,12 @@ describe("writeFileSync", () => { } }); it("returning ArrayBuffer works", () => { - const buffer = new Uint8Array([ + const buffer = new Buffer([ 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); + writeFileSync(path, buffer); const out = readFileSync(path); for (let i = 0; i < buffer.length; i++) { |