-
-
Notifications
You must be signed in to change notification settings - Fork 89
Make suite.only a thin alias of suite.focus
#1192
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -13,36 +13,57 @@ import { useHasOnliedTests } from './useHasOnliedTests'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| function useClosestMatchingFocus( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| testObject: TIsolateTest, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ): Result<Nullable<TIsolateFocused>> { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const { fieldName } = VestTest.getData(testObject); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const groupName = VestTest.getGroupName(testObject); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return makeResult.Ok( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Walker.findClosest(testObject, (child: TIsolate) => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (!FocusSelectors.isIsolateFocused(child)) return false; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const { fieldName } = VestTest.getData(testObject); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return child.data.match?.includes(fieldName) || child.data.matchAll; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return FocusSelectors.isFocusMatch( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| child as TIsolateFocused, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| fieldName, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| groupName, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ).unwrap(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| export function useIsExcluded(testObject: TIsolateTest): boolean { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const { fieldName } = VestTest.getData(testObject); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (useIsExcludedIndividually()) return true; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const inclusion = useInclusion(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return useIsExcludedByFocus(testObject); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| function useIsExcludedByFocus(testObject: TIsolateTest): boolean { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const { fieldName } = VestTest.getData(testObject); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const groupName = VestTest.getGroupName(testObject); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const focusMatch = useClosestMatchingFocus(testObject).unwrap(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // if test is skipped | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // no need to proceed | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (FocusSelectors.isSkipFocused(focusMatch).unwrap()) return true; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const isTestIncluded = FocusSelectors.isOnlyFocused(focusMatch).unwrap(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // if field is only'ed | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (isTestIncluded) return false; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (FocusSelectors.isSkipFocused(focusMatch, fieldName, groupName).unwrap()) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return true; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (FocusSelectors.isOnlyFocused(focusMatch, fieldName, groupName).unwrap()) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // if field is only'ed | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return false; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return useIsExcludedByInclusion(testObject, fieldName, groupName); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| function useIsExcludedByInclusion( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| testObject: TIsolateTest, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| fieldName: string, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| groupName?: string, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ): boolean { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // If there is _ANY_ `only`ed test (and we already know this one isn't) return true | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (useHasOnliedTests(testObject)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Check if inclusion rules for this field (`include` hook) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return !dynamicValue(inclusion[fieldName], testObject); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (!useHasOnliedTests(testObject, fieldName, groupName)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return false; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // We're done here. This field is not excluded | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return false; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const inclusion = useInclusion(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Check if inclusion rules for this field (`include` hook) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return !dynamicValue(inclusion[fieldName], testObject); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+56
to
69
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The logic within Here's the breakdown:
This means that if To fix this, function useIsExcludedByInclusion(
testObject: TIsolateTest,
fieldName: string,
groupName?: string,
): boolean {
// If there are *any* 'only' tests active in the suite, and this test is not
// explicitly 'only' focused (as determined by useIsExcludedByFocus),
// then this test should be excluded, unless it's explicitly included by an 'include' hook.
if (hasAnyOnlyIsolatesInSuite()) { // Use the new global check function
const inclusion = useInclusion();
// Check if inclusion rules for this field (`include` hook)
return !dynamicValue(inclusion[fieldName], testObject);
}
// If no 'only' tests are active globally, then this test is not excluded by 'only' logic.
return false;
}
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
useHasOnliedTestsfunction, as modified in this PR, checks if the giventestObject(or an ancestor) isonlyfocused. However, inuseIsExcludedByInclusion, this function is called after it has already been determined that thetestObjectis not explicitlyonlyfocused. This meansuseHasOnliedTestswill always returnfalsein that context.To correctly implement the
suite.onlybehavior (where all non-focused tests are excluded unless explicitly included),useIsExcludedByInclusionneeds to know if anyonlyisolates are active in the suite globally, not if the current test itself isonlyfocused. The current implementation ofuseHasOnliedTestsdoes not serve this purpose.I recommend refactoring
useHasOnliedTeststo check for the global presence ofonlyisolates in the suite. Alternatively, introduce a new helper function for this global check and use it inuseIsExcludedByInclusion.Here's a suggestion to introduce a new global check function and keep the existing
useHasOnliedTestsfor its specific (though currently unused inuseIsExcludedByInclusion) purpose: