Conversation
|
Important Review skippedDraft detected. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the Note Other AI code review bot(s) detectedCodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Summary of ChangesHello @ealush, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request introduces a more ergonomic and direct way to perform focused validation runs within the suite by adding a Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request successfully refactors suite.only to be a thin alias of suite.focus, providing a more concise and chainable API for focused validation runs. The changes include updating type definitions, modifying the suite creation logic, and updating all relevant tests, snapshots, and documentation. The introduction of group-based focusing is a valuable enhancement. However, a logical issue was identified in how useIsExcludedByInclusion interacts with the only mode, which could lead to incorrect exclusion behavior.
| export function useHasOnliedTests( | ||
| testObject: TIsolateTest, | ||
| fieldName?: TFieldName, | ||
| groupName?: TGroupName, | ||
| ): boolean { | ||
| return isNotNullish( | ||
| Walker.findClosest(testObject, (child: TIsolate) => { | ||
| if (!FocusSelectors.isIsolateFocused(child)) return false; | ||
|
|
||
| return FocusSelectors.isOnlyFocused(child, fieldName).unwrap(); | ||
| return FocusSelectors.isOnlyFocused(child, fieldName, groupName).unwrap(); | ||
| }), | ||
| ); |
There was a problem hiding this comment.
The useHasOnliedTests function, as modified in this PR, checks if the given testObject (or an ancestor) is only focused. However, in useIsExcludedByInclusion, this function is called after it has already been determined that the testObject is not explicitly only focused. This means useHasOnliedTests will always return false in that context.
To correctly implement the suite.only behavior (where all non-focused tests are excluded unless explicitly included), useIsExcludedByInclusion needs to know if any only isolates are active in the suite globally, not if the current test itself is only focused. The current implementation of useHasOnliedTests does not serve this purpose.
I recommend refactoring useHasOnliedTests to check for the global presence of only isolates in the suite. Alternatively, introduce a new helper function for this global check and use it in useIsExcludedByInclusion.
Here's a suggestion to introduce a new global check function and keep the existing useHasOnliedTests for its specific (though currently unused in useIsExcludedByInclusion) purpose:
import { isNotNullish } from 'vest-utils';
import { TIsolate, Walker, VestRuntime } from 'vestjs-runtime';
import { FocusModes } from './FocusedKeys';
import { TIsolateTest } from '../../core/isolate/IsolateTest/IsolateTest';
import { TFieldName, TGroupName } from '../../suiteResult/SuiteResultTypes';
import { FocusSelectors } from './focused';
/**
* Checks if there are any 'only' focused isolates active in the current suite context.
* This function performs a global check across the entire suite isolate tree.
*/
export function hasAnyOnlyIsolatesInSuite(): boolean {
const currentSuiteIsolate = VestRuntime.useAvailableRoot();
if (!currentSuiteIsolate) return false;
return Walker.some(currentSuiteIsolate, (isolate: TIsolate) => {
if (!FocusSelectors.isIsolateFocused(isolate)) return false;
return isolate.data.focusMode === FocusModes.ONLY;
});
}
/**
* Checks if the given testObject (or any of its ancestors) is 'only' focused
* for the specified fieldName and groupName.
*/
export function useHasOnliedTests(
testObject: TIsolateTest,
fieldName?: TFieldName,
groupName?: TGroupName,
): boolean {
return isNotNullish(
Walker.findClosest(testObject, (child: TIsolate) => {
if (!FocusSelectors.isIsolateFocused(child)) return false;
return FocusSelectors.isOnlyFocused(child, fieldName, groupName).unwrap();
}),
);
}| 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); | ||
| } |
There was a problem hiding this comment.
The logic within useIsExcludedByInclusion is currently inverted, leading to incorrect behavior when suite.only is active.
Here's the breakdown:
useIsExcludedByFocusdetermines that the currenttestObjectis not explicitlyonlyfocused, and then callsuseIsExcludedByInclusion.- Inside
useIsExcludedByInclusion, the conditionif (!useHasOnliedTests(testObject, fieldName, groupName))is evaluated. SinceuseHasOnliedTests(as currently implemented) checks if this specific test isonlyfocused, and we already know it's not,useHasOnliedTestswill returnfalse. - Consequently,
!useHasOnliedTests(...)becomestrue, causing the function to immediatelyreturn false.
This means that if only mode is active, but the current test is not among the only focused tests, it will not be excluded. This breaks the fundamental behavior of suite.only, which should exclude all tests not explicitly focused.
To fix this, useIsExcludedByInclusion should check for the global presence of any only isolates in the suite (using the hasAnyOnlyIsolatesInSuite function proposed in the useHasOnliedTests.ts comment). If global only mode is active, and the current test is not explicitly only focused (which is the precondition for calling this function), then the test should be excluded unless an include hook explicitly includes it.
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;
}| 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); | |
| } | |
| 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()) { | |
| 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; | |
| } |
🚀 Benchmark Results
Raw Output |
Motivation
suite.only(...)instead ofsuite.focus({ only: ... }).onlyAPI through the existingfocusimplementation.afterEach,afterField,run) available for focused runs.Description
onlytofocusinuseCreateSuiteMethods.tsby creating afocusFnand makingonlycallfocusFn({ only: match })instead of using a separateuseCreateOnlyimplementation.useCreateOnlyimplementation and delete the now-obsoleteonly.hook.test.tstest file.suite.only(...)oversuite.focus({ only: ... })and adapt types/imports to useFocusMatchwhere applicable.focusimplementation intact so all behavior remains consistent while providing the shorter API.Testing
npx lint-staged(which ranprettierandeslint --fix) and they completed successfully.Codex Task