Skip to content

Comments

feat(reporters): customize project name colors through options#7419

Closed
kevinmarrec wants to merge 1 commit intovitest-dev:mainfrom
kevinmarrec:reporter-colors
Closed

feat(reporters): customize project name colors through options#7419
kevinmarrec wants to merge 1 commit intovitest-dev:mainfrom
kevinmarrec:reporter-colors

Conversation

@kevinmarrec
Copy link

@kevinmarrec kevinmarrec commented Feb 4, 2025

Description

Fixes #6481
Follows #7371

Introduce a colors reporter option to be able to customize what colors are used when formatting reporter outputs.

Maybe what we would to introduce instead is the whole formatProjectName function override.

Tests

I'd like some help to writing tests for this.

Documentation

Needs to be discussed, the option name is subject to change.

.reduce((acc, v, idx) => acc + v.charCodeAt(0) + idx, 0)

const colors = [c.black, c.yellow, c.cyan, c.green, c.magenta]
colors = typeof colors === 'function' ? colors(c) : colors
Copy link
Author

@kevinmarrec kevinmarrec Feb 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Provides tinyrainbow :

{ colors: (c) => [c.blue, c.red] }

We may only allow function type to keep things simpler.


if (benches.length > 0 && benches.every(t => t.result?.state !== 'run' && t.result?.state !== 'queued')) {
let title = `\n ${getStateSymbol(task)} ${formatProjectName(task.file.projectName)}${getFullName(task, c.dim(' > '))}`
let title = `\n ${getStateSymbol(task)} ${formatProjectName(task.file.projectName, { colors: this.colors })}${getFullName(task, c.dim(' > '))}`
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds like little cumbersome, I'm open for refactoring for something like formatOptions

@kevinmarrec kevinmarrec changed the title feat(reporters): customize colors through options feat(reporters): customize project name colors through options Feb 4, 2025
private options: DefaultReporterOptions
private summary?: SummaryReporter

protected colors: DefaultReporterOptions['colors']
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Colors should also be inherited by UI, so limiting it to reporters won't work
  2. Since UI also requires colors, we can't use ANSII or functions, it should be hard coded names

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the feedback, I'll work on another solution.

@kevinmarrec
Copy link
Author

Colors should also be inherited by UI, so limiting it to reporters won't work

Closing this, will eventually work on a more suitable solution that would also work for Vitest UI.

The option should be configured at upper level therefore test object and not test.reporters

@kevinmarrec kevinmarrec closed this Feb 4, 2025
@kevinmarrec kevinmarrec deleted the reporter-colors branch February 4, 2025 13:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow custom colors for project names

2 participants