Skip to content

feat: support get task name from test context#770

Merged
9aoy merged 3 commits intomainfrom
taskName
Dec 15, 2025
Merged

feat: support get task name from test context#770
9aoy merged 3 commits intomainfrom
taskName

Conversation

@9aoy
Copy link
Collaborator

@9aoy 9aoy commented Dec 15, 2025

Summary

support get task name from test context

import { beforeEach } from '@rstest/core';

beforeEach(async (ctx) => {
   // get name of the current test
  console.log('task name', ctx.task.name);
});

Related Links

Checklist

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

Copilot AI review requested due to automatic review settings December 15, 2025 06:56
@netlify
Copy link

netlify bot commented Dec 15, 2025

Deploy Preview for rstest-dev ready!

Name Link
🔨 Latest commit 98e8f0a
🔍 Latest deploy log https://app.netlify.com/projects/rstest-dev/deploys/693fb32d10cdfb000871fe86
😎 Deploy Preview https://deploy-preview-770--rstest-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
Contributor

Copilot AI left a comment

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 task metadata support to TestContext, enabling hooks and test functions to access the current test's name and result. The implementation unifies the type signatures for beforeEach, afterEach, onTestFinished, and onTestFailed to all accept TestContext, providing a more consistent API.

Key Changes:

  • Added task property to TestContext containing name (always available) and result (available after test execution)
  • Updated hook type signatures (beforeEach, afterEach, onTestFinished, onTestFailed) to accept TestContext
  • Moved fixture initialization to occur before beforeEach hooks to ensure context is fully populated
  • Updated documentation in both English and Chinese

Reviewed changes

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

Show a summary per file
File Description
packages/core/src/types/api.ts Added task property with name and optional result to TestContext; unified OnTestFinishedHandler and OnTestFailedHandler types to use TestContext
packages/core/src/types/testSuite.ts Updated BeforeEachListener and AfterEachListener to accept TestContext parameter
packages/core/src/runtime/runner/runner.ts Modified createTestContext to accept test parameter and initialize task.name; moved beforeRunTest call before beforeEach hooks; updated all hook invocations to pass test.context; added task.result population before afterEach hooks
website/docs/en/api/test-api/test.mdx Documented new task property in TestContext interface
website/docs/zh/api/test-api/test.mdx Documented new task property in TestContext interface (Chinese)
website/docs/en/api/test-api/hooks.mdx Updated beforeEach and afterEach type signatures to show TestContext parameter
website/docs/zh/api/test-api/hooks.mdx Updated beforeEach and afterEach type signatures to show TestContext parameter (Chinese)
e2e/lifecycle/fixtures/beforeEach.test.ts Added test case verifying ctx.task.name is accessible in beforeEach hook

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

@9aoy 9aoy merged commit a05cfd0 into main Dec 15, 2025
16 checks passed
@9aoy 9aoy deleted the taskName branch December 15, 2025 07:25
@9aoy 9aoy mentioned this pull request Dec 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant