mirror of
https://github.com/denoland/deno.git
synced 2025-03-04 01:44:26 -05:00
feat(std/node) stub out process.stdin, stdout, stderr (#7184)
This commit is contained in:
parent
e4188f7dfb
commit
cead79f5b8
2 changed files with 95 additions and 1 deletions
|
@ -38,6 +38,67 @@ export const process = {
|
||||||
platform,
|
platform,
|
||||||
version,
|
version,
|
||||||
versions,
|
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 */
|
/** https://nodejs.org/api/process.html#process_process_events */
|
||||||
// on is not exported by node, it is only available within process:
|
// on is not exported by node, it is only available within process:
|
||||||
|
|
|
@ -18,8 +18,11 @@ Deno.test({
|
||||||
allKeys.delete("process");
|
allKeys.delete("process");
|
||||||
// without esm default
|
// without esm default
|
||||||
allKeys.delete("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("on");
|
||||||
|
allKeys.add("stdin");
|
||||||
|
allKeys.add("stderr");
|
||||||
|
allKeys.add("stdout");
|
||||||
const allStr = Array.from(allKeys).sort().join(" ");
|
const allStr = Array.from(allKeys).sort().join(" ");
|
||||||
assertEquals(Object.keys(all.default).sort().join(" "), allStr);
|
assertEquals(Object.keys(all.default).sort().join(" "), allStr);
|
||||||
assertEquals(Object.keys(all.process).sort().join(" "), allStr);
|
assertEquals(Object.keys(all.process).sort().join(" "), allStr);
|
||||||
|
@ -130,3 +133,33 @@ Deno.test({
|
||||||
assertEquals(typeof env.PATH, "string");
|
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);
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
Loading…
Add table
Reference in a new issue