Skip to content

Conversation

@macarie
Copy link
Member

@macarie macarie commented Nov 9, 2025

Description

A spin-off of #8813 and third attempt at creating an extensible API for handling test artifacts produced by Vitest and third-parties.

After talking more with @sheremet-va about the issues encountered while developing #8813 and the current API, we came up with this solution, which should make it easier for developers building on top of Vitest, as well as improve internal artifact handling.

The main features of this version are:

  • Type-safe artifact registration via TestArtifactRegistry module augmentation
  • Extensible TestArtifactBase interface as foundation for all artifacts
  • TestArtifact union type containing all artifact types that can be produced (including custom ones)
  • Automatic source location tracking for all recorded artifacts
  • Automatic attachment management (validation, Uint8Array to base64 conversion)
  • Extensible TestAttachment interface for custom metadata
  • recordArtifact(artifact, task) API for capturing artifacts during test execution

Annotations are now built on top of this system, though they maintain special internal handling for backward compatibility until the next major version. Everything should be fully backward compatible until then.

Note: Developing #8813 on top of this API provided a much better experience compared to the previous two attempts.

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 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:.

@netlify
Copy link

netlify bot commented Nov 9, 2025

Deploy Preview for vitest-dev ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit e6389eb
🔍 Latest deploy log https://app.netlify.com/projects/vitest-dev/deploys/691bb356e2d8ad0008dfc0ed
😎 Deploy Preview https://deploy-preview-8987--vitest-dev.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

Copy link
Member Author

@macarie macarie left a comment

Choose a reason for hiding this comment

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

Didn't change/add any new docs, would like to get a first review and check that everything is okay first.

Copy link
Member Author

Choose a reason for hiding this comment

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

This test is still very much in-progress, still have to figure out a couple of things.

})
})

describe('reporters', () => {
Copy link
Member Author

Choose a reason for hiding this comment

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

Should these built-in reporters have any general handling for artifacts?

Personally, I don't think they should, but it should be an artifact-by-artifact decision.

Copy link
Member Author

Choose a reason for hiding this comment

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

Modified this only to check that annotations are not added to artifacts.

@macarie macarie requested a review from sheremet-va November 10, 2025 00:00
@macarie macarie marked this pull request as draft November 10, 2025 00:00
sheremet-va
sheremet-va previously approved these changes Nov 11, 2025
@macarie macarie force-pushed the feat/record-artifacts branch 2 times, most recently from 3c73e71 to 7e3aaf7 Compare November 12, 2025 00:57
Copy link
Member

@sheremet-va sheremet-va left a comment

Choose a reason for hiding this comment

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

Just some styling ideas

title: Test Artifacts
---

# Test Artifacts <Badge type="danger">advanced</Badge> <Badge type="warning">experimental</Badge>
Copy link
Member

Choose a reason for hiding this comment

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

We have <Experimental /> component now 😄 I think we should also add Advanced

Copy link
Member

Choose a reason for hiding this comment

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

We should also have a version here. I wonder if experimental features should have a warning color in the Version component though 🤔

- [`onHookEnd(beforeAll)`](#onhookend)
- [`onTestCaseReady`](#ontestcaseready)
- [`onTestAnnotate`](#ontestannotate) <Version>3.2.0</Version>
- [`onTestCaseArtifactRecord`](#ontestcaseartifactrecord) <Version>4.0.9</Version>
Copy link
Member

Choose a reason for hiding this comment

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

Can we change the Version color to be warning when it's experimental? In 4.1 we can revert it to normal and switch to 4.1

link: '/api/advanced/metadata',
},
{
text: 'Artifacts',
Copy link
Member

Choose a reason for hiding this comment

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

Maybe call it TestArtifact like the interface

@macarie macarie marked this pull request as ready for review November 12, 2025 22:08
sheremet-va
sheremet-va previously approved these changes Nov 14, 2025
@sheremet-va
Copy link
Member

Note: update <Version> when merging

@macarie macarie force-pushed the feat/record-artifacts branch from 7cc3b57 to 46c5db1 Compare November 17, 2025 23:18
@sheremet-va sheremet-va merged commit 7729236 into vitest-dev:main Nov 18, 2025
12 of 14 checks passed
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.

2 participants