Skip to content

feat(core): add task metadata support#1507

Merged
9aoy merged 7 commits into
mainfrom
feat-task-metadata
Jul 9, 2026
Merged

feat(core): add task metadata support#1507
9aoy merged 7 commits into
mainfrom
feat-task-metadata

Conversation

@9aoy

@9aoy 9aoy commented Jul 6, 2026

Copy link
Copy Markdown
Collaborator

Summary

This PR adds metadata support for tests, suites, file results, and custom reporters. TestOptions.meta initializes task metadata, suite metadata is shallow-inherited by descendant suites and tests with child keys overriding parent keys, and runtime updates through context.task.meta / hook ctx.meta are exposed through programmatic results and reporter hooks.

Example

import { afterAll, describe, test } from '@rstest/core';

// File-level metadata is exposed on TestFileResult.meta.
afterAll((ctx) => {
  ctx.meta.fileHook = 'afterAll';
});

describe('checkout', { meta: { owner: 'platform', area: 'payment' } }, () => {
  test('submits order', { meta: { caseId: 'checkout-001' } }, (ctx) => {
    // Test-level metadata inherits suite metadata and can be updated at runtime.
    ctx.task.meta.mutantId = process.env.STRYKER_ACTIVE_MUTANT;
  });
});

Custom reporters can read the resolved metadata from case, suite, and file results:

import type { Reporter } from '@rstest/core';

const metadataReporter: Reporter = {
  onTestCaseStart(test) {
    console.log('case start metadata', test.meta);
  },
  onTestCaseResult(result) {
    console.log('case result metadata', result.meta);
  },
  onTestSuiteResult(result) {
    console.log('suite metadata', result.meta);
  },
  onTestFileResult(result) {
    console.log('file metadata', result.meta);
  },
};

Checklist

  • Tests updated (or not required).
  • Documentation updated (or not required).

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: a5a0236018

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread e2e/programmatic/fixtures/run-metadata.mjs
Comment thread e2e/programmatic/fixtures/run-metadata.mjs
Comment thread e2e/programmatic/fixtures/run-metadata.mjs
@9aoy 9aoy force-pushed the feat-task-metadata branch from a5a0236 to 0ed9165 Compare July 6, 2026 08:19
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Jul 6, 2026

Copy link
Copy Markdown

Deploying rstest with  Cloudflare Pages  Cloudflare Pages

Latest commit: 400358c
Status: ✅  Deploy successful!
Preview URL: https://5e60f5ca.rstest.pages.dev
Branch Preview URL: https://feat-task-metadata.rstest.pages.dev

View logs

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR adds first-class “task metadata” support to @rstest/core so users can initialize metadata via TestOptions.meta, inherit it through nested describe blocks (shallow merge with child keys overriding), and mutate it at runtime via context.task.meta (tests) and ctx.meta (suite/file hooks). The resolved metadata is then exposed consistently through reporter hooks and the programmatic runRstest results.

Changes:

  • Extend core task/result types (TestCaseInfo, TestSuiteInfo, TestResult, SuiteContext, TestOptions, TestContext.task) with meta and document the semantics.
  • Implement metadata initialization + inheritance in the runtime collector, and plumb metadata through runner events/results (including TestFileResult.meta).
  • Add/extend unit + e2e coverage verifying inheritance, isolation between siblings, reporter hook visibility, and programmatic API visibility.

Reviewed changes

Copilot reviewed 23 out of 23 changed files in this pull request and generated no comments.

Show a summary per file
File Description
website/docs/zh/api/runtime-api/test-api/test.mdx Documents TestOptions.meta and context.task.meta usage in the runtime test API (ZH).
website/docs/zh/api/runtime-api/test-api/hooks.mdx Documents ctx.meta behavior and how hook-written metadata surfaces in results (ZH).
website/docs/zh/api/runtime-api/test-api/describe.mdx Documents suite-level meta inheritance/override semantics (ZH).
website/docs/zh/api/javascript-api/types.mdx Notes how TestResult.meta / TestFileResult.meta are populated and surfaced (ZH).
website/docs/zh/api/javascript-api/reporter.mdx Documents where reporters can read runtime vs hook metadata (ZH).
website/docs/en/api/runtime-api/test-api/test.mdx Documents TestOptions.meta and context.task.meta usage in the runtime test API (EN).
website/docs/en/api/runtime-api/test-api/hooks.mdx Documents ctx.meta behavior and how hook-written metadata surfaces in results (EN).
website/docs/en/api/runtime-api/test-api/describe.mdx Documents suite-level meta inheritance/override semantics (EN).
website/docs/en/api/javascript-api/types.mdx Notes how TestResult.meta / TestFileResult.meta are populated and surfaced (EN).
website/docs/en/api/javascript-api/reporter.mdx Documents where reporters can read runtime vs hook metadata (EN).
packages/core/tests/runner/runtime.test.ts Adds unit tests for metadata initialization, inheritance, overrides, and sibling isolation.
packages/core/src/types/testSuite.ts Introduces TaskMeta and adds meta to task info/results plus SuiteContext.
packages/core/src/types/api.ts Adds TestOptions.meta and TestContext.task.meta to the public runtime API types.
packages/core/src/runtime/runner/runtime.ts Implements metadata initialization on tasks and shallow inheritance during collection.
packages/core/src/runtime/runner/runner.ts Threads metadata through suite/file/test execution contexts and emitted results.
packages/core/src/runtime/runner/index.ts Includes metadata when converting internal tasks to public TestInfo.
packages/core/src/api/index.ts Exposes meta on the programmatic API TestResult/TestFileResult mapping.
e2e/reporter/rstest.metadataReporterConfig.ts Adds a custom reporter fixture that prints captured metadata from hooks.
e2e/reporter/index.test.ts Adds e2e assertions that reporter hooks receive the expected metadata snapshots/finals.
e2e/reporter/fixtures/metadata.test.ts Adds fixture tests that mutate ctx.meta and ctx.task.meta for e2e validation.
e2e/programmatic/index.test.ts Adds e2e assertions that runRstest returns metadata in file/case/suite results.
e2e/programmatic/fixtures/run-metadata.mjs Adds a programmatic runner fixture that collects metadata via reporters + API results.
e2e/programmatic/fixtures/disk/sum.test.ts Updates programmatic disk fixture to write metadata from hooks and test context.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@9aoy

9aoy commented Jul 6, 2026

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 0ed91658d6

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread packages/core/src/types/testSuite.ts Outdated
Comment thread packages/core/src/runtime/runner/runtime.ts Outdated
Comment thread packages/core/src/runtime/runner/runner.ts
@9aoy

9aoy commented Jul 9, 2026

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: ac59f0e82d

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread packages/core/src/runtime/runner/runner.ts Outdated
Comment thread website/docs/en/api/runtime-api/test-api/test.mdx Outdated
Comment thread website/docs/en/api/runtime-api/test-api/hooks.mdx Outdated
@9aoy

9aoy commented Jul 9, 2026

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 400358c9dd

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread website/docs/en/api/runtime-api/test-api/test.mdx
@9aoy 9aoy requested a review from fi3ework July 9, 2026 06:38
@9aoy 9aoy merged commit e38ff12 into main Jul 9, 2026
12 checks passed
@9aoy 9aoy deleted the feat-task-metadata branch July 9, 2026 11:23
@fi3ework fi3ework mentioned this pull request Jul 9, 2026
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.

3 participants