aboutsummaryrefslogtreecommitdiff
path: root/test/bun.js/console-iterator.test.js
diff options
context:
space:
mode:
authorGravatar Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> 2022-12-05 11:35:34 -0800
committerGravatar Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> 2022-12-05 11:35:34 -0800
commit0ea8de40871052842f2e342b4c452f6746691487 (patch)
treea4e1028f90a801324966172e47b9b20533e4ad7a /test/bun.js/console-iterator.test.js
parent71293033474eea83c47b6c6948f991b1dc37ad22 (diff)
downloadbun-0ea8de40871052842f2e342b4c452f6746691487.tar.gz
bun-0ea8de40871052842f2e342b4c452f6746691487.tar.zst
bun-0ea8de40871052842f2e342b4c452f6746691487.zip
Make `console` an `AsyncIterable`
Diffstat (limited to 'test/bun.js/console-iterator.test.js')
-rw-r--r--test/bun.js/console-iterator.test.js64
1 files changed, 64 insertions, 0 deletions
diff --git a/test/bun.js/console-iterator.test.js b/test/bun.js/console-iterator.test.js
new file mode 100644
index 000000000..c211fe8e6
--- /dev/null
+++ b/test/bun.js/console-iterator.test.js
@@ -0,0 +1,64 @@
+import { spawnSync, spawn } from "bun";
+import { describe, expect, it } from "bun:test";
+import { bunExe } from "bunExe";
+
+describe("should work for static input", () => {
+ const inputs = [
+ "hello world",
+ "hello world\n",
+ "hello world\n\n",
+ "hello world\n\n\n",
+ "Hello\nWorld\n",
+ "1",
+ "❤️ Red Heart ✨ Sparkles 🔥 Fire\n❤️ Red Heart ✨ Sparkles\n❤️ Red Heart\n❤️\n\nnormal",
+ ];
+
+ for (let input of inputs) {
+ it(input.replaceAll("\n", "\\n"), () => {
+ const { stdout } = spawnSync({
+ cmd: [bunExe(), import.meta.dir + "/" + "console-iterator-run.js"],
+ stdin: Buffer.from(input),
+ env: {
+ BUN_DEBUG_QUIET_LOGS: "1",
+ },
+ });
+ expect(stdout.toString()).toBe(input.replaceAll("\n", ""));
+ });
+ }
+});
+
+describe("should work for streaming input", () => {
+ const inputs = [
+ "hello world",
+ "hello world\n",
+ "hello world\n\n",
+ "hello world\n\n\n",
+ "Hello\nWorld\n",
+ "1",
+ "❤️ Red Heart ✨ Sparkles 🔥 Fire\n❤️ Red Heart ✨ Sparkles\n❤️ Red Heart\n❤️\n\nnormal",
+ ];
+
+ for (let input of inputs) {
+ it(input.replaceAll("\n", "\\n"), async () => {
+ const { stdout, stdin } = spawn({
+ cmd: [bunExe(), import.meta.dir + "/" + "console-iterator-run.js"],
+ stdin: "pipe",
+ stdout: "pipe",
+ env: {
+ BUN_DEBUG_QUIET_LOGS: "1",
+ },
+ });
+ stdin.write(input.slice(0, 4));
+ await new Promise((resolve) => setTimeout(resolve, 1));
+ stdin.write(input.slice(4, 5));
+ await new Promise((resolve) => setTimeout(resolve, 1));
+ stdin.write(input.slice(5));
+ await new Promise((resolve) => setTimeout(resolve, 1));
+ stdin.end();
+
+ expect(await new Response(stdout).text()).toBe(
+ input.replaceAll("\n", ""),
+ );
+ });
+ }
+});