From bb65e15c7f0746295ad5e78ad6e2faed70ef8995 Mon Sep 17 00:00:00 2001 From: Vladimir Date: Mon, 1 Dec 2025 15:26:05 +0100 Subject: [PATCH] fix(reporters): show project in github reporter (#9138) ### Description Resolves #issue-number ### Please don't delete this checklist! Before submitting the PR, please make sure you do the following: - [ ] It's really useful if your PR references an issue where it is discussed ahead of time. If the feature is substantial or introduces breaking changes without a discussion, PR might be closed. - [ ] Ideally, include a test that fails without this PR but passes with it. - [ ] Please, don't make changes to `pnpm-lock.yaml` unless you introduce a new test example. - [ ] Please check [Allow edits by maintainers](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/working-with-forks/allowing-changes-to-a-pull-request-branch-created-from-a-fork) to make review process faster. Note that this option is not available for repositories that are owned by Github organizations. ### Tests - [ ] Run the tests with `pnpm test:ci`. ### Documentation - [ ] If you introduce new functionality, document it. You can run documentation with `pnpm run docs` command. ### Changesets - [ ] Changes in changelog are generated from PR name. Please, make sure that it explains your changes in an understandable manner. Please, prefix changeset messages with `feat:`, `fix:`, `perf:`, `docs:`, or `chore:`. --- .vscode/settings.json | 2 +- .../src/node/reporters/github-actions.ts | 2 +- test/reporters/tests/github-actions.test.ts | 18 ++++++++++++++++++ 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index 14991480b..95f06bbd7 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -23,7 +23,7 @@ // ], "vitest.ignoreWorkspace": true, - "vitest.configSearchPatternInclude": "test/{core,cli,config,browser}/{vitest,vite}.{config.ts,config.unit.mts}", + "vitest.configSearchPatternInclude": "test/{core,cli,config,browser,reporters}/{vitest,vite}.{config.ts,config.unit.mts}", "testing.automaticallyOpenTestResults": "neverOpen", // Enable eslint for all supported languages diff --git a/packages/vitest/src/node/reporters/github-actions.ts b/packages/vitest/src/node/reporters/github-actions.ts index 888625db7..092f8aed1 100644 --- a/packages/vitest/src/node/reporters/github-actions.ts +++ b/packages/vitest/src/node/reporters/github-actions.ts @@ -80,7 +80,7 @@ export class GithubActionsReporter implements Reporter { for (const error of task.result?.errors ?? []) { projectErrors.push({ project, - title, + title: project.name ? `[${project.name}] ${title}` : title, error, file, }) diff --git a/test/reporters/tests/github-actions.test.ts b/test/reporters/tests/github-actions.test.ts index 9640d6501..3598510f6 100644 --- a/test/reporters/tests/github-actions.test.ts +++ b/test/reporters/tests/github-actions.test.ts @@ -18,6 +18,24 @@ describe(GithubActionsReporter, () => { expect(stderr).toBe('') }) + it('prints the project name when there is one', async () => { + let { stdout, stderr } = await runVitest( + { + name: 'test-project', + reporters: new GithubActionsReporter(), + root: './fixtures', + include: ['**/some-failing.test.ts'], + }, + ) + stdout = stdout.replace(resolve(import.meta.dirname, '..').replace(/:/g, '%3A'), '__TEST_DIR__') + expect(stdout).toMatchInlineSnapshot(` + " + ::error file=__TEST_DIR__/fixtures/some-failing.test.ts,title=[test-project] some-failing.test.ts > 3 + 3 = 7,line=8,column=17::AssertionError: expected 6 to be 7 // Object.is equality%0A%0A- Expected%0A+ Received%0A%0A- 7%0A+ 6%0A%0A ❯ some-failing.test.ts:8:17%0A%0A + " + `) + expect(stderr).toBe('') + }) + it('uses onWritePath to format path', async () => { const { stdout, stderr } = await runVitest( { -- 2.51.2