Skip to content

enhance: should throw error when nest describe / test inside a test#443

Merged
9aoy merged 2 commits intomainfrom
nest-test-check
Aug 5, 2025
Merged

enhance: should throw error when nest describe / test inside a test#443
9aoy merged 2 commits intomainfrom
nest-test-check

Conversation

@9aoy
Copy link
Copy Markdown
Collaborator

@9aoy 9aoy commented Aug 5, 2025

Summary

Rstest does not support nested describe / test within tests. Currently, we should throw an error in this case.

image

Related Links

Checklist

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

Copilot AI review requested due to automatic review settings August 5, 2025 04:15
@netlify
Copy link
Copy Markdown

netlify bot commented Aug 5, 2025

Deploy Preview for rstest-dev ready!

Name Link
🔨 Latest commit 8d51fdb
🔍 Latest deploy log https://app.netlify.com/projects/rstest-dev/deploys/689187b98cfd45000802b269
😎 Deploy Preview https://deploy-preview-443--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
Copy Markdown
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

Implements validation to prevent nested describe/test blocks inside test cases in rstest. The framework now detects when developers attempt to create illegal nesting patterns and throws clear error messages.

  • Added runtime status tracking to differentiate between test collection and execution phases
  • Implemented validation checks in test/describe registration methods to detect illegal nesting
  • Enhanced error formatting to provide specific error messages for nested test violations

Reviewed Changes

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

Show a summary per file
File Description
tests/describe/fixtures/nested.test.ts Test fixture demonstrating illegal nesting patterns (describe and test inside test cases)
tests/describe/cli.test.ts Integration test verifying error messages for nested test violations
packages/core/src/runtime/util.ts Added TestRegisterError class and enhanced error formatting for nested test detection
packages/core/src/runtime/runner/runtime.ts Added status tracking and validation logic to prevent test registration during execution
packages/core/src/runtime/runner/runner.ts Updated error formatting calls to include test context
packages/core/src/runtime/runner/index.ts Set runtime status to 'running' when test execution begins
Comments suppressed due to low confidence (3)

packages/core/src/runtime/util.ts:31

  • [nitpick] The error message has inconsistent formatting. It starts with "Can't" (contraction) but the TestRegisterError message uses "cannot" (formal). Consider using consistent formality: either "Cannot nest describe or test inside a test" or adjust the TestRegisterError to use contractions.
      errObj.message = `Can't nest describe or test inside a test. ${error.message} because it is nested within test '${test.name}'`;

packages/core/src/runtime/runner/runtime.ts:37

  • [nitpick] The property name 'status' is ambiguous in this context. Consider a more descriptive name like 'phase' or 'executionPhase' to clearly indicate it tracks whether the runtime is in collection or execution phase.
  private status: 'running' | 'collect' = 'collect';

packages/core/src/runtime/runner/runtime.ts:59

  • [nitpick] The method name 'updateStatus' is generic. Consider renaming to 'setExecutionPhase' or 'updateExecutionPhase' to be more specific about what status is being updated.
  updateStatus(status: 'running' | 'collect'): void {

@9aoy 9aoy merged commit 62c39ec into main Aug 5, 2025
16 checks passed
@9aoy 9aoy deleted the nest-test-check branch August 5, 2025 05:55
@9aoy 9aoy mentioned this pull request Aug 5, 2025
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