| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -249,6 +249,10 @@ export abstract class BaseReporter implements Reporter { | |||
| 249 | 249 | return getTestName(test, separator) | |
| 250 | 250 | } | |
| 251 | 251 | ||
| 252 | + protected getFullName(test: Task, separator?: string): string { | ||
| 253 | + return getFullName(test, separator) | ||
| 254 | + } | ||
| 255 | + | ||
| 252 | 256 | protected formatShortError(error: ErrorWithDiff): string { | |
| 253 | 257 | return `${F_RIGHT} ${error.message}` | |
| 254 | 258 | } | |
@@ -374,7 +378,7 @@ export abstract class BaseReporter implements Reporter { | |||
| 374 | 378 | const task = log.taskId ? this.ctx.state.idMap.get(log.taskId) : undefined | |
| 375 | 379 | ||
| 376 | 380 | if (task) { | |
| 377 | - headerText = getFullName(task, c.dim(' > ')) | ||
| 381 | + headerText = this.getFullName(task, c.dim(' > ')) | ||
| 378 | 382 | } | |
| 379 | 383 | else if (log.taskId && log.taskId !== '__vitest__unknown_test__') { | |
| 380 | 384 | headerText = log.taskId | |
@@ -579,7 +583,7 @@ export abstract class BaseReporter implements Reporter { | |||
| 579 | 583 | continue | |
| 580 | 584 | } | |
| 581 | 585 | ||
| 582 | - const groupName = getFullName(group, c.dim(' > ')) | ||
| 586 | + const groupName = this.getFullName(group, c.dim(' > ')) | ||
| 583 | 587 | const project = this.ctx.projects.find(p => p.name === bench.file.projectName) | |
| 584 | 588 | ||
| 585 | 589 | this.log(` ${formatProjectName(project)}${bench.name}${c.dim(` - ${groupName}`)}`) | |
@@ -636,7 +640,7 @@ export abstract class BaseReporter implements Reporter { | |||
| 636 | 640 | const projectName = (task as File)?.projectName || task.file?.projectName || '' | |
| 637 | 641 | const project = this.ctx.projects.find(p => p.name === projectName) | |
| 638 | 642 | ||
| 639 | - let name = getFullName(task, c.dim(' > ')) | ||
| 643 | + let name = this.getFullName(task, c.dim(' > ')) | ||
| 640 | 644 | ||
| 641 | 645 | if (filepath) { | |
| 642 | 646 | name += c.dim(` [ ${this.relative(filepath)} ]`) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,12 @@ | |||
| 1 | + import {expect, test } from 'vitest'; | ||
| 2 | + | ||
| 3 | + test('pass', ( { task }) => { | ||
| 4 | + task.meta.custom = "Passing test added this" | ||
| 5 | + }); | ||
| 6 | + | ||
| 7 | + | ||
| 8 | + test('fails', ( { task }) => { | ||
| 9 | + task.meta.custom = "Failing test added this" | ||
| 10 | + | ||
| 11 | + expect(true).toBe(false) | ||
| 12 | + }); | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1 @@ | |||
| 1 | + export default {} | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,5 +1,6 @@ | |||
| 1 | - import type { TestSpecification } from 'vitest/node' | ||
| 1 | + import type { RunnerTask, TestSpecification } from 'vitest/node' | ||
| 2 | 2 | import { describe, expect, test } from 'vitest' | |
| 3 | + import { DefaultReporter } from 'vitest/reporters' | ||
| 3 | 4 | import { runVitest, runVitestCli } from '../../test-utils' | |
| 4 | 5 | ||
| 5 | 6 | describe('default reporter', async () => { | |
@@ -238,6 +239,21 @@ describe('default reporter', async () => { | |||
| 238 | 239 | expect(stdout).toContain('Example project') | |
| 239 | 240 | expect(stdout).toContain('\x1B[30m\x1B[45m Example project \x1B[49m\x1B[39m') | |
| 240 | 241 | }) | |
| 242 | + | ||
| 243 | + test('extended reporter can override getFullName', async () => { | ||
| 244 | + class Custom extends DefaultReporter { | ||
| 245 | + getFullName(test: RunnerTask, separator?: string): string { | ||
| 246 | + return `${separator}{ name: ${test.name}, meta: ${test.meta.custom} } (Custom getFullName here)` | ||
| 247 | + } | ||
| 248 | + } | ||
| 249 | + | ||
| 250 | + const { stderr } = await runVitest({ | ||
| 251 | + root: 'fixtures/metadata', | ||
| 252 | + reporters: new Custom(), | ||
| 253 | + }) | ||
| 254 | + | ||
| 255 | + expect(stderr).toMatch('FAIL > { name: fails, meta: Failing test added this } (Custom getFullName here') | ||
| 256 | + }) | ||
| 241 | 257 | }, 120000) | |
| 242 | 258 | ||
| 243 | 259 | function trimReporterOutput(report: string) { | |
| Back | FazBrowse Home | New Git URL |
0 commit comments