Files
bun.sh/test/js/node/async_hooks/async-context/async-context-fs-fstat.js
Jarred Sumner e1505b7143 Use JSC::Integrity:: auditCellFully in bindings (#22538)
### What does this PR do?

### How did you verify your code works?
2025-09-10 00:31:54 -07:00

32 lines
836 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"), "fstat-test-" + Date.now() + ".txt");
fs.writeFileSync(testFile, "test");
asyncLocalStorage.run({ test: "fs.fstat" }, () => {
fs.open(testFile, "r", (err, fd) => {
if (err) {
console.error("ERROR:", err);
process.exit(1);
}
fs.fstat(fd, (err, stats) => {
if (asyncLocalStorage.getStore()?.test !== "fs.fstat") {
console.error("FAIL: fs.fstat callback lost context");
fs.closeSync(fd);
fs.unlinkSync(testFile);
process.exit(1);
}
fs.closeSync(fd);
fs.unlinkSync(testFile);
process.exit(0);
});
});
});