mirror of
https://github.com/oven-sh/bun
synced 2026-02-10 02:48:50 +00:00
Co-authored-by: Jarred-Sumner <709451+Jarred-Sumner@users.noreply.github.com> Co-authored-by: Dylan Conway <dylan.conway567@gmail.com>
38 lines
1.1 KiB
JavaScript
38 lines
1.1 KiB
JavaScript
const { AsyncLocalStorage } = require("async_hooks");
|
|
const fs = require("fs");
|
|
const path = require("path");
|
|
|
|
const asyncLocalStorage = new AsyncLocalStorage();
|
|
const testFile = path.join(fs.mkdtempSync("fstest"), "readstream-test-" + Date.now() + ".txt");
|
|
let failed = false;
|
|
|
|
// Create test file
|
|
fs.writeFileSync(testFile, "test data for read stream");
|
|
|
|
asyncLocalStorage.run({ test: "fs.createReadStream" }, () => {
|
|
const stream = fs.createReadStream(testFile);
|
|
|
|
stream.on("data", chunk => {
|
|
if (asyncLocalStorage.getStore()?.test !== "fs.createReadStream") {
|
|
console.error("FAIL: fs.createReadStream data event lost context");
|
|
failed = true;
|
|
}
|
|
});
|
|
|
|
stream.on("end", () => {
|
|
if (asyncLocalStorage.getStore()?.test !== "fs.createReadStream") {
|
|
console.error("FAIL: fs.createReadStream end event lost context");
|
|
failed = true;
|
|
}
|
|
});
|
|
|
|
stream.on("close", () => {
|
|
if (asyncLocalStorage.getStore()?.test !== "fs.createReadStream") {
|
|
console.error("FAIL: fs.createReadStream close event lost context");
|
|
failed = true;
|
|
}
|
|
fs.unlinkSync(testFile);
|
|
process.exit(failed ? 1 : 0);
|
|
});
|
|
});
|