aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Alex Lam S.L <alexlamsl@gmail.com> 2022-12-11 07:51:02 +0200
committerGravatar GitHub <noreply@github.com> 2022-12-10 21:51:02 -0800
commit780f7de843c42bf9a32f39a1192289c367015138 (patch)
treeeb794d6edff2f726cc63fcc74a04f643953a4568
parent660eb46b17060019de65989e52aabf6994213020 (diff)
downloadbun-780f7de843c42bf9a32f39a1192289c367015138.tar.gz
bun-780f7de843c42bf9a32f39a1192289c367015138.tar.zst
bun-780f7de843c42bf9a32f39a1192289c367015138.zip
override `process.stdin.on()` correctly (#1603)
* override `process.stdin.on()` correctly fixes #1601 * add tests
-rw-r--r--src/bun.js/builtins/js/ProcessObjectInternals.js2
-rw-r--r--test/bun.js/process-stdio.test.ts6
2 files changed, 7 insertions, 1 deletions
diff --git a/src/bun.js/builtins/js/ProcessObjectInternals.js b/src/bun.js/builtins/js/ProcessObjectInternals.js
index bf548eee6..be23220b1 100644
--- a/src/bun.js/builtins/js/ProcessObjectInternals.js
+++ b/src/bun.js/builtins/js/ProcessObjectInternals.js
@@ -511,10 +511,10 @@ function getStdinStream(fd, rawRequire, Bun) {
}
on(ev, cb) {
- super.on(ev, cb);
if (!this.#readStream && (ev === "readable" || ev === "data")) {
this.#loadReadStream();
}
+ return super.on(ev, cb);
}
#loadReadStream() {
diff --git a/test/bun.js/process-stdio.test.ts b/test/bun.js/process-stdio.test.ts
index 886bf9dac..45db37d05 100644
--- a/test/bun.js/process-stdio.test.ts
+++ b/test/bun.js/process-stdio.test.ts
@@ -3,6 +3,12 @@ import { describe, expect, it, test } from "bun:test";
import { bunExe } from "bunExe";
import { isatty } from "tty";
+test("process.stdin", () => {
+ expect(process.stdin).toBeDefined();
+ expect(process.stdin.on("close", function() {})).toBe(process.stdin);
+ expect(process.stdin.once("end", function() {})).toBe(process.stdin);
+});
+
test("process.stdout", () => {
expect(process.stdout).toBeDefined();
expect(process.stdout.isTTY).toBe(isatty(1));