-
Notifications
You must be signed in to change notification settings - Fork 196
Description
Description
In our E2E test suite (specifically in *.spec.ts files), we have step definition functions that are used in test scenarios. However, the naming patterns are inconsistent, making it hard to distinguish them from regular helper functions. This leads to confusion during code reviews, maintenance, and onboarding.
Current Inconsistencies
We currently use two main approaches, loosely aligned with BDD Given/When/Then grammar:
-
Prefixed with "user" (e.g., past-tense or "has" form): These represent "Given" or setup steps and are grammatically consistent within this category.
- Example:
await api.userHasBeenCreated({ ... }) - Example:
await api.userHasCreatedFolder({ ... })
- Example:
-
Without "user" prefix (e.g., imperative or action-based): These represent "When" or action steps.
- Example:
await ui.logInUser({ ... })(imperative, present tense for action) - Example:
await ui.logOutUser({ ... })
- Example:
The inconsistency lies in the inconsistent use of the "user" prefix: Given steps consistently use it, but When steps do not, leading to a mix that doesn't align well across the BDD structure.
Questions for Discussion
- Prefix Usage: Should all step definitions be prefixed with "user" (e.g.,
userHasDeletedProjectSpace) for consistency in bothui.*andapi.*modules? For example, we could useapi.userHasBeenLoggedOutorui.userHasBeenLoggedOut. - Tense and Form: For "Given" steps (setup), should we use past tense like
userHasLoggedInor present likeuserLogsIn? For "When" steps (actions), imperative likelogInUserseems fine, but is there a better pattern? Grammatically aligning with Given/When/Then could mean present tense for When (e.g.,userLogsIninstead oflogInUser) to match the action-oriented nature. - Distinguishability: How can we ensure step definitions are clearly distinguishable from helper/utility functions (e.g., via naming, location, or documentation)?
- Examples to Consider:
- Current:
export async function deleteGroup({ ... })→ Should it beexport async function userHasDeletedGroup({ ... })orexport async function deleteGroupForUser({ ... })? - Current:
ui.logInUser→ Should it beui.userLogsIn(present tense for When) or keep as-is?
- Current:
Proposed Goals
- Establish a consistent naming pattern across
api.*andui.*step definitions. - Align with BDD principles (Given/When/Then) where possible.
- Improve readability and reduce ambiguity in test code.
Additional Context
- This affects files in the
tests/e2e-playwright/steps/directory. - Related to our testing framework (Playwright).
- No breaking changes needed yet; this is for future consistency.
Please share your thoughts, suggestions, or examples from similar projects. Let's aim for a pattern that scales well!