Assert-ConsoleOutput
Compares console output with a golden file (for Pester and other tests).
Syntax
Assert-ConsoleOutput
[-Culture <CultureInfo>]
[-Glyphs <Ascii| Basic| Full>]
[-GoldenPath] <String>
[-Height <Int32>]
[-InputObject] <Object>
[-PassThru]
[-Width <Int32>]
[<CommonParameters>]#All Parameter SetsDescription
Renders a widget at a fixed width, glyph tier and culture (invariant by default), so the result does not depend on the machine, and compares the text with a golden file. The first run writes the file and fails so it can be reviewed; a difference fails with the first differing line, both versions and the column where they part. Set CONSOLEMONSTER_UPDATE_GOLDEN=1 to rewrite golden files after an intended change. Strings are compared as they are. In Pester the thrown error fails the test; see the README for a Should operator built on it.
Examples
Example 1
# Requires Pester and the reviewed Golden/report.txt snapshot beside the test file.
It 'renders the report table' {
$goldenPath = Join-Path $PSScriptRoot 'Golden/report.txt'
if (-not (Test-Path -LiteralPath $goldenPath -PathType Leaf)) { throw 'Provide a reviewed golden file before running this example.' }
if ($env:CONSOLEMONSTER_UPDATE_GOLDEN -eq '1') { throw 'Golden updates must be disabled for this comparison.' }
$rows = @([pscustomobject]@{ Name = 'web01'; Status = 'Pass' })
$outputOptions = @{
GoldenPath = $goldenPath
Width = 80
}
$rows | New-ConsoleTable | Assert-ConsoleOutput @outputOptions
}Compare a table with an existing Pester golden file
Example 2
$view = New-ConsolePanel -Title 'Inventory' -Content {
$textOptions = @{
Text = @('web01: Pass')
}
New-ConsoleText @textOptions
}
$outputOptions = @{
PassThru = $true
InputObject = $view
GoldenPath = './inventory.txt'
}
Assert-ConsoleOutput @outputOptionsCheck an inventory panel against an existing baseline
Parameters
- -Culture CultureInfo
- The culture for numbers and dates (default: invariant).
- -Glyphs GlyphTier
- The glyph tier (default Full).
- Possible values:
Ascii,Basic,Full - -GoldenPath String
- Path to the expected plain-text rendering used for the comparison.
- -Height Int32
- Height in cells (default: as tall as the widget measures).
- -InputObject Object
- A widget, or text to compare as it is.
- -PassThru SwitchParameter
- Writes the rendered text to the pipeline when it matches.
- -Width Int32
- Width in cells (default 0: terminal width, falling back to 100).
Common Parameters
This command supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable.
For more information, see about_CommonParameters.