Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Testing

The project ships a modular test runner with automatic suite discovery. The same *.Tests.ps1 suites run under Pester 5 when it is installed and under a bundled zero-dependency native engine otherwise.

Runner architecture

flowchart TD
    A["tests/RunTests.bat<br/>PATH pwsh launcher"] --> B["tests/Run-Tests.ps1"]
    B --> C["Discover tests/suites/*.Tests.ps1"]
    B --> D{Engine}
    D -- "Pester 5 installed or --pester" --> E["Invoke-Pester per suite"]
    D -- "no Pester or --native" --> F["tests/helpers/TestHarness.ps1"]
    F --> G["native Describe / It / Should shim"]
    E --> H["Per-suite results"]
    G --> H
    H --> I["Totals, status, exit code"]

The runner has two modes:

  • TUI when a real console is available and no CLI flag is passed.
  • Headless for --list, --all, --suite, and CI.

Running the suite

tests\RunTests.bat
tests\RunTests.bat --list
tests\RunTests.bat --all
tests\RunTests.bat --suite catalog,paths
tests\RunTests.bat --suite 01,05 --verbose
tests\RunTests.bat --all --pester
tests\RunTests.bat --all --native
tests\RunTests.bat --help
FlagEffect
--listList every discovered suite with its number, slug, and title
--allRun every suite
--suite <names>Run suites by number, slug, or title keyword; comma- or semicolon-separated
--pesterForce Pester 5; fail if it is not installed
--nativeForce the bundled engine
--verboseShow per-case timings
--no-pauseSkip the return-to-menu pause in the TUI

The runner exits 0 when every case passes and 1 when any case fails.

TUI keys

KeyAction
↑ / ↓Move the selection
EnterRun the selected suite
1–9, 0Jump to a suite by number
ARun all suites
PToggle Pester 5 / native engine (when Pester is available)
VToggle verbose timings
Q / EscQuit

Suite inventory

SuiteSlugFocus
01_SyntaxAndDocs01_syntaxanddocsParses every project .ps1; entry points, launcher hygiene, documentation set, catalog-count alignment
02_Catalog02_catalogFive modules, twenty-four actions, unique IDs, required fields, search, menu reachability
03_Paths03_pathsNormalization, drive roots, protected paths, scan roots, containment, validation
04_Junctions04_junctionsMissing/not-a-junction/active/orphaned/empty classification, discovery, summary, stale filter
05_Operations05_operationsCreate, retarget rollback, repair, remove, empty-target deletion, dry-run, cleanup
06_Inventory06_inventoryJSON/CSV export, empty CSV, dry-run export, round-trip import, restore guards, backup
07_Cli07_cliHelp, list, search, inspect, create/retarget/remove, dry-run cleanup, usage errors, destructive refusal
08_CrossVolume08_crossvolumeAlternate-volume targets, native results, alternate-volume link attempts, separator normalization

Engine selection

flowchart TD
    A[Start] --> B{--pester?}
    B -- yes --> C{Pester 5 available?}
    C -- no --> X[Error with install hint]
    C -- yes --> P[Pester 5]
    B -- no --> D{--native?}
    D -- yes --> N[Native engine]
    D -- no --> E{Pester 5 installed?}
    E -- yes --> P
    E -- no --> N

The native engine is not a mock of the product. It is a small test harness that implements the subset of Pester the suites use:

  • BeforeAll, BeforeEach, AfterEach;
  • Describe, It;
  • Should with Be, BeTrue, BeFalse, BeNullOrEmpty, BeGreaterOrEqual, BeLessOrEqual, Match, Contain, BeIn, Throw, and -Not.

If a suite uses a Pester feature outside this subset, it will pass under Pester 5 and fail under the native engine. Keep suites inside the shared subset so both engines behave identically.

Test harness API

tests/helpers/TestHarness.ps1 exposes:

FunctionPurpose
Get-WjmTestRepoRootResolve the repository root from tests/helpers
Get-WjmTestCoreModulePathsRead src/core/manifest.ps1 and return the product’s load order
Invoke-WjmNativeSuiteFileRun one suite with the native shim and return pass/fail counts

The native shim removes any loaded Pester module first, so an older Windows PowerShell Pester cannot hijack the shim when pwsh starts without a clean module path.

Junction test kit

tests/helpers/JunctionTestKit.ps1 provides capability-based fixtures. It follows the same rule as the product: do not gate on filesystem type.

FunctionPurpose
New-WjmTestWorkspaceCreate a temp workspace with target, target2, link, and link2
Get-WjmTestAlternateVolumeRootReturn a second ready fixed volume, or ''
New-WjmTestFileWrite a fixture file, creating parents
New-WjmTestJunctionTry New-Item -ItemType Junction, then mklink /J for broken-target cases
Remove-WjmTestJunctionDetach a link non-recursively, then fall back to rmdir
Remove-WjmTestWorkspaceDetach links first, then remove the workspace tree

Design rules

  1. Attempt, then inspect. A test performs the operation and asserts on the native result instead of skipping because a volume is “not NTFS”.
  2. Links live where creation is most likely to succeed. Workspaces use the current user’s temp directory.
  3. Targets may live elsewhere. When a second fixed volume exists, the kit creates a cross-volume target. If the volume rejects directory creation, the alternate paths are left empty rather than faked.
  4. Cleanup never follows a reparse point. Links are detached before the workspace tree is removed.

Broken junctions

New-Item -ItemType Junction refuses to create a link to a missing target. Broken-junction coverage therefore uses cmd.exe /c mklink /J, which can create the link anyway. This is a testing concern only; the product still surfaces whatever Windows reports.

Writing a suite

  1. Add tests/suites/NN_Name.Tests.ps1.
  2. Start with #Requires -Version 7.0.
  3. In BeforeAll, resolve the repo root, load TestHarness.ps1 and JunctionTestKit.ps1, then dot-source every core module via Get-WjmTestCoreModulePaths.
  4. Use Describe and It. Use BeforeEach/AfterEach for fixtures and cleanup.
  5. Use junction fixtures for filesystem cases and plain temp files where a junction is not required.
  6. Assert behavior and result fields, not console formatting.
  7. Run under both engines when possible:
tests\RunTests.bat --suite NN --native
tests\RunTests.bat --suite NN --pester

The runner auto-discovers new files; no registration is required.

Continuous integration

The test workflow runs on Windows with PowerShell 7 and exercises both engines:

  • checkout;
  • install Pester 5;
  • run tests\Run-Tests.ps1 --all --native --no-pause;
  • run tests\Run-Tests.ps1 --all --pester --no-pause.

Running both engines keeps the native shim in sync with the Pester suites. The cross-volume suite is written to pass when only one volume exists: it attempts the operation and asserts on the observed native result.

Troubleshooting

SymptomCauseFix
Pester 5+ is not installed--pester was forcedInstall Pester 5 or use --native
A suite passes in Pester but fails nativelyThe suite uses a Pester feature outside the shim subsetRewrite the assertion using the supported set
Junction tests fail with access deniedThe temp location or parent requires different ACLsRun the session where the user can write the temp tree
Cross-volume case is skipped-lookingNo second fixed volume existsExpected; the test asserts on the native outcome, not a skip