enhance: should throw error when nest describe / test inside a test#443
Merged
enhance: should throw error when nest describe / test inside a test#443
Conversation
✅ Deploy Preview for rstest-dev ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
Contributor
There was a problem hiding this comment.
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 {
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Rstest does not support nested describe / test within tests. Currently, we should throw an error in this case.
Related Links
Checklist