Skip to content

Commit

Permalink
Add ref and unref to stdin mock (#23)
Browse files Browse the repository at this point in the history
  • Loading branch information
threepointone authored Sep 12, 2023
1 parent d3c66f6 commit f44b077
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion source/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,16 @@ class Stderr extends EventEmitter {
class Stdin extends EventEmitter {
// eslint-disable-next-line @typescript-eslint/naming-convention
isTTY = true;
data: string | null = null;
constructor(options: {isTTY?: boolean} = {}) {
super();
this.isTTY = options.isTTY ?? true;
}

write = (data: string) => {
this.emit('data', data);
this.data = data;
this.emit('readable');
// this.emit('data', data);
};

setEncoding() {
Expand All @@ -54,6 +61,22 @@ class Stdin extends EventEmitter {
pause() {
// Do nothing
}

ref() {
// Do nothing
}

unref() {
// Do nothing
}

read: () => string | null = () => {
const data = this.data;

this.data = null;

return data;
};
}

type Instance = {
Expand Down

0 comments on commit f44b077

Please sign in to comment.