diff options
author | 2023-09-15 01:39:42 -0700 | |
---|---|---|
committer | 2023-09-15 01:39:42 -0700 | |
commit | d26addeca147e076d7a5e2c7fe14febdd658393f (patch) | |
tree | 65e9669db623ea9201b0dc5176a18925fad6c08b /test | |
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')
-rwxr-xr-x | test/bun.lockb | bin | 157381 -> 163146 bytes | |||
-rw-r--r-- | test/js/third_party/prompts/prompts.js | 25 | ||||
-rw-r--r-- | test/js/third_party/prompts/prompts.test.ts | 28 | ||||
-rw-r--r-- | test/package.json | 1 |
4 files changed, 54 insertions, 0 deletions
diff --git a/test/bun.lockb b/test/bun.lockb Binary files differindex 059054600..a6a467f5b 100755 --- a/test/bun.lockb +++ b/test/bun.lockb 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"'); +}); diff --git a/test/package.json b/test/package.json index bab0e7200..d7ae63d11 100644 --- a/test/package.json +++ b/test/package.json @@ -27,6 +27,7 @@ "pg-connection-string": "2.6.1", "postgres": "3.3.5", "prisma": "5.1.1", + "prompts": "^2.4.2", "socket.io": "4.7.1", "socket.io-client": "4.7.1", "supertest": "6.3.3", |