Skip to content

screenshotFailures does not attach screenshots to JUnit reporter output #9904

@radqut

Description

@radqut

Describe the bug

When using browser mode with screenshotFailures: true, screenshots are captured on test failures, but they are not attached/referenced in the JUnit XML report.

This makes it difficult to correlate failures with their screenshots in CI/CD pipelines that consume JUnit XML (e.g., GitLab, Jenkins, GitHub Actions, etc.), as users have to manually find the corresponding screenshot file.

Reproduction

// vitest.config.ts
import { defineConfig } from 'vitest/config';

export default defineConfig({
  test: {
    browser: {
      enabled: true,
      provider: 'playwright',
      screenshotFailures: true,
      screenshotDirectory: 'screenshots',
      instances: [
        { browser: 'chromium' },
      ],
    },
    reporters: ['junit'],
    outputFile: {
      junit: 'junit.xml',
    },
  },
});

Steps to reproduce

  • Run npx vitest --run
  • Observe that a screenshot is saved to the screenshots/
  • Open junit.xml
  • Note that there is no reference to the screenshot in the XML output

Expected behavior

The JUnit XML report should include a reference to the failure screenshot, for example via the [[ATTACHMENT|path/to/screenshot.png]] convention inside or , which is widely supported by CI systems:

<testcase name="failing test" classname="src/example.test.ts" time="0.123">
  <failure message="expected 3 to be 2">AssertionError: expected 3 to be 2</failure>
  <system-out>
    [[ATTACHMENT|screenshots/example-test-failing-test-1.png]]
  </system-out>
</testcase>

Actual behavior

The JUnit XML report contains the failure message but no reference to the captured screenshot:

<testcase name="failing test" classname="src/example.test.ts" time="0.123">
  <failure message="expected 3 to be 2">AssertionError: expected 3 to be 2</failure>
</testcase>

System Info

System:
    OS: Windows 11 10.0.26200
    CPU: (8) x64 Intel(R) Core(TM) i3-10100F CPU @ 3.60GHz
    Memory: 12.99 GB / 31.93 GB
  Binaries:
    Node: 22.21.1 - C:\Users\Micha\AppData\Local\mise\installs\node\22.21.1\node.EXE
    Yarn: 4.9.2 - C:\Users\Micha\AppData\Local\mise\installs\node\22.21.1\yarn.CMD
    npm: 11.11.1 - C:\Users\Micha\AppData\Local\mise\installs\node\22.21.1\npm.CMD
  Browsers:
    Chrome: 145.0.7632.160
    Edge: Chromium (142.0.3595.69)
  npmPackages:
    @vitejs/plugin-react: ^6.0.1 => 6.0.1
    @vitest/browser-playwright: ^4.1.0 => 4.1.0
    @vitest/coverage-istanbul: ^4.1.0 => 4.1.0
    @vitest/ui: ^4.1.0 => 4.1.0
    playwright: ^1.58.2 => 1.58.2
    vite: ^8.0.0 => 8.0.0
    vitest: ^4.1.0 => 4.1.0
    vitest-browser-react: ^2.1.0 => 2.1.0

Used Package Manager

pnpm

Validations

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions