From d26addeca147e076d7a5e2c7fe14febdd658393f Mon Sep 17 00:00:00 2001 From: Dylan Conway <35280289+dylan-conway@users.noreply.github.com> Date: Fri, 15 Sep 2023 01:39:42 -0700 Subject: dup and close file descriptors (#5341) * track one shot fds * dup fd * skip for rearm on mac * dup if fd * cleanup * force unregister on close * deinitForceUnregister * test * add prompts --------- Co-authored-by: Jarred Sumner --- test/js/third_party/prompts/prompts.js | 25 +++++++++++++++++++++++++ test/js/third_party/prompts/prompts.test.ts | 28 ++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+) create mode 100644 test/js/third_party/prompts/prompts.js create mode 100644 test/js/third_party/prompts/prompts.test.ts (limited to 'test/js') 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"'); +}); -- cgit v1.2.3