Skip to content

Restructure the Json test suite to the function test specification #35

Description

Context and request

tests/Json.Tests.ps1 does not follow the PowerShell Function Test Specification. The suite opens with Describe 'Module' and groups by concern — Context 'Format-Json', Context 'Data Type Handling', Context 'Complex JSON Structures' — so tests for a single command are scattered across contexts and there is no per-command Describe. It names such as Should compact pretty JSON do not name the command under test, which makes a failure in the CI summary ambiguous about which command broke.

The suite also writes to the host inside It blocks via LogGroup/Write-Host wrappers around nearly every assertion, which adds noise without adding diagnostic value that Pester's own failure output does not already provide.

The framework's FunctionTest check only verifies that each public command is referenced somewhere under tests/, so the current layout passes structurally. This is about making the suite navigable, not about satisfying a gate.

Acceptance criteria.

  • The suite follows Describe '<Module>' → Describe '<Function>' → Context '<Function> - <use case>' → It '<Function> - <expected behavior>'.
  • Every It name states the command and the behaviour it asserts, so a CI failure line identifies both without opening the file.
  • Every existing assertion is preserved; no test is dropped in the restructure.
  • Code coverage remains at or above the 95% target in .github/PSModule.yml.
  • The suite passes on Linux, macOS, and Windows.

Technical decisions

The module keeps the Simple profile from the Tests section — a single root tests/Json.Tests.ps1. With three commands there is no reason to split into per-group files, and doing so would change the TestName values the workflow derives from file basenames.

This is a mechanical restructure with no assertion changes, so it ships separately from the pipeline fix. Reviewing a large move diff alongside a version bump would hide regressions in both.

LogGroup/Write-Host calls are removed from It blocks. They belong in BeforeAll when a fixture genuinely needs explaining; Pester reports actual versus expected on failure already.

The PSAvoidUsingWriteHost and PSAvoidLongLines suppression attributes at the top of the file should be re-evaluated once the Write-Host calls are gone — a suppression that no longer suppresses anything is misleading.

Depends on the Pester 6 requirement landing first, so the restructured suite is written against the version it will actually run under.

Implementation plan

  • Confirm the suite is green under Pester 6 before restructuring, to establish the baseline
  • Restructure to Describe 'Json' with a nested Describe per public command
  • Redistribute the Data Type Handling and Complex JSON Structures assertions into Context blocks under the command they exercise
  • Rename every It to <Function> - <expected behavior>
  • Remove LogGroup/Write-Host from It blocks, keeping fixture setup in BeforeAll
  • Remove suppression attributes that no longer apply
  • Confirm the same number of assertions run before and after
  • Confirm coverage still meets the 95% target on all three runners

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions