Metadata
Metadata lets you attach JSON-serializable data to test, suite, and file results. Built-in reporters do not print it by default; it is intended for custom reporters, the programmatic API, CI integrations, dashboards, ownership mapping, and external tools such as mutation testing runners.
Add metadata to a test
Pass meta in the test options object to set the initial metadata for a test case.
Reporter hooks and the programmatic API can read this declared metadata from TestResult.meta. You can define metadata when declaring the test, or modify and add fields through task.meta during the test:
Prefer mutating individual properties on task.meta; assigning task.meta = { ... } replaces the entire object and wipes any declared or suite-inherited keys.
Add metadata to a suite
Pass meta to describe when several tests share the same fields.
Suite metadata is inherited by descendant suites and tests. Child top-level keys override parent keys, so a test can override only the fields that are different.
Add file and suite metadata from hooks
File-level and suite-level hooks (beforeAll and afterAll) receive a metadata object through ctx.meta (while per-test hooks beforeEach and afterEach access test metadata through ctx.task.meta).
A file-level hook writes to TestFileResult.meta. A hook inside a describe block writes to that suite result's meta, which is passed to custom reporters through onTestSuiteResult.
Read metadata in a custom reporter
Custom reporters can read metadata from case, suite, and file results.
Use onTestCaseStart when you need the declared metadata before the test runs. Use onTestCaseResult, onTestSuiteResult, or onTestFileResult when you need final metadata produced during runtime.
Read metadata from the programmatic API
The result returned by rstest.run() includes the same result metadata as reporters.
This is useful when an external tool owns the Node.js process and wants to run Rstest, then consume structured results without parsing terminal output.
Metadata value type
Metadata must be JSON-serializable (prefer small strings, numbers, booleans, null, arrays, and plain objects; do not store functions, class instances, symbols, BigInt, or large objects). See TaskMeta and TaskMetaValue for the exported @rstest/core type definitions.
Inheritance and isolation rules
Rstest applies these rules when metadata is collected and reported:
- Suite metadata is inherited by child suites and tests.
- Child top-level keys override parent top-level keys.
- Inherited metadata is copied for each descendant, so runtime mutation does not leak to sibling tests or sibling suites.
- Nested objects and arrays are copied during inheritance.
- Mutating
task.metaduring a test (orctx.task.metainbeforeEach/afterEach) affects that test's finalTestResult.meta. - Mutating
ctx.metain file-levelbeforeAllorafterAllhooks affectsTestFileResult.meta; mutating it in suite-levelbeforeAllorafterAllhooks affects that suite result'smeta.
Skipped and todo tests
Declared metadata is still available for skipped and todo tests.
Because these tests do not execute, runtime mutations are not possible, but reporters can still read their declared metadata from onTestCaseStart and onTestCaseResult.