Compare commits

...

2 Commits

Author SHA1 Message Date
autofix-ci[bot]
1a98b8d37e [autofix.ci] apply automated fixes 2025-08-27 03:43:16 +00:00
Claude Bot
df3ea74d3c fix: node:fs/promises methods now return proper Promise instances (#22167)
Fixed issue where promises returned by node:fs/promises methods like
readFile() would fail instanceof Promise checks. The problem was that
wrapInternalPromise was creating JSInternalPromise objects instead of
proper JSPromise objects with the correct prototype chain.

Changes:
- Added new C++ wrapper function to create JSPromise from JSInternalPromise
- Updated wrapInternalPromise to use proper Promise constructor
- Added comprehensive test for instanceof checks on fs/promises methods

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-08-27 03:41:37 +00:00

View File

@@ -0,0 +1,39 @@
import { expect, test } from "bun:test";
import { tempDirWithFiles } from "harness";
import { mkdir, readFile, stat, writeFile } from "node:fs/promises";
import { join } from "path";
test("fs/promises methods return actual Promise instances", async () => {
const dir = tempDirWithFiles("fs-promises-instanceof", {
"test.txt": "test content",
});
const testFile = join(dir, "test.txt");
// Test readFile
const readResult = readFile(testFile);
expect(readResult instanceof Promise).toBe(true);
expect(readResult.constructor).toBe(Promise);
expect(Object.prototype.toString.call(readResult)).toBe("[object Promise]");
// Test writeFile
const writeResult = writeFile(join(dir, "write-test.txt"), "content");
expect(writeResult instanceof Promise).toBe(true);
expect(writeResult.constructor).toBe(Promise);
// Test stat
const statResult = stat(testFile);
expect(statResult instanceof Promise).toBe(true);
expect(statResult.constructor).toBe(Promise);
// Test mkdir
const mkdirResult = mkdir(join(dir, "new-dir"));
expect(mkdirResult instanceof Promise).toBe(true);
expect(mkdirResult.constructor).toBe(Promise);
// Ensure promises actually resolve correctly
await readResult;
await writeResult;
await statResult;
await mkdirResult;
});