Skip to content

Commit

Permalink
stub Deno.stdin.isTerminal()
Browse files Browse the repository at this point in the history
  • Loading branch information
timreichen committed Dec 13, 2024
1 parent a8326ca commit fdbe7c1
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
4 changes: 4 additions & 0 deletions cli/prompt_secret.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ export function promptSecret(
): string | null {
const { mask = "*", clear } = options ?? {};

if (!input.isTerminal()) {
return null;
}

// Make the output consistent with the built-in prompt()
message += " ";
const callback = !mask ? undefined : (n: number) => {
Expand Down
7 changes: 7 additions & 0 deletions cli/prompt_secret_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const decoder = new TextDecoder();

Deno.test("promptSecret() handles CR", () => {
stub(Deno.stdin, "setRaw");
stub(Deno.stdin, "isTerminal", () => true);

const expectedOutput = [
"Please provide the password: ",
Expand Down Expand Up @@ -52,6 +53,7 @@ Deno.test("promptSecret() handles CR", () => {

Deno.test("promptSecret() handles LF", () => {
stub(Deno.stdin, "setRaw");
stub(Deno.stdin, "isTerminal", () => true);

const expectedOutput = [
"Please provide the password: ",
Expand Down Expand Up @@ -95,6 +97,7 @@ Deno.test("promptSecret() handles LF", () => {

Deno.test("promptSecret() handles input", () => {
stub(Deno.stdin, "setRaw");
stub(Deno.stdin, "isTerminal", () => true);

const expectedOutput = [
"Please provide the password: ",
Expand Down Expand Up @@ -151,6 +154,7 @@ Deno.test("promptSecret() handles input", () => {

Deno.test("promptSecret() handles DEL", () => {
stub(Deno.stdin, "setRaw");
stub(Deno.stdin, "isTerminal", () => true);

const expectedOutput = [
"Please provide the password: ",
Expand Down Expand Up @@ -213,6 +217,7 @@ Deno.test("promptSecret() handles DEL", () => {

Deno.test("promptSecret() handles BS", () => {
stub(Deno.stdin, "setRaw");
stub(Deno.stdin, "isTerminal", () => true);

const expectedOutput = [
"Please provide the password: ",
Expand Down Expand Up @@ -275,6 +280,7 @@ Deno.test("promptSecret() handles BS", () => {

Deno.test("promptSecret() handles clear option", () => {
stub(Deno.stdin, "setRaw");
stub(Deno.stdin, "isTerminal", () => true);

const expectedOutput = [
"Please provide the password: ",
Expand Down Expand Up @@ -333,6 +339,7 @@ Deno.test("promptSecret() handles clear option", () => {

Deno.test("promptSecret() handles mask option", () => {
stub(Deno.stdin, "setRaw");
stub(Deno.stdin, "isTerminal", () => true);

const expectedOutput = [
"Please provide the password: ",
Expand Down

0 comments on commit fdbe7c1

Please sign in to comment.