Skip to content
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

feat: print project name as a label #6925

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
3 changes: 2 additions & 1 deletion packages/vitest/src/node/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ export class Vitest {

public packageInstaller: VitestPackageInstaller

/** TODO: rename to `_coreRootProject` */
/** @internal */
public coreWorkspaceProject!: TestProject

Expand All @@ -91,7 +92,7 @@ export class Vitest {
/** @deprecated use `_cachedSpecs` */
projectTestFiles = this._cachedSpecs

/** @private */
/** @internal */
public _browserLastPort = defaultBrowserPort

constructor(
Expand Down
6 changes: 3 additions & 3 deletions packages/vitest/src/node/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -276,15 +276,15 @@ export class Logger {
+ '\nThis might cause false positive tests. Resolve unhandled errors to make sure your tests are not affected.',
),
)
this.log(c.red(divider(c.bold(c.inverse(' Unhandled Errors ')))))
this.log(errorMessage)
this.error(c.red(divider(c.bold(c.inverse(' Unhandled Errors ')))))
this.error(errorMessage)
errors.forEach((err) => {
this.printError(err, {
fullStack: true,
type: (err as ErrorWithDiff).type || 'Unhandled Error',
})
})
this.log(c.red(divider()))
this.error(c.red(divider()))
}

printSourceTypeErrors(errors: TypeCheckError[]) {
Expand Down
6 changes: 3 additions & 3 deletions packages/vitest/src/node/reporters/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -406,12 +406,12 @@ export abstract class BaseReporter implements Reporter {
const errorDivider = () => this.error(`${c.red(c.dim(divider(`[${current++}/${failedTotal}]`, undefined, 1)))}\n`)

if (failedSuites.length) {
this.error(`${errorBanner(`Failed Suites ${failedSuites.length}`)}\n`)
this.error(`\n${errorBanner(`Failed Suites ${failedSuites.length}`)}\n`)
this.printTaskErrors(failedSuites, errorDivider)
}

if (failedTests.length) {
this.error(`${errorBanner(`Failed Tests ${failedTests.length}`)}\n`)
this.error(`\n${errorBanner(`Failed Tests ${failedTests.length}`)}\n`)
this.printTaskErrors(failedTests, errorDivider)
}

Expand Down Expand Up @@ -492,7 +492,7 @@ export abstract class BaseReporter implements Reporter {
}

this.ctx.logger.error(
`${c.red(c.bold(c.inverse(' FAIL ')))}${formatProjectName(projectName)} ${name}`,
`${c.red(c.bold(c.inverse(' FAIL ')))} ${formatProjectName(projectName)}${name}`,
)
}

Expand Down
7 changes: 5 additions & 2 deletions packages/vitest/src/node/reporters/renderers/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -239,13 +239,16 @@ export function formatProjectName(name: string | undefined, suffix = ' ') {
if (!name) {
return ''
}
if (!c.isColorSupported) {
return `|${name}|${suffix}`
}
const index = name
.split('')
.reduce((acc, v, idx) => acc + v.charCodeAt(0) + idx, 0)

const colors = [c.blue, c.yellow, c.cyan, c.green, c.magenta]
const colors = [c.black, c.yellow, c.cyan, c.green, c.magenta]

return colors[index % colors.length](`|${name}|`) + suffix
return c.inverse(colors[index % colors.length](` ${name} `)) + suffix
}

export function withLabel(color: 'red' | 'green' | 'blue' | 'cyan' | 'yellow', label: string, message?: string) {
Expand Down
Loading