Skip to content

Commit

Permalink
feat(node) stub out process.stdin, stdout, stderr (denoland/deno#7184)
Browse files Browse the repository at this point in the history
  • Loading branch information
JayHelton authored and denobot committed Jan 31, 2021
1 parent 8bddcb4 commit d59a595
Show file tree
Hide file tree
Showing 2 changed files with 95 additions and 1 deletion.
61 changes: 61 additions & 0 deletions node/process.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,67 @@ export const process = {
platform,
version,
versions,
get stderr() {
return {
fd: Deno.stderr.rid,
get isTTY(): boolean {
return Deno.isatty(this.fd);
},
pipe(_destination: Deno.Writer, _options: { end: boolean }): void {
// TODO(JayHelton): to be implemented
notImplemented();
},
// eslint-disable-next-line @typescript-eslint/ban-types
write(_chunk: string | Uint8Array, _callback: Function): void {
// TODO(JayHelton): to be implemented
notImplemented();
},
// eslint-disable-next-line @typescript-eslint/ban-types
on(_event: string, _callback: Function): void {
// TODO(JayHelton): to be implemented
notImplemented();
},
};
},
get stdin() {
return {
fd: Deno.stdin.rid,
get isTTY(): boolean {
return Deno.isatty(this.fd);
},
read(_size: number): void {
// TODO(JayHelton): to be implemented
notImplemented();
},
// eslint-disable-next-line @typescript-eslint/ban-types
on(_event: string, _callback: Function): void {
// TODO(JayHelton): to be implemented
notImplemented();
},
};
},
get stdout() {
return {
fd: Deno.stdout.rid,
get isTTY(): boolean {
return Deno.isatty(this.fd);
},
pipe(_destination: Deno.Writer, _options: { end: boolean }): void {
// TODO(JayHelton): to be implemented
notImplemented();
},
// eslint-disable-next-line @typescript-eslint/ban-types
write(_chunk: string | Uint8Array, _callback: Function): void {
// TODO(JayHelton): to be implemented
notImplemented();
},
// eslint-disable-next-line @typescript-eslint/ban-types
on(_event: string, _callback: Function): void {
// TODO(JayHelton): to be implemented
notImplemented();
},
};
},

/** https://nodejs.org/api/process.html#process_process_events */
// on is not exported by node, it is only available within process:
Expand Down
35 changes: 34 additions & 1 deletion node/process_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,11 @@ Deno.test({
allKeys.delete("process");
// without esm default
allKeys.delete("default");
// with on, which is not exported via *
// with on, stdin, stderr, and stdout, which is not exported via *
allKeys.add("on");
allKeys.add("stdin");
allKeys.add("stderr");
allKeys.add("stdout");
const allStr = Array.from(allKeys).sort().join(" ");
assertEquals(Object.keys(all.default).sort().join(" "), allStr);
assertEquals(Object.keys(all.process).sort().join(" "), allStr);
Expand Down Expand Up @@ -130,3 +133,33 @@ Deno.test({
assertEquals(typeof env.PATH, "string");
},
});

Deno.test({
name: "process.stdin",
fn() {
assertEquals(typeof process.stdin.fd, "number");
assertEquals(process.stdin.fd, Deno.stdin.rid);
// TODO(jayhelton) Uncomment out this assertion once PTY is supported
//assert(process.stdin.isTTY);
},
});

Deno.test({
name: "process.stdout",
fn() {
assertEquals(typeof process.stdout.fd, "number");
assertEquals(process.stdout.fd, Deno.stdout.rid);
// TODO(jayhelton) Uncomment out this assertion once PTY is supported
// assert(process.stdout.isTTY);
},
});

Deno.test({
name: "process.stderr",
fn() {
assertEquals(typeof process.stderr.fd, "number");
assertEquals(process.stderr.fd, Deno.stderr.rid);
// TODO(jayhelton) Uncomment out this assertion once PTY is supported
// assert(process.stderr.isTTY);
},
});

0 comments on commit d59a595

Please sign in to comment.