aboutsummaryrefslogtreecommitdiff
path: root/test/bun.js/console
diff options
context:
space:
mode:
Diffstat (limited to 'test/bun.js/console')
-rw-r--r--test/bun.js/console/console-iterator-run.js3
-rw-r--r--test/bun.js/console/console-iterator.test.js65
-rw-r--r--test/bun.js/console/console-log.expected.txt46
-rw-r--r--test/bun.js/console/console-log.js64
-rw-r--r--test/bun.js/console/console-log.test.ts18
5 files changed, 196 insertions, 0 deletions
diff --git a/test/bun.js/console/console-iterator-run.js b/test/bun.js/console/console-iterator-run.js
new file mode 100644
index 000000000..7664c85a1
--- /dev/null
+++ b/test/bun.js/console/console-iterator-run.js
@@ -0,0 +1,3 @@
+for await (const line of console) {
+ console.write(line);
+}
diff --git a/test/bun.js/console/console-iterator.test.js b/test/bun.js/console/console-iterator.test.js
new file mode 100644
index 000000000..533f084e1
--- /dev/null
+++ b/test/bun.js/console/console-iterator.test.js
@@ -0,0 +1,65 @@
+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 proc = spawn({
+ cmd: [bunExe(), import.meta.dir + "/" + "console-iterator-run.js"],
+ stdin: "pipe",
+ stdout: "pipe",
+ env: {
+ BUN_DEBUG_QUIET_LOGS: "1",
+ },
+ });
+ const { stdout, stdin } = proc;
+ stdin.write(input.slice(0, (input.length / 2) | 0));
+ stdin.flush();
+ await new Promise((resolve) => setTimeout(resolve, 1));
+ stdin.write(input.slice((input.length / 2) | 0));
+ stdin.flush();
+ stdin.end();
+
+ expect(await new Response(stdout).text()).toBe(
+ input.replaceAll("\n", ""),
+ );
+ proc.kill(0);
+ });
+ }
+});
diff --git a/test/bun.js/console/console-log.expected.txt b/test/bun.js/console/console-log.expected.txt
new file mode 100644
index 000000000..69fb3eeba
--- /dev/null
+++ b/test/bun.js/console/console-log.expected.txt
@@ -0,0 +1,46 @@
+Hello World!
+123
+-123
+123.567
+-123.567
+true
+false
+null
+undefined
+Symbol(Symbol Description)
+2022-02-27T05:11:48.999Z
+[ 123, 456, 789 ]
+{
+ name: "foo"
+}
+{
+ a: 123,
+ b: 456,
+ c: 789
+}
+{
+ a: {
+ b: {
+ c: 123
+ },
+ bacon: true
+ },
+ name: "bar"
+}
+Promise { <pending> }
+[Function]
+[Function: Foo]
+{}
+[Function: foooo]
+/FooRegex/
+Is it a bug or a feature that formatting numbers like 123 is colored
+String 123 should be 2nd word, 456 == 456 and percent s %s == What okay
+{
+ foo: {
+ name: "baz"
+ },
+ bar: [Circular]
+} am
+[
+ {}, {}, {}, {}
+]
diff --git a/test/bun.js/console/console-log.js b/test/bun.js/console/console-log.js
new file mode 100644
index 000000000..c22303371
--- /dev/null
+++ b/test/bun.js/console/console-log.js
@@ -0,0 +1,64 @@
+console.log("Hello World!");
+console.log(123);
+console.log(-123);
+console.log(123.567);
+console.log(-123.567);
+console.log(true);
+console.log(false);
+console.log(null);
+console.log(undefined);
+console.log(Symbol("Symbol Description"));
+console.log(new Date(2021, 12, 30, 666, 777, 888, 999));
+console.log([123, 456, 789]);
+console.log({ name: "foo" });
+console.log({ a: 123, b: 456, c: 789 });
+console.log({
+ a: {
+ b: {
+ c: 123,
+ },
+ bacon: true,
+ },
+ name: "bar",
+});
+
+console.log(new Promise(() => {}));
+
+class Foo {}
+
+console.log(() => {});
+console.log(Foo);
+console.log(new Foo());
+console.log(function foooo() {});
+
+console.log(/FooRegex/);
+
+console.error("uh oh");
+console.time("Check");
+
+console.log(
+ "Is it a bug or a feature that formatting numbers like %d is colored",
+ 123,
+);
+//console.log(globalThis);
+
+console.log(
+ "String %s should be 2nd word, 456 == %s and percent s %s == %s",
+ "123",
+ "456",
+ "%s",
+ "What",
+ "okay",
+);
+
+const infinteLoop = {
+ foo: {
+ name: "baz",
+ },
+ bar: {},
+};
+
+infinteLoop.bar = infinteLoop;
+console.log(infinteLoop, "am");
+
+console.log(new Array(4).fill({}));
diff --git a/test/bun.js/console/console-log.test.ts b/test/bun.js/console/console-log.test.ts
new file mode 100644
index 000000000..1365e174d
--- /dev/null
+++ b/test/bun.js/console/console-log.test.ts
@@ -0,0 +1,18 @@
+import { file, spawn } from "bun";
+import { expect, it } from "bun:test";
+import { bunExe } from "bunExe";
+
+it("should log to console correctly", async () => {
+ const { stdout, stderr, exited } = spawn({
+ cmd: [bunExe(), import.meta.dir + "/console-log.js"],
+ stdin: null,
+ stdout: "pipe",
+ stderr: "pipe",
+ env: {
+ BUN_DEBUG_QUIET_LOGS: "1",
+ },
+ });
+ expect(await exited).toBe(0);
+ expect(await new Response(stderr).text()).toBe("uh oh\n");
+ expect(await new Response(stdout).text()).toBe(await new Response(file(import.meta.dir + "/console-log.expected.txt")).text());
+});