-
Notifications
You must be signed in to change notification settings - Fork 223
fix(fancy): align right-side content across log types #445
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,7 @@ | ||
| import { describe, test, expect } from "vitest"; | ||
| import { ConsolaReporter, LogLevels, LogObject, createConsola } from "../src"; | ||
| import { FancyReporter } from "../src/reporters/fancy"; | ||
| import { stripAnsi } from "../src/utils/string"; | ||
|
|
||
| describe("consola", () => { | ||
| test("can set level", () => { | ||
|
|
@@ -56,6 +58,31 @@ describe("consola", () => { | |
|
|
||
| expect(logs.at(-1)!.args).toEqual(["SPAM", "(repeated 4 times)"]); | ||
| }); | ||
|
|
||
| test("fancy reporter aligns right-side content across log types (#394)", () => { | ||
| const reporter = new FancyReporter(); | ||
| const opts = { columns: 120, date: true }; | ||
|
|
||
| const lines = ["info", "success", "start"].map((type) => { | ||
| const logObj: LogObject = { | ||
| type, | ||
| level: 3, | ||
| tag: "", | ||
| args: ["test message"], | ||
| date: new Date("2025-01-01T00:00:00.000Z"), | ||
| } as any; | ||
| return reporter.formatLogObj(logObj, opts as any); | ||
| }); | ||
|
|
||
| // Extract the position of the date string in each line | ||
| const positions = lines.map((line) => { | ||
| return stripAnsi(line).lastIndexOf("12:00:00 AM"); | ||
| }); | ||
|
|
||
| // All positions must be equal (right-aligned) | ||
| expect(positions[0]).toBe(positions[1]); | ||
| expect(positions[1]).toBe(positions[2]); | ||
| }); | ||
|
Comment on lines
+77
to
+85
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win 🧩 Analysis chain🏁 Script executed: #!/bin/bash
set -euo pipefail
rg -n -C 4 'formatDate|toLocaleTimeString|lastIndexOf\("12:00:00 AM"\)' src testRepository: unjs/consola Length of output: 1710 🏁 Script executed: #!/bin/bash
set -euo pipefail
printf '%s\n' '--- test/consola.test.ts ---'
sed -n '1,105p' test/consola.test.ts
printf '%s\n' '--- src/reporters/basic.ts ---'
sed -n '1,90p' src/reporters/basic.ts
printf '%s\n' '--- related date-option and reporter usage ---'
rg -n -C 3 'date:|formatDate\(|new Date\(|BasicReporter|basic' test srcRepository: unjs/consola Length of output: 10357 🏁 Script executed: #!/bin/bash
set -euo pipefail
printf '%s\n' '--- src/reporters/fancy.ts ---'
sed -n '90,145p' src/reporters/fancy.ts
printf '%s\n' '--- runtime date representations ---'
node - <<'JS'
const date = new Date("2025-01-01T00:00:00.000Z");
for (const [locale, timeZone] of [
["en-US", "UTC"],
["en-GB", "UTC"],
["de-DE", "UTC"],
["en-US", "America/Los_Angeles"],
]) {
console.log(
`${locale} / ${timeZone}:`,
date.toLocaleTimeString(locale, { timeZone }),
);
}
JSRepository: unjs/consola Length of output: 2204 Make the timestamp assertion non-vacuous and locale-independent.
🤖 Prompt for AI AgentsSource: MCP tools |
||
| }); | ||
|
|
||
| function wait(delay) { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
Repository: unjs/consola
Length of output: 285
🏁 Script executed:
Repository: unjs/consola
Length of output: 4710
🏁 Script executed:
Repository: unjs/consola
Length of output: 13146
Scope
iconWidthDiffto built-in ambiguous iconsWhen
opts.columns >= 80, a custom combining icon such ase\u0301hasstringWidth(typeStripped) === 1buttypeStripped.length === 2. This setsiconWidthDiffto-1and shifts right-aligned content left by one column.Apply the correction only to built-in icons that over-report their width, or use a terminal-width-aware baseline.
🤖 Prompt for AI Agents
Source: MCP tools