Skip to content
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

Feature: Upgrade All Tests to Be Compatible with Pester 5.x #141

Open
jonnybottles opened this issue Nov 3, 2024 · 0 comments
Open

Feature: Upgrade All Tests to Be Compatible with Pester 5.x #141

jonnybottles opened this issue Nov 3, 2024 · 0 comments
Assignees
Labels
status/backlog In backlog / not validated type/feature New feature or request

Comments

@jonnybottles
Copy link
Collaborator

What problem would this feature solve?

The current test suite for Hawk relies on Pester 3.x syntax and practices, which are incompatible with Pester 5.x. This results in test failures and unrecognized syntax when running tests on newer systems. Updating all tests to be compatible with Pester 5.x will ensure smoother test execution, maintainability, and access to new Pester features for improved test quality.

Clear description of the current limitation/problem

  • Tests currently use outdated syntax (e.g., Should Be instead of Should -Be).
  • Mock scoping rules have changed, causing mocks to fail in contexts where they worked previously.
  • The older Assert-MockCalled method does not align with Pester 5.x’s Should -Invoke.
  • Without updates, the Hawk project’s tests are difficult to maintain and run on systems configured with Pester 5.x, creating inconsistencies and slowing development.

Proposed Solution

Syntax Modernization: Update all Should assertions to the new syntax, replacing legacy assertions without dashes (e.g., Should Be ➔ Should -Be).

Mock Scoping Compliance: Ensure all mocks are placed in appropriate blocks (BeforeEach or directly in It blocks) to align with Pester 5.x scoping rules.

Mock Call Verification Update: Replace Assert-MockCalled with Should -Invoke to allow verification of mock calls using the updated syntax.

Organized Test Structure: Adopt BeforeAll, BeforeEach, AfterAll, and AfterEach blocks for setup and teardown steps, ensuring compatibility with Pester 5.x’s structured approach to test setup and cleanup.

Technical Requirements

Syntax Changes:
Replace all legacy Should assertions without dashes.
Identify and replace any deprecated syntax, such as Assert-MockCalled.

Scope Adjustment for Mocks:
Move Mock commands to BeforeEach or It blocks as needed to ensure proper availability within each test’s scope.

Refactoring Structure:
Add BeforeAll for global setup tasks and BeforeEach for test-specific mock definitions or setups.
Use AfterAll and AfterEach where necessary to clean up or reset test environments after execution.

Implementation Approach

Identify Syntax Compatibility Issues:
Use a script or manual search to locate all instances of legacy Should syntax, Assert-MockCalled, and any unscoped Mock commands.
Track progress in the feature branch to ensure complete conversion.

Update Test Files:
Implement syntax changes iteratively, starting with one test file to confirm compatibility before scaling to others.
Apply mock scoping adjustments by adding Mock definitions within BeforeEach or specific It blocks.

Testing:
After each batch of updates, run the test suite to confirm compatibility and make adjustments as needed.
Review any additional test outputs or errors to ensure full functionality.

Acceptance Criteria

No Legacy Syntax: All Should assertions are updated to the Pester 5.x syntax.
Mocks Scoped Correctly: All mocks are defined within BeforeEach or specific test blocks to meet Pester 5.x scoping requirements.
Full Test Pass: The entire test suite runs successfully without syntax or scoping errors in Pester 5.x.
Documentation Updated: Update documentation to reflect the Pester 5.x compatibility requirement for future Hawk contributors.

@jonnybottles jonnybottles added type/feature New feature or request status/backlog In backlog / not validated labels Nov 3, 2024
@jonnybottles jonnybottles self-assigned this Nov 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status/backlog In backlog / not validated type/feature New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant