Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(prompt): add integration tests (#172)
- Loading branch information
Showing
43 changed files
with
322 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
\x1bd\x1bd\x1b |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
? Select an option | ||
❯ ✘ Foo | ||
✘ Bar | ||
✘ Baz\x1b[3A\x1b[20G\x1b[?25l\x1b[G\x1b[0J ? Select an option | ||
✔ Foo | ||
❯ ✘ Bar | ||
✘ Baz\x1b[3A\x1b[20G\x1b[?25l\x1b[G\x1b[0J ? Select an option | ||
✔ Foo | ||
✘ Bar | ||
❯ ✔ Baz\x1b[3A\x1b[20G\x1b[?25l\x1b[G\x1b[0J ? Select an option › Foo, Baz | ||
\x1b[?25h\x1b[?25h |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { Checkbox } from "../../../checkbox.ts"; | ||
|
||
await Checkbox.prompt({ | ||
message: "Select an option", | ||
options: [ | ||
{ name: "Foo", value: "foo" }, | ||
{ name: "Bar", value: "bar" }, | ||
{ name: "Baz", value: "baz" }, | ||
], | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
? Select an option | ||
❯ × Foo | ||
× Bar | ||
× Baz\x1b[3A\x1b[20G\x1b[?25l\x1b[G\x1b[0J ? Select an option | ||
√ Foo | ||
❯ × Bar | ||
× Baz\x1b[3A\x1b[20G\x1b[?25l\x1b[G\x1b[0J ? Select an option | ||
√ Foo | ||
× Bar | ||
❯ √ Baz\x1b[3A\x1b[20G\x1b[?25l\x1b[G\x1b[0J ? Select an option » Foo, Baz | ||
\x1b[?25h\x1b[?25h |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
y |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
? Please confirm (y/N) › | ||
❯ some hint\x1b[1A\x1b[27G\x1b[G\x1b[0J ? Please confirm (y/N) › Yes | ||
\x1b[?25h\x1b[?25h |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { Confirm } from "../../../confirm.ts"; | ||
|
||
await Confirm.prompt({ | ||
message: "Please confirm", | ||
hint: "some hint", | ||
default: false, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
? Please confirm (y/N) » | ||
❯ some hint\x1b[1A\x1b[27G\x1b[G\x1b[0J ? Please confirm (y/N) » Yes | ||
\x1b[?25h\x1b[?25h |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
bar |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
? Whats your name? (foo) › \x1b[29G\x1b[G\x1b[0J ? Whats your name? (foo) › bar | ||
\x1b[?25h\x1b[?25h |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { Input } from "../../../input.ts"; | ||
|
||
await Input.prompt({ | ||
message: "Whats your name?", | ||
default: "foo", | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
? Whats your name? (foo) » \x1b[29G\x1b[G\x1b[0J ? Whats your name? (foo) » bar | ||
\x1b[?25h\x1b[?25h |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
foo |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
? Whats your name? (foo) › | ||
foo | ||
bar | ||
baz\x1b[3A\x1b[29G\x1b[G\x1b[0J ? Whats your name? (foo) › foo | ||
\x1b[?25h\x1b[?25h |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { Input } from "../../../input.ts"; | ||
|
||
await Input.prompt({ | ||
message: "Whats your name?", | ||
default: "foo", | ||
suggestions: ["foo", "bar", "baz"], | ||
list: true, | ||
}); |
5 changes: 5 additions & 0 deletions
5
prompt/test/integration/fixtures/input_suggestions.windows.out
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
? Whats your name? (foo) » | ||
foo | ||
bar | ||
baz\x1b[3A\x1b[29G\x1b[G\x1b[0J ? Whats your name? (foo) » foo | ||
\x1b[?25h\x1b[?25h |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
bar, foo |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
? Enter some keywords (foo, far) › | ||
❯ some hint...\x1b[1A\x1b[37G\x1b[G\x1b[0J ? Enter some keywords (foo, far) › bar, foo | ||
❯ some hint...\x1b[1A\x1b[45G\x1b[G\x1b[0J ? Enter some keywords (foo, far) › bar, foo | ||
\x1b[?25h\x1b[?25h |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { List } from "../../../list.ts"; | ||
|
||
await List.prompt({ | ||
message: "Enter some keywords", | ||
default: ["foo", "far"], | ||
hint: "some hint...", | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
? Enter some keywords (foo, far) » | ||
❯ some hint...\x1b[1A\x1b[37G\x1b[G\x1b[0J ? Enter some keywords (foo, far) » bar, foo | ||
❯ some hint...\x1b[1A\x1b[45G\x1b[G\x1b[0J ? Enter some keywords (foo, far) » bar, foo | ||
\x1b[?25h\x1b[?25h |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
19uu | ||
dddd | ||
uuu |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
? How old are you? (7) › \x1b[27G\x1b[G\x1b[0J ? How old are you? (7) › 18 | ||
✘ Value must be lower or equal than 20\x1b[1A\x1b[28G\x1b[G\x1b[0J ? How old are you? (7) › 20 | ||
\x1b[?25h\x1b[?25h |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { Number } from "../../../number.ts"; | ||
|
||
await Number.prompt({ | ||
message: "How old are you?", | ||
default: 7, | ||
max: 20, | ||
min: 18, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
? How old are you? (7) » \x1b[27G\x1b[G\x1b[0J ? How old are you? (7) » 19 | ||
× Value must be lower or equal than 20\x1b[1A\x1b[28G\x1b[G\x1b[0J ? How old are you? (7) » 20 | ||
\x1b[?25h\x1b[?25h |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
19.uuuu |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
? How old are you? (7) › \x1b[27G\x1b[G\x1b[0J ? How old are you? (7) › 19.4 | ||
\x1b[?25h\x1b[?25h |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { Number } from "../../../number.ts"; | ||
|
||
await Number.prompt({ | ||
message: "How old are you?", | ||
default: 7, | ||
max: 20, | ||
min: 18, | ||
float: true, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
? How old are you? (7) » \x1b[27G\x1b[G\x1b[0J ? How old are you? (7) » 19.4 | ||
\x1b[?25h\x1b[?25h |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
123 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
? enter your secret › \x1b[24G\x1b[G\x1b[0J ? enter your secret › *** | ||
\x1b[?25h\x1b[?25h |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { Secret } from "../../../secret.ts"; | ||
|
||
await Secret.prompt({ | ||
message: "enter your secret", | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
? enter your secret » \x1b[24G\x1b[G\x1b[0J ? enter your secret » *** | ||
\x1b[?25h\x1b[?25h |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
\x1bd\x1bd |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
? Select an option | ||
❯ Foo | ||
Bar | ||
Baz\x1b[3A\x1b[20G\x1b[?25l\x1b[G\x1b[0J ? Select an option | ||
Foo | ||
❯ Bar | ||
Baz\x1b[3A\x1b[20G\x1b[?25l\x1b[G\x1b[0J ? Select an option › Baz | ||
\x1b[?25h\x1b[?25h |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { Select } from "../../../select.ts"; | ||
|
||
await Select.prompt({ | ||
message: "Select an option", | ||
options: [ | ||
{ name: "Foo", value: "foo" }, | ||
{ name: "Bar", value: "bar" }, | ||
{ name: "Baz", value: "baz" }, | ||
], | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
? Select an option | ||
❯ Foo | ||
Bar | ||
Baz\x1b[3A\x1b[20G\x1b[?25l\x1b[G\x1b[0J ? Select an option | ||
Foo | ||
❯ Bar | ||
Baz\x1b[3A\x1b[20G\x1b[?25l\x1b[G\x1b[0J ? Select an option » Baz | ||
\x1b[?25h\x1b[?25h |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
yny | ||
- suggestions | ||
- hidden |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
? Please confirm (No) › No / Yes | ||
❯ some hint\x1b[1A\x1b[0G\x1b[?25l\x1b[G\x1b[0J ? Please confirm (No) › Yes | ||
\x1b[?25h\x1b[?25h |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { Toggle } from "../../../toggle.ts"; | ||
|
||
await Toggle.prompt({ | ||
message: "Please confirm", | ||
hint: "some hint", | ||
default: false, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
? Please confirm (No) » No / Yes | ||
❯ some hint\x1b[1A\x1b[0G\x1b[?25l\x1b[G\x1b[0J ? Please confirm (No) » Yes | ||
\x1b[?25h\x1b[?25h |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import { | ||
assert, | ||
assertEquals, | ||
dirname, | ||
expandGlob, | ||
WalkEntry, | ||
} from "../../../dev_deps.ts"; | ||
|
||
const baseDir = `${dirname(import.meta.url).replace("file://", "")}`; | ||
|
||
for await (const file: WalkEntry of expandGlob(`${baseDir}/fixtures/*.ts`)) { | ||
if (file.isFile) { | ||
const name = file.name.replace(/_/g, " ").replace(".ts", ""); | ||
Deno.test({ | ||
name: `prompt - integration - ${name}`, | ||
async fn() { | ||
const output: string = await runPrompt(file); | ||
const expectedOutput: string = await getExpectedOutput(file.path); | ||
assertEquals( | ||
output, | ||
expectedOutput | ||
.replace(/\\x1b/g, "\x1b") | ||
.replace(/\r\n/g, "\n"), | ||
); | ||
}, | ||
}); | ||
} | ||
} | ||
|
||
async function getExpectedOutput(path: string) { | ||
const osOutputPath = path.replace(/\.ts$/, `.${Deno.build.os}.out`); | ||
try { | ||
return await Deno.readTextFile(osOutputPath); | ||
} catch (_) { | ||
const outputPath = path.replace(/\.ts$/, ".out"); | ||
return await Deno.readTextFile(outputPath); | ||
} | ||
} | ||
|
||
async function runPrompt(file: WalkEntry): Promise<string> { | ||
const inputPath: string = file.path.replace(/\.ts$/, ".in"); | ||
const inputFile = await Deno.open(inputPath); | ||
const process = Deno.run({ | ||
stdin: "piped", | ||
stdout: "piped", | ||
cmd: [ | ||
"deno", | ||
"run", | ||
"--unstable", | ||
"--allow-all", | ||
file.path, | ||
], | ||
env: { | ||
NO_COLOR: "true", | ||
}, | ||
}); | ||
|
||
const [output, bytesCopied] = await Promise.all([ | ||
process.output(), | ||
Deno.copy(inputFile, process.stdin), | ||
]); | ||
inputFile.close(); | ||
process.stdin.close(); | ||
process.close(); | ||
|
||
assert(bytesCopied > 0, "No bytes copied"); | ||
|
||
return new TextDecoder().decode(output); | ||
} |
Oops, something went wrong.