aboutsummaryrefslogtreecommitdiff
path: root/test/js
diff options
context:
space:
mode:
Diffstat (limited to 'test/js')
-rw-r--r--test/js/third_party/prompts/prompts.js25
-rw-r--r--test/js/third_party/prompts/prompts.test.ts28
2 files changed, 53 insertions, 0 deletions
diff --git a/test/js/third_party/prompts/prompts.js b/test/js/third_party/prompts/prompts.js
new file mode 100644
index 000000000..bf96ba26e
--- /dev/null
+++ b/test/js/third_party/prompts/prompts.js
@@ -0,0 +1,25 @@
+import prompt from "prompts";
+
+const questions = [
+ {
+ type: "text",
+ name: "twitter",
+ message: `What's your twitter handle?`,
+ format: v => `@${v}`,
+ },
+ {
+ type: "number",
+ name: "age",
+ message: "How old are you?",
+ validate: value => (value < 18 ? `Sorry, you have to be 18` : true),
+ },
+ {
+ type: "password",
+ name: "secret",
+ message: "Tell me a secret",
+ },
+];
+
+const answers = await prompt(questions);
+
+console.log(answers);
diff --git a/test/js/third_party/prompts/prompts.test.ts b/test/js/third_party/prompts/prompts.test.ts
new file mode 100644
index 000000000..9c62456f5
--- /dev/null
+++ b/test/js/third_party/prompts/prompts.test.ts
@@ -0,0 +1,28 @@
+import path from "path";
+import { bunExe, bunEnv } from "harness";
+
+test("works with prompts", async () => {
+ var child = Bun.spawn({
+ cmd: [bunExe(), path.join(import.meta.dir, "prompts.js")],
+ env: bunEnv,
+ stdout: "pipe",
+ stdin: "pipe",
+ });
+
+ child.stdin.write("dylan\n");
+ Bun.sleepSync(100);
+ child.stdin.write("999\n");
+ Bun.sleepSync(100);
+ child.stdin.write("hi\n");
+
+ var out = "";
+ for await (const chunk of child.stdout) {
+ out += new TextDecoder().decode(chunk);
+ }
+
+ expect(await child.exited).toBe(0);
+
+ expect(out).toContain('twitter: "@dylan"');
+ expect(out).toContain("age: 999");
+ expect(out).toContain('secret: "hi"');
+});