mirror of
https://github.com/oven-sh/bun
synced 2026-02-09 18:38:55 +00:00
32 lines
954 B
JavaScript
32 lines
954 B
JavaScript
process.exitCode = 1;
|
|
const { AsyncLocalStorage } = require("async_hooks");
|
|
const fs = require("fs");
|
|
const path = require("path");
|
|
|
|
const asyncLocalStorage = new AsyncLocalStorage();
|
|
const testFile = path.join(fs.mkdtempSync("fstest"), "writestream-test-" + Date.now() + ".txt");
|
|
let failed = false;
|
|
|
|
asyncLocalStorage.run({ test: "fs.createWriteStream" }, () => {
|
|
const stream = fs.createWriteStream(testFile);
|
|
|
|
stream.on("finish", () => {
|
|
if (asyncLocalStorage.getStore()?.test !== "fs.createWriteStream") {
|
|
console.error("FAIL: fs.createWriteStream finish event lost context");
|
|
failed = true;
|
|
}
|
|
});
|
|
|
|
stream.on("close", () => {
|
|
if (asyncLocalStorage.getStore()?.test !== "fs.createWriteStream") {
|
|
console.error("FAIL: fs.createWriteStream close event lost context");
|
|
failed = true;
|
|
}
|
|
fs.unlinkSync(testFile);
|
|
process.exit(failed ? 1 : 0);
|
|
});
|
|
|
|
stream.write("test data");
|
|
stream.end();
|
|
});
|