Skip to content

Commit

Permalink
console: fix console.table() display edge case
Browse files Browse the repository at this point in the history
If the properties are not specified in `console.table()`, then we should
make a best effort to determine them rather than put all values into a
"Values" column.

PR-URL: #20323
Reviewed-By: Gus Caplan <me@gus.host>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: James M Snell <jasnell@gmail.com>
  • Loading branch information
Trott authored and MylesBorins committed May 4, 2018
1 parent be34388 commit 29bc735
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 14 deletions.
4 changes: 1 addition & 3 deletions lib/console.js
Original file line number Diff line number Diff line change
Expand Up @@ -363,9 +363,7 @@ Console.prototype.table = function(tabularData, properties) {
tabularData = previewSetIterator(tabularData);

const setlike = setIter || isSet(tabularData);
if (setlike ||
(properties === undefined &&
(isArray(tabularData) || isTypedArray(tabularData)))) {
if (setlike) {
const values = [];
let length = 0;
for (const v of tabularData) {
Expand Down
31 changes: 20 additions & 11 deletions test/parallel/test-console-table.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,13 @@ test([1, 2, 3], `
`);

test([Symbol(), 5, [10]], `
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ (index) β”‚ Values β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ 0 β”‚ Symbol() β”‚
β”‚ 1 β”‚ 5 β”‚
β”‚ 2 β”‚ [ 10 ] β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ (index) β”‚ 0 β”‚ Values β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ 0 β”‚ β”‚ Symbol() β”‚
β”‚ 1 β”‚ β”‚ 5 β”‚
β”‚ 2 β”‚ 10 β”‚ β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
`);

test([undefined, 5], `
Expand Down Expand Up @@ -182,10 +182,10 @@ test({ a: undefined }, ['x'], `
`);

test([], `
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ (index) β”‚ Values β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”˜
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ (index) β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
`);

test(new Map(), `
Expand All @@ -194,3 +194,12 @@ test(new Map(), `
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”˜
`);

test([{ a: 1, b: 'Y' }, { a: 'Z', b: 2 }], `
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”
β”‚ (index) β”‚ a β”‚ b β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€
β”‚ 0 β”‚ 1 β”‚ 'Y' β”‚
β”‚ 1 β”‚ 'Z' β”‚ 2 β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”˜
`);

0 comments on commit 29bc735

Please sign in to comment.