aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Jarred Sumner <jarred@jarredsumner.com> 2023-05-19 19:50:06 -0700
committerGravatar GitHub <noreply@github.com> 2023-05-19 19:50:06 -0700
commit4db3d793cfb949e360b16b224beb22d4c7dc924e (patch)
treee5e35cc9164748ad66ba4647859e269e3be6377a
parent0b6a32269f3e54a3fbce08a351b6577e384ae3b8 (diff)
downloadbun-4db3d793cfb949e360b16b224beb22d4c7dc924e.tar.gz
bun-4db3d793cfb949e360b16b224beb22d4c7dc924e.tar.zst
bun-4db3d793cfb949e360b16b224beb22d4c7dc924e.zip
console.log changes (#2966)
* [breaking] Don't quote property names of identifiers in console.log * Make UTF-16 strings green * always quote for jest * update tests * Update this --------- Co-authored-by: Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com>
-rw-r--r--src/bun.js/bindings/exports.zig8
-rw-r--r--src/bun.js/test/pretty_format.zig12
-rw-r--r--test/js/bun/util/inspect.test.js16
-rw-r--r--test/js/web/console/console-log.expected.txt24
-rw-r--r--test/js/web/url/url.test.ts104
5 files changed, 82 insertions, 82 deletions
diff --git a/src/bun.js/bindings/exports.zig b/src/bun.js/bindings/exports.zig
index 5c171adf8..ba4ca0321 100644
--- a/src/bun.js/bindings/exports.zig
+++ b/src/bun.js/bindings/exports.zig
@@ -1755,14 +1755,14 @@ pub const ZigConsoleClient = struct {
this.addForNewLine(key.len + 1);
writer.print(
- comptime Output.prettyFmt("\"{}\"<d>:<r> ", enable_ansi_colors),
+ comptime Output.prettyFmt("<r>{}<d>:<r> ", enable_ansi_colors),
.{key},
);
} else if (key.is16Bit() and JSLexer.isLatin1Identifier(@TypeOf(key.utf16SliceAligned()), key.utf16SliceAligned())) {
this.addForNewLine(key.len + 1);
writer.print(
- comptime Output.prettyFmt("\"{}\"<d>:<r> ", enable_ansi_colors),
+ comptime Output.prettyFmt("<r>{}<d>:<r> ", enable_ansi_colors),
.{key},
);
} else if (key.is16Bit()) {
@@ -1789,10 +1789,10 @@ pub const ZigConsoleClient = struct {
.{},
);
} else {
- this.addForNewLine(key.len + 1);
+ this.addForNewLine(key.len + 2);
writer.print(
- comptime Output.prettyFmt("{s}<d>:<r> ", enable_ansi_colors),
+ comptime Output.prettyFmt("<r><green>{s}<r><d>:<r> ", enable_ansi_colors),
.{JSPrinter.formatJSONString(key.slice())},
);
}
diff --git a/src/bun.js/test/pretty_format.zig b/src/bun.js/test/pretty_format.zig
index ef2a217b9..400b0b4e1 100644
--- a/src/bun.js/test/pretty_format.zig
+++ b/src/bun.js/test/pretty_format.zig
@@ -826,17 +826,17 @@ pub const JestPrettyFormat = struct {
// TODO: make this one pass?
if (!key.is16Bit() and JSLexer.isLatin1Identifier(@TypeOf(key.slice()), key.slice())) {
- this.addForNewLine(key.len + 1);
+ this.addForNewLine(key.len + 2);
writer.print(
- comptime Output.prettyFmt("\"{}\"<d>:<r> ", enable_ansi_colors),
+ comptime Output.prettyFmt("<r>\"{}\"<d>:<r> ", enable_ansi_colors),
.{key},
);
} else if (key.is16Bit() and JSLexer.isLatin1Identifier(@TypeOf(key.utf16SliceAligned()), key.utf16SliceAligned())) {
- this.addForNewLine(key.len + 1);
+ this.addForNewLine(key.len + 2);
writer.print(
- comptime Output.prettyFmt("\"{}\"<d>:<r> ", enable_ansi_colors),
+ comptime Output.prettyFmt("<r>\"{}\"<d>:<r> ", enable_ansi_colors),
.{key},
);
} else if (key.is16Bit()) {
@@ -863,10 +863,10 @@ pub const JestPrettyFormat = struct {
.{},
);
} else {
- this.addForNewLine(key.len + 1);
+ this.addForNewLine(key.len + 2);
writer.print(
- comptime Output.prettyFmt("{s}<d>:<r> ", enable_ansi_colors),
+ comptime Output.prettyFmt("<r><green>{s}<r><d>:<r> ", enable_ansi_colors),
.{JSPrinter.formatJSONString(key.slice())},
);
}
diff --git a/test/js/bun/util/inspect.test.js b/test/js/bun/util/inspect.test.js
index 5d2f27c61..5c67999fe 100644
--- a/test/js/bun/util/inspect.test.js
+++ b/test/js/bun/util/inspect.test.js
@@ -7,7 +7,7 @@ it("getters", () => {
},
};
- expect(Bun.inspect(obj)).toBe("{\n" + ' "foo": [Getter]' + "\n" + "}");
+ expect(Bun.inspect(obj)).toBe("{\n" + " foo: [Getter]" + "\n" + "}");
var called = false;
const objWithThrowingGetter = {
get foo() {
@@ -20,7 +20,7 @@ it("getters", () => {
},
};
- expect(Bun.inspect(objWithThrowingGetter)).toBe("{\n" + ' "foo": [Getter]' + "\n" + "}");
+ expect(Bun.inspect(objWithThrowingGetter)).toBe("{\n" + " foo: [Getter]" + "\n" + "}");
expect(called).toBe(false);
});
@@ -39,7 +39,7 @@ it("when prototype defines the same property, don't print the same property twic
};
var obj = Object.create(base);
obj.foo = "456";
- expect(Bun.inspect(obj).trim()).toBe('{\n "foo": "456"\n}'.trim());
+ expect(Bun.inspect(obj).trim()).toBe('{\n foo: "456"\n}'.trim());
});
it("Blob inspect", () => {
@@ -71,7 +71,7 @@ it("Blob inspect", () => {
}`);
});
-it.skip("utf16 property name", () => {
+it("utf16 property name", () => {
var { Database } = require("bun:sqlite");
const db = Database.open(":memory:");
expect("笑".codePointAt(0)).toBe(31505);
@@ -218,10 +218,10 @@ it("inspect", () => {
expect(Bun.inspect(1, "hi")).toBe("1 hi");
expect(Bun.inspect([])).toBe("[]");
expect(Bun.inspect({})).toBe("{}");
- expect(Bun.inspect({ hello: 1 })).toBe('{\n "hello": 1\n}');
- expect(Bun.inspect({ hello: 1, there: 2 })).toBe('{\n "hello": 1,\n "there": 2\n}');
- expect(Bun.inspect({ hello: "1", there: 2 })).toBe('{\n "hello": "1",\n "there": 2\n}');
- expect(Bun.inspect({ 'hello-"there': "1", there: 2 })).toBe('{\n "hello-\\"there": "1",\n "there": 2\n}');
+ expect(Bun.inspect({ hello: 1 })).toBe("{\n hello: 1\n}");
+ expect(Bun.inspect({ hello: 1, there: 2 })).toBe("{\n hello: 1,\n there: 2\n}");
+ expect(Bun.inspect({ hello: "1", there: 2 })).toBe('{\n hello: "1",\n there: 2\n}');
+ expect(Bun.inspect({ 'hello-"there': "1", there: 2 })).toBe('{\n "hello-\\"there": "1",\n there: 2\n}');
var str = "123";
while (str.length < 4096) {
str += "123";
diff --git a/test/js/web/console/console-log.expected.txt b/test/js/web/console/console-log.expected.txt
index 938f81e05..97191c8be 100644
--- a/test/js/web/console/console-log.expected.txt
+++ b/test/js/web/console/console-log.expected.txt
@@ -11,21 +11,21 @@ Symbol(Symbol Description)
2000-06-27T02:24:34.304Z
[ 123, 456, 789 ]
{
- "name": "foo"
+ name: "foo"
}
{
- "a": 123,
- "b": 456,
- "c": 789
+ a: 123,
+ b: 456,
+ c: 789
}
{
- "a": {
- "b": {
- "c": 123
+ a: {
+ b: {
+ c: 123
},
- "bacon": true
+ bacon: true
},
- "name": "bar"
+ name: "bar"
}
Promise { <pending> }
[Function]
@@ -36,10 +36,10 @@ Promise { <pending> }
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"
+ foo: {
+ name: "baz"
},
- "bar": [Circular]
+ bar: [Circular]
} am
[
{}, {}, {}, {}
diff --git a/test/js/web/url/url.test.ts b/test/js/web/url/url.test.ts
index 33b33aefd..4e71c44d7 100644
--- a/test/js/web/url/url.test.ts
+++ b/test/js/web/url/url.test.ts
@@ -62,34 +62,34 @@ describe("url", () => {
});
it("prints", () => {
expect(Bun.inspect(new URL("https://example.com"))).toBe(`URL {
- "href": "https://example.com/",
- "origin": "https://example.com",
- "protocol": "https:",
- "username": "",
- "password": "",
- "host": "example.com",
- "hostname": "example.com",
- "port": "",
- "pathname": "/",
- "hash": "",
- "search": "",
- "searchParams": URLSearchParams {
- "append": [Function: append],
- "delete": [Function: delete],
- "get": [Function: get],
- "getAll": [Function: getAll],
- "has": [Function: has],
- "set": [Function: set],
- "sort": [Function: sort],
- "entries": [Function: entries],
- "keys": [Function: keys],
- "values": [Function: values],
- "forEach": [Function: forEach],
- "toString": [Function: toString],
+ href: "https://example.com/",
+ origin: "https://example.com",
+ protocol: "https:",
+ username: "",
+ password: "",
+ host: "example.com",
+ hostname: "example.com",
+ port: "",
+ pathname: "/",
+ hash: "",
+ search: "",
+ searchParams: URLSearchParams {
+ append: [Function: append],
+ delete: [Function: delete],
+ get: [Function: get],
+ getAll: [Function: getAll],
+ has: [Function: has],
+ set: [Function: set],
+ sort: [Function: sort],
+ entries: [Function: entries],
+ keys: [Function: keys],
+ values: [Function: values],
+ forEach: [Function: forEach],
+ toString: [Function: toString],
[Symbol(Symbol.iterator)]: [Function: entries]
},
- "toJSON": [Function: toJSON],
- "toString": [Function: toString]
+ toJSON: [Function: toJSON],
+ toString: [Function: toString]
}`);
expect(
@@ -97,34 +97,34 @@ describe("url", () => {
new URL("https://github.com/oven-sh/bun/issues/135?hello%20i%20have%20spaces%20thank%20you%20good%20night"),
),
).toBe(`URL {
- "href": "https://github.com/oven-sh/bun/issues/135?hello%20i%20have%20spaces%20thank%20you%20good%20night",
- "origin": "https://github.com",
- "protocol": "https:",
- "username": "",
- "password": "",
- "host": "github.com",
- "hostname": "github.com",
- "port": "",
- "pathname": "/oven-sh/bun/issues/135",
- "hash": "",
- "search": "?hello%20i%20have%20spaces%20thank%20you%20good%20night",
- "searchParams": URLSearchParams {
- "append": [Function: append],
- "delete": [Function: delete],
- "get": [Function: get],
- "getAll": [Function: getAll],
- "has": [Function: has],
- "set": [Function: set],
- "sort": [Function: sort],
- "entries": [Function: entries],
- "keys": [Function: keys],
- "values": [Function: values],
- "forEach": [Function: forEach],
- "toString": [Function: toString],
+ href: "https://github.com/oven-sh/bun/issues/135?hello%20i%20have%20spaces%20thank%20you%20good%20night",
+ origin: "https://github.com",
+ protocol: "https:",
+ username: "",
+ password: "",
+ host: "github.com",
+ hostname: "github.com",
+ port: "",
+ pathname: "/oven-sh/bun/issues/135",
+ hash: "",
+ search: "?hello%20i%20have%20spaces%20thank%20you%20good%20night",
+ searchParams: URLSearchParams {
+ append: [Function: append],
+ delete: [Function: delete],
+ get: [Function: get],
+ getAll: [Function: getAll],
+ has: [Function: has],
+ set: [Function: set],
+ sort: [Function: sort],
+ entries: [Function: entries],
+ keys: [Function: keys],
+ values: [Function: values],
+ forEach: [Function: forEach],
+ toString: [Function: toString],
[Symbol(Symbol.iterator)]: [Function: entries]
},
- "toJSON": [Function: toJSON],
- "toString": [Function: toString]
+ toJSON: [Function: toJSON],
+ toString: [Function: toString]
}`);
});
it("works", () => {