diff options
author | 2023-02-17 17:02:55 -0800 | |
---|---|---|
committer | 2023-02-17 17:02:55 -0800 | |
commit | e542d9b4ed144adbb9dc16db2e29a04556535724 (patch) | |
tree | 0f107d8e88a2a74873918427aa8d9644d1c9be12 | |
parent | fb313f210a51387fd77e0ddf4172ee3b52d0bdc9 (diff) | |
download | bun-e542d9b4ed144adbb9dc16db2e29a04556535724.tar.gz bun-e542d9b4ed144adbb9dc16db2e29a04556535724.tar.zst bun-e542d9b4ed144adbb9dc16db2e29a04556535724.zip |
Fix flaky test
-rw-r--r-- | test/bun.js/fs.test.js | 37 |
1 files changed, 19 insertions, 18 deletions
diff --git a/test/bun.js/fs.test.js b/test/bun.js/fs.test.js index 5e4827672..9408a7e64 100644 --- a/test/bun.js/fs.test.js +++ b/test/bun.js/fs.test.js @@ -29,10 +29,7 @@ import fs, { import { tmpdir } from "node:os"; import { join } from "node:path"; -import { - ReadStream as ReadStream_, - WriteStream as WriteStream_, -} from "../fixtures/export-lazy-fs-streams/export-from"; +import { ReadStream as ReadStream_, WriteStream as WriteStream_ } from "../fixtures/export-lazy-fs-streams/export-from"; import { ReadStream as ReadStreamStar_, WriteStream as WriteStreamStar_, @@ -44,6 +41,10 @@ if (!import.meta.dir) { import.meta.dir = "."; } +function mkdirForce(path) { + if (!existsSync(path)) mkdirSync(path, { recursive: true }); +} + describe("copyFileSync", () => { it("should work for files < 128 KB", () => { const tempdir = `/tmp/fs.test.js/${Date.now()}/1234/hi`; @@ -624,16 +625,16 @@ describe("fs.WriteStream", () => { expect(stream instanceof fs.WriteStream).toBe(true); }); - it("should be able to write to a file", (done) => { + it("should be able to write to a file", done => { const pathToDir = `${tmpdir()}/${Date.now()}`; - mkdirSync(pathToDir); + mkdirForce(pathToDir); const path = `${pathToDir}/fs-writestream-test.txt`; const stream = new fs.WriteStream(path, { flags: "w+" }); stream.write("Test file written successfully"); stream.end(); - stream.on("error", (e) => { + stream.on("error", e => { done(e instanceof Error ? e : new Error(e)); }); @@ -671,16 +672,16 @@ describe("fs.WriteStream", () => { expect(stream instanceof fs.WriteStream).toBe(true); }); - it("should be able to write to a file with re-exported WriteStream", (done) => { + it("should be able to write to a file with re-exported WriteStream", done => { const pathToDir = `${tmpdir()}/${Date.now()}`; - mkdirSync(pathToDir); + mkdirForce(pathToDir); const path = `${pathToDir}/fs-writestream-re-exported-test.txt`; const stream = new WriteStream_(path, { flags: "w+" }); stream.write("Test file written successfully"); stream.end(); - stream.on("error", (e) => { + stream.on("error", e => { done(e instanceof Error ? e : new Error(e)); }); @@ -701,9 +702,9 @@ describe("fs.ReadStream", () => { expect(stream instanceof fs.ReadStream).toBe(true); }); - it("should be able to read from a file", (done) => { + it("should be able to read from a file", done => { const pathToDir = `${tmpdir()}/${Date.now()}`; - mkdirSync(pathToDir); + mkdirForce(pathToDir); const path = `${pathToDir}fs-readstream-test.txt`; writeFileSync(path, "Test file written successfully", { @@ -713,13 +714,13 @@ describe("fs.ReadStream", () => { const stream = new fs.ReadStream(path); stream.setEncoding("utf8"); - stream.on("error", (e) => { + stream.on("error", e => { done(e instanceof Error ? e : new Error(e)); }); let data = ""; - stream.on("data", (chunk) => { + stream.on("data", chunk => { data += chunk; }); @@ -757,9 +758,9 @@ describe("fs.ReadStream", () => { expect(stream instanceof fs.ReadStream).toBe(true); }); - it("should be able to read from a file, with re-exported ReadStream", (done) => { + it("should be able to read from a file, with re-exported ReadStream", done => { const pathToDir = `${tmpdir()}/${Date.now()}`; - mkdirSync(pathToDir); + mkdirForce(pathToDir); const path = `${pathToDir}fs-readstream-re-exported-test.txt`; writeFileSync(path, "Test file written successfully", { @@ -769,13 +770,13 @@ describe("fs.ReadStream", () => { const stream = new ReadStream_(path); stream.setEncoding("utf8"); - stream.on("error", (e) => { + stream.on("error", e => { done(e instanceof Error ? e : new Error(e)); }); let data = ""; - stream.on("data", (chunk) => { + stream.on("data", chunk => { data += chunk; }); |