console.table bugfix (#10876)

This commit is contained in:
Dylan Conway
2024-05-06 19:46:35 -07:00
committed by GitHub
parent 16bf341a60
commit 5cbb1ba96a
3 changed files with 26 additions and 0 deletions

View File

@@ -359,12 +359,17 @@ const TablePrinter = struct {
// find or create the column for the property
const column: *Column = brk: {
const col_str = String.init(col_key);
for (columns.items[1..]) |*col| {
if (col.name.eql(col_str)) {
break :brk col;
}
}
// Need to ref this string because JSPropertyIterator
// uses `toString` instead of `toStringRef` for property names
col_str.ref();
try columns.append(.{ .name = col_str });
break :brk &columns.items[columns.items.len - 1];

View File

@@ -0,0 +1,3 @@
for (let i = 0; i < 50; i++) {
console.table([{ n: 8 }]);
}

View File

@@ -214,3 +214,21 @@ test.skip("console.table character widths", () => {
console.log(actualOutput);
});
test("console.table repeat 50", () => {
const expected = `┌───┬───┐
│ │ n │
├───┼───┤
│ 0 │ 8 │
└───┴───┘
`;
const { stdout, stderr } = spawnSync({
cmd: [bunExe(), `${import.meta.dir}/console-table-repeat-50.ts`],
stdout: "pipe",
stderr: "pipe",
env: bunEnv,
});
expect(stdout.toString()).toBe(expected.repeat(50));
expect(stderr.toString()).toBe("");
});