Skip to content

Commit

Permalink
override process.stdin.on() correctly (#1603)
Browse files Browse the repository at this point in the history
* override `process.stdin.on()` correctly

fixes #1601

* add tests
  • Loading branch information
alexlamsl committed Dec 11, 2022
1 parent 660eb46 commit 780f7de
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/bun.js/builtins/js/ProcessObjectInternals.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
6 changes: 6 additions & 0 deletions test/bun.js/process-stdio.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down

0 comments on commit 780f7de

Please sign in to comment.