This commit is contained in:
Jarred Sumner
2024-03-08 04:56:06 -08:00
parent fa12b0014b
commit 49bcae6196
2 changed files with 21 additions and 12 deletions

View File

@@ -0,0 +1,19 @@
const { writeFileSync, createReadStream } = require("fs");
const { join } = require("path");
const { tmpdir } = require("os");
// This test should fail if ot doesn't go through the "readable" event
process.exitCode = 1;
const testData = new Uint8Array(parseInt(process.env.READABLE_SIZE || (1024 * 1024).toString(10))).fill("a");
const path = join(tmpdir(), `${Date.now()}-testEmitReadableOnEnd.txt`);
writeFileSync(path, testData);
const stream = createReadStream(path);
stream.on("readable", () => {
const chunk = stream.read();
if (!chunk) {
process.exitCode = 0;
}
});

View File

@@ -188,18 +188,8 @@ describe("createReadStream", () => {
});
});
it("should emit readable on end", done => {
const testData = "Hello world";
const path = join(tmpdir(), `${Date.now()}-testEmitReadableOnEnd.txt`);
writeFileSync(path, testData);
const stream = createReadStream(path);
stream.on("readable", () => {
const chunk = stream.read();
if (!chunk) {
done();
}
});
it("should emit readable on end", () => {
expect([join(import.meta.dir, "emit-readable-on-end.js")]).toRun();
});
});