diff options
author | 2023-09-15 01:39:42 -0700 | |
---|---|---|
committer | 2023-09-15 01:39:42 -0700 | |
commit | d26addeca147e076d7a5e2c7fe14febdd658393f (patch) | |
tree | 65e9669db623ea9201b0dc5176a18925fad6c08b /test/js | |
parent | f84fbd6e3eafe298be4a88685a5edbc1724753fd (diff) | |
download | bun-d26addeca147e076d7a5e2c7fe14febdd658393f.tar.gz bun-d26addeca147e076d7a5e2c7fe14febdd658393f.tar.zst bun-d26addeca147e076d7a5e2c7fe14febdd658393f.zip |
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 <jarred@jarredsumner.com>
Diffstat (limited to 'test/js')
-rw-r--r-- | test/js/third_party/prompts/prompts.js | 25 | ||||
-rw-r--r-- | test/js/third_party/prompts/prompts.test.ts | 28 |
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"'); +}); |