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

Misc updates to docs #309

Merged
merged 8 commits into from
Jan 10, 2025
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 14 additions & 12 deletions docs/migrations/breaking-changes-in-v5.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -6,34 +6,36 @@ description: Pester v5 included an all-new runtime which lead to some breaking c

## Actual breaking changes

- (❗ new in 5.0.1) The Parameters of `Invoke-Pester` changed significantly, but in 5.0.1, a compatibility parameter set was added. To allow all the v4 parameters to be used, e.g. like this `Invoke-Pester -Script $testFile -PassThru -Verbose -OutputFile $tr -OutputFormat NUnitXml -CodeCoverage "$tmp/*-*.ps1" -CodeCoverageOutputFile $cc -Show All`. The compatibility is not 100%, neither -Script not -CodeCoverage take hashtables, they just take a collection of paths. The `-Strict` parameter and `-PesterOption` are ignored. The `-Output` \ `-Show` parameter takes all the values, but translates only the most used options to Pester 5 compatible options, otherwise it uses `Detailed` output. It also allows all the Pester 5 output options, to allow you to use `Diagnostic` during migration. **This whole Legacy-parameter set is deprecated** and prints a warning when used. For more options and the Advanced interface see [simple and advanced interface](./v4-to-v5#simple-and-advanced-interface) above on how to invoke Pester.
- The Parameters of `Invoke-Pester` changed significantly, but a compatibility parameter set was added to allow all the v4 parameters to be used, e.g. like this `Invoke-Pester -Script $testFile -PassThru -Verbose -OutputFile $tr -OutputFormat NUnitXml -CodeCoverage "$tmp/*-*.ps1" -CodeCoverageOutputFile $cc -Show All`. Be aware of these limitations and notes:
- The compatibility is not 100%, neither `-Script` not `-CodeCoverage` take hashtables, they just take a collection of paths.
- The `-Strict` parameter and `-PesterOption` are ignored.
- The `-Output` \ `-Show` parameter takes all the values, but translates only the most used options to Pester 5 compatible options, otherwise it uses `Detailed` output. It also allows all the Pester 5 output options, to allow you to use `Diagnostic` during migration.
- **This whole Legacy-parameter set is deprecated** and prints a warning when used. For more options and the Advanced interface see [simple and advanced interface](./v4-to-v5#simple-and-advanced-interface) above on how to invoke Pester.
- PowerShell 2 is no longer supported
- Legacy syntax `Should Be` (without `-`) is removed, see [Migrating from Pester v3 to v4](./v3-to-v4)
- Mocks are scoped based on their placement, not in whole `Describe` / `Context`. The count also depends on their placement. See [mock scoping](../usage/mocking#mocks-are-scoped-based-on-their-placement)
- `Assert-VerifiableMocks` was removed, see [Should -Invoke](../usage/mocking#should--invoke)
- All code placed in the body of `Describe` outside of `It`, `BeforeAll`, `BeforeEach`, `AfterAll`, `AfterEach` will run during discovery and it's state might or might not be available to the test code, see [Discovery and Run](../usage/discovery-and-run)

- `-Output` parameter has reduced options to `None`, `Normal`, `Detailed` and `Diagnostic`, `-Show` alias is removed
- `-Output` parameter has reduced options to `None`, `Normal`, `Detailed` and `Diagnostic`. `-Show` alias is removed
- `-PesterOption` switch is removed
- `-TestName` switch is replaced with `-FullNameFilter` switch
- `-Script` option was renamed to `-Path` and takes paths only, it does not take hashtables. For parametrized scripts, see [Providing external data to tests](../usage/data-driven-tests#providing-external-data-to-tests)
- Using `$MyInvocation.MyCommand.Path` to locate your script in `BeforeAll` does not work. This does not break it for your scripts and modules. Use `$PSScriptRoot` or `$PSCommandPath`. See [Migrating from Pester v4](../usage/importing-tested-functions#migrating-from-pester-v4) or the [importing ps files](https://jakubjares.com/2020/04/11/pester5-importing-ps-files/) article for detailed information.
- Should `-Throw` is using `-like` to match the exception message instead of .Contains. Use `*` or any of the other `-like` wildcard to match only part of the message.
- Variables defined during Discovery, are not available in Before*, After* and It. When generating tests via foreach blocks, make sure you pass all variables into the test using -TestCases / -ForEach.
- Gherkin is removed, and will later move to it's own module, please keep using Pester version 4.
- `TestDrive` is defined during Run only, it cannot be used in -TestCases / -ForEach.
- Variables defined during Discovery, are not available in `BeforeAll/-Each`, `AfterAll/-Each` and `It`. When generating tests via foreach blocks, make sure you pass all variables into the test using `-ForEach`.
- Gherkin is removed, please keep using Pester version 4.
- `TestDrive` is defined during Run only, it cannot be used in `-ForEach`.

### Deprecated features

- `Assert-MockCalled` is deprecated, it is recommended to use [Should -Invoke](../usage/mocking)
- `Assert-VerifiableMock` is deprecated, it is recommended to use [Should -InvokeVerifiable](../usage/mocking)
- `Assert-MockCalled` is deprecated, it is recommended to use [Should -Invoke](../usage/mocking).
- `Assert-VerifiableMock` is deprecated, it is recommended to use [Should -InvokeVerifiable](../usage/mocking).
- Pending state (`Set-ItResult -Pending`) is deprecated and will be removed in a future version.

### Additional issues to be solved future releases

- `-Strict` switch is not available
- Inconclusive and Pending states are currently no longer available, `-Pending` and `-Inconclusive` are translated to `-Skip` both on test blocks and when using `Set-ItResult`
- Automatic Code coverage via -CI switch currently disabled as it's slow. Can still be enabled using configuration, but is largely untested.
- Generating tests using foreach during discovery time works mostly, generating them from BeforeAll, to postpone expensive work till it is needed in case the test is filtered out also works, but is hacky. Get in touch if you need it and help me refine it.
- Running on huge codebases is largely untested
- Automatic Code coverage via -CI switch currently disabled as it's slow. Can still be enabled using configuraitonis largely untested.
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove comment about being untested?



**Noticed more of them? Share please!**
24 changes: 12 additions & 12 deletions docs/migrations/v4-to-v5.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -138,18 +138,18 @@ The following table shows a mapping of v4 Legacy parameters (those which have no

</div>

The following table shows the mapping for v4 *Show* property values to the configuration property *Output.Verbosity*:
The following table shows the mapping for v4 `-Show` property values to the configuration property `Output.Verbosity`:

| *Show* value | Configuration Object *Output Verbosity* Property |
| ------------ | ------------------------------------------------ |
| All | Detailed |
| Default | Detailed |
| Detailed | Detailed |
| Fails | Normal |
| Diagnostic | Diagnostic |
| Normal | Normal |
| Minimal | Minimal |
| None | None |
| `-Show` Value | `Output.Verbosity` Property |
| ------------- | ----------------------------|
| All | Detailed |
| Default | Detailed |
| Detailed | Detailed |
| Fails | Normal |
| Diagnostic | Diagnostic |
| Normal | Normal |
| Minimal | Minimal |
| None | None |


### Implicit parameters for TestCases
Expand All @@ -170,7 +170,7 @@ This also works for Mock.

#### Mocks can be debugged

Mocks don't rewrite the scriptblock you provide anymore. You can now set breakpoints into them as well as any of the ParameterFilter or Should -Invoke Parameter filter.
Mocks don't rewrite the scriptblock you provide anymore. You can now set breakpoints into them as well as any of the `-ParameterFilter` used in `Mock` and `Should -Invoke`.

#### Avoid putting in InModuleScope around your Describe and It blocks

Expand Down
6 changes: 3 additions & 3 deletions docs/usage/output.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ This option controls the general level of console output. Pester v5 supports the

### StackTraceVerbosity

**New in Pester 5.3!**
**New in Pester 5.3.0!**<br/>
When an error is shown due to a failed setup or test, a stacktrace is included to help you identify where the problem occured. Users might not care much about this while developers need it to identify and fix any issues.
This option lets you control how much of the stacktrace that will be printed using one of the following levels:

Expand All @@ -50,7 +50,7 @@ The result-object returned from `Run.PassThru / -PassThru` includes a `ErrorReco

### CIFormat

**New in Pester 5.3!**
**New in Pester 5.3.0!**<br/>
Pester supports CI-specific output syntaxes to highlight, log and navigate to errors in your tests for a few popular CI systems. This options lets your control how this behavior should work. The following levels are currently supported:

- **None**: Disable all CI-specific syntax. Error messages are presented in the format you're familiar with.
Expand Down Expand Up @@ -78,7 +78,7 @@ Auto-detection works by checking if `GITHUB_ACTIONS` environment variable is equ

### RenderMode

**New in Pester 5.4!**
**New in Pester 5.4.0!**<br/>
Pester supports multiple render modes for console output, including ANSI escape sequences which enables colors in CI-logs. The currently supported modes are:

- **Auto (default)**: Automatically enables the recommended mode using the following rules:
Expand Down
10 changes: 5 additions & 5 deletions docs/usage/skip.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,9 @@ Tests completed in 1.03s
Tests Passed: 1, Failed: 0, Skipped: 4, Total: 5, NotRun: 0
```

:::warning
Pending is translated to skipped, Inconclusive does not exist anymore.
:::

### Conditional skip

Evaluation of the skip-parameter is done as part of the Discovery-phase. This means you can also dynamically skip tests based on values available in that phase. Either as logic done in BeforeDiscovery or based on values passed into a parametrized test.
Evaluation of the skip-parameter is done as part of the Discovery-phase. This means you can also dynamically skip tests based on values available in that phase. Either as logic done in `BeforeDiscovery` or based on values passed into a parametrized test.

```powershell
$sb = {
Expand Down Expand Up @@ -126,3 +122,7 @@ Describing My Describe Block
Tests completed in 206ms
Tests Passed: 1, Failed: 0, Skipped: 2 NotRun: 0
```

:::tip Skipping during Run-phase
In certain scenarios you might need to mark a test as skipped or inconclusive during execution. This is possible using [`Set-ItResult`](../commands/Set-ItResult). Be aware that setup and teardown-blocks will be executed, so use `-Skip` whenever possible.
:::