Compare commits

...

1 Commits

Author SHA1 Message Date
Claude Bot
bcded111d2 fix(test): show empty string keys in object diffs
`Identifier::isEmpty()` returns true for both null identifiers and
empty string `""` identifiers. This caused `forEachPropertyOrdered` and
`forEachPropertyImpl` to skip properties with empty string keys when
iterating over object properties for display.

Replace `property.isEmpty()` with `property.isNull()` to only skip
null identifiers while preserving legitimate empty string property keys.
Also remove redundant `key.len == 0` check in `forEachPropertyImpl`.

Closes #18028

Co-Authored-By: Claude <noreply@anthropic.com>
2026-02-19 10:11:21 +00:00
2 changed files with 68 additions and 5 deletions

View File

@@ -5138,7 +5138,7 @@ restart:
RETURN_IF_EXCEPTION(scope, void());
for (auto& property : properties) {
if (property.isEmpty() || property.isNull()) [[unlikely]]
if (property.isNull()) [[unlikely]]
continue;
// ignore constructor
@@ -5169,9 +5169,6 @@ restart:
ZigString key = toZigString(property.isSymbol() && !property.isPrivateName() ? property.impl() : property.string());
if (key.len == 0)
continue;
JSC::JSValue propertyValue = jsUndefined();
if ((slot.attributes() & PropertyAttribute::DontEnum) != 0) {
@@ -5312,7 +5309,7 @@ extern "C" [[ZIG_EXPORT(nothrow)]] bool JSC__isBigIntInInt64Range(JSC::EncodedJS
auto clientData = WebCore::clientData(vm);
for (auto property : vector) {
if (property.isEmpty() || property.isNull()) [[unlikely]]
if (property.isNull()) [[unlikely]]
continue;
// ignore constructor

View File

@@ -0,0 +1,66 @@
import { expect, test } from "bun:test";
import { bunEnv, bunExe, tempDir } from "harness";
// https://github.com/oven-sh/bun/issues/18028
// Object diff in bun test should display empty string keys correctly.
test("toStrictEqual diff shows empty string keys", () => {
expect({
val: { "": "value" },
}).toStrictEqual({
val: { "": "value" },
});
});
test("toEqual diff shows empty string keys", () => {
expect({ "": "hello" }).toEqual({ "": "hello" });
});
test("empty string key with various value types", () => {
expect({ "": 0 }).toEqual({ "": 0 });
expect({ "": null }).toEqual({ "": null });
expect({ "": "" }).toEqual({ "": "" });
expect({ "": false }).toEqual({ "": false });
expect({ "": undefined }).toEqual({ "": undefined });
});
test("empty string key mixed with other keys", () => {
expect({ foo: "bar", "": "value" }).toEqual({ foo: "bar", "": "value" });
});
test("toStrictEqual fails and shows diff with empty string key", async () => {
using dir = tempDir("issue-18028", {
"test.test.ts": `
import { test, expect } from "bun:test";
test("diff", () => {
expect({ val: {} }).toStrictEqual({ val: { "": "value" } });
});
`,
});
await using proc = Bun.spawn({
cmd: [bunExe(), "test", "test.test.ts"],
cwd: String(dir),
env: { ...bunEnv, FORCE_COLOR: "0" },
stdout: "pipe",
stderr: "pipe",
});
const [stderr, exitCode] = await Promise.all([proc.stderr.text(), proc.exited]);
// The diff section should show non-zero changed lines
expect(stderr).toContain("- Expected - 3");
expect(stderr).toContain("+ Received + 1");
// The diff should include the empty string key
expect(stderr).toContain('"": "value"');
expect(exitCode).toBe(1);
});
test("console.log shows empty string keys", () => {
const result = Bun.spawnSync({
cmd: [bunExe(), "-e", 'console.log({ "": "value", foo: "bar" })'],
env: { ...bunEnv, NO_COLOR: "1" },
});
const stdout = result.stdout.toString();
expect(stdout).toContain('"": "value"');
});