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

Docusaurus v3 #272

Merged
merged 13 commits into from
Nov 6, 2023
4 changes: 2 additions & 2 deletions docs/assertions/assertions.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ Set-Content -Path TestDrive:\file.txt -Value 'I am a file.'
```
:::

:::caution
:::warning
Make sure the input is either a quoted string or an Item object. Otherwise PowerShell will try to invoke the
path, likely throwing an error `Cannot run a document in the middle of a pipeline`.

Expand Down Expand Up @@ -352,7 +352,7 @@ so the following assertion will pass:
Wildcard-characters `?*[]` can be escaped using backtick, ex `` `*``.
:::

:::caution
:::warning
The input object must be a ScriptBlock, otherwise it is processed outside of the assertion.

```powershell
Expand Down
2 changes: 1 addition & 1 deletion docs/assertions/custom-assertions.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ If a problem occurs in your function, ex. it was called with invalid parameters,
`Should` accepts the value to assert by pipeline but passes it to the assertion using `-ActualValue $ActualValue`. This means `ValueFromPipelineByPropertyName` is not available inside your function, but you can write your own logic to work with complex types provided to `ActualValue`.
:::

:::caution Using advanced functions as assertions
:::warning Using advanced functions as assertions
Advanced functions, typically enabled by using `[CmdletBinding()]` or `[Parameter()]`, disallows arguments by default. In this scenario, make sure to accept all mandatory parameters in your param-block to avoid errors even if you don't use them. They are `ActualValue`, `Negate` and `CallerSessionState`.
:::

Expand Down
18 changes: 9 additions & 9 deletions docs/commands/Assert-MockCalled.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ Assert-MockCalled [-CommandName] <String> [[-Times] <Int32>] [-ParameterFilter <

## DESCRIPTION

{{ Fill in the Description }}
\{\{ Fill in the Description \}\}

## EXAMPLES

Expand All @@ -52,13 +52,13 @@ Assert-MockCalled [-CommandName] <String> [[-Times] <Int32>] [-ParameterFilter <
PS C:\> {{ Add example code here }}
```

{{ Add example description here }}
\{\{ Add example description here \}\}

## PARAMETERS

### -CommandName

{{ Fill CommandName Description }}
\{\{ Fill CommandName Description \}\}

```yaml
Type: String
Expand All @@ -74,7 +74,7 @@ Accept wildcard characters: False

### -Times

{{ Fill Times Description }}
\{\{ Fill Times Description \}\}

```yaml
Type: Int32
Expand All @@ -90,7 +90,7 @@ Accept wildcard characters: False

### -ParameterFilter

{{ Fill ParameterFilter Description }}
\{\{ Fill ParameterFilter Description \}\}

```yaml
Type: ScriptBlock
Expand All @@ -106,7 +106,7 @@ Accept wildcard characters: False

### -ExclusiveFilter

{{ Fill ExclusiveFilter Description }}
\{\{ Fill ExclusiveFilter Description \}\}

```yaml
Type: ScriptBlock
Expand All @@ -122,7 +122,7 @@ Accept wildcard characters: False

### -ModuleName

{{ Fill ModuleName Description }}
\{\{ Fill ModuleName Description \}\}

```yaml
Type: String
Expand All @@ -138,7 +138,7 @@ Accept wildcard characters: False

### -Scope

{{ Fill Scope Description }}
\{\{ Fill Scope Description \}\}

```yaml
Type: String
Expand All @@ -154,7 +154,7 @@ Accept wildcard characters: False

### -Exactly

{{ Fill Exactly Description }}
\{\{ Fill Exactly Description \}\}

```yaml
Type: SwitchParameter
Expand Down
4 changes: 2 additions & 2 deletions docs/commands/Assert-VerifiableMock.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ Assert-VerifiableMock [<CommonParameters>]

## DESCRIPTION

{{ Fill in the Description }}
\{\{ Fill in the Description \}\}

## EXAMPLES

Expand All @@ -41,7 +41,7 @@ Assert-VerifiableMock [<CommonParameters>]
PS C:\> {{ Add example code here }}
```

{{ Add example description here }}
\{\{ Add example description here \}\}

## PARAMETERS

Expand Down
38 changes: 20 additions & 18 deletions docs/usage/_GetEmoji.mdx
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
<details>
<summary>Required code for samples (PowerShell 6 or later)</summary>
To run the sample below, place this file in the same folder as Get-Emoji.Tests.ps1.
<summary>Required code for samples (PowerShell 6 or later)</summary>
<div>
To run the sample below, place this file in the same folder as Get-Emoji.Tests.ps1.

```powershell title="Get-Emoji.ps1"
$emojis = @(
@{ Name = 'apple'; Symbol = '🍎'; Kind = 'Fruit' }
@{ Name = 'beaming face with smiling eyes'; Symbol = '😁'; Kind = 'Face' }
@{ Name = 'cactus'; Symbol = '🌵'; Kind = 'Plant' }
@{ Name = 'giraffe'; Symbol = '🦒'; Kind = 'Animal' }
@{ Name = 'pencil'; Symbol = '✏️'; Kind = 'Item' }
@{ Name = 'penguin'; Symbol = '🐧'; Kind = 'Animal' }
@{ Name = 'pensive'; Symbol = '😔'; Kind = 'Face' }
@{ Name = 'slightly smiling face'; Symbol = '🙂'; Kind = 'Face' }
@{ Name = 'smiling face with smiling eyes'; Symbol = '😊'; Kind = 'Face' }
) | ForEach-Object { [PSCustomObject]$_ }
```powershell title="Get-Emoji.ps1"
$emojis = @(
@{ Name = 'apple'; Symbol = '🍎'; Kind = 'Fruit' }
@{ Name = 'beaming face with smiling eyes'; Symbol = '😁'; Kind = 'Face' }
@{ Name = 'cactus'; Symbol = '🌵'; Kind = 'Plant' }
@{ Name = 'giraffe'; Symbol = '🦒'; Kind = 'Animal' }
@{ Name = 'pencil'; Symbol = '✏️'; Kind = 'Item' }
@{ Name = 'penguin'; Symbol = '🐧'; Kind = 'Animal' }
@{ Name = 'pensive'; Symbol = '😔'; Kind = 'Face' }
@{ Name = 'slightly smiling face'; Symbol = '🙂'; Kind = 'Face' }
@{ Name = 'smiling face with smiling eyes'; Symbol = '😊'; Kind = 'Face' }
) | ForEach-Object { [PSCustomObject]$_ }

function Get-Emoji ([string]$Name = '*') {
$emojis | Where-Object Name -like $Name | ForEach-Object Symbol
}
```
function Get-Emoji ([string]$Name = '*') {
$emojis | Where-Object Name -like $Name | ForEach-Object Symbol
}
```
</div>
</details>
90 changes: 46 additions & 44 deletions docs/usage/_PesterDemoFunctions.mdx
Original file line number Diff line number Diff line change
@@ -1,53 +1,55 @@
<details>
<summary>Required code for samples (PowerShell 6 or later)</summary>
This module is required for the Emoji and Fruit tests below. Copy and paste this in your console before running the tests.
<summary>Required code for samples (PowerShell 6 or later)</summary>
<div>
This module is required for the Emoji and Fruit tests below. Copy and paste this in your console before running the tests.

```powershell
Get-Module PesterDemoFunctions | Remove-Module
New-Module PesterDemoFunctions -ScriptBlock {
$emojis = @(
@{ Name = 'apple'; Symbol = '🍎'; Kind = 'Fruit' }
@{ Name = 'beaming face with smiling eyes'; Symbol = '😁'; Kind = 'Face' }
@{ Name = 'cactus'; Symbol = '🌵'; Kind = 'Plant' }
@{ Name = 'giraffe'; Symbol = '🦒'; Kind = 'Animal' }
@{ Name = 'pencil'; Symbol = '✏️'; Kind = 'Item' }
@{ Name = 'penguin'; Symbol = '🐧'; Kind = 'Animal' }
@{ Name = 'pensive'; Symbol = '😔'; Kind = 'Face' }
@{ Name = 'slightly smiling face'; Symbol = '🙂'; Kind = 'Face' }
@{ Name = 'smiling face with smiling eyes'; Symbol = '😊'; Kind = 'Face' }
) | ForEach-Object { [PSCustomObject]$_ }
```powershell
Get-Module PesterDemoFunctions | Remove-Module
New-Module PesterDemoFunctions -ScriptBlock {
$emojis = @(
@{ Name = 'apple'; Symbol = '🍎'; Kind = 'Fruit' }
@{ Name = 'beaming face with smiling eyes'; Symbol = '😁'; Kind = 'Face' }
@{ Name = 'cactus'; Symbol = '🌵'; Kind = 'Plant' }
@{ Name = 'giraffe'; Symbol = '🦒'; Kind = 'Animal' }
@{ Name = 'pencil'; Symbol = '✏️'; Kind = 'Item' }
@{ Name = 'penguin'; Symbol = '🐧'; Kind = 'Animal' }
@{ Name = 'pensive'; Symbol = '😔'; Kind = 'Face' }
@{ Name = 'slightly smiling face'; Symbol = '🙂'; Kind = 'Face' }
@{ Name = 'smiling face with smiling eyes'; Symbol = '😊'; Kind = 'Face' }
) | ForEach-Object { [PSCustomObject]$_ }

function Get-Emoji ([string]$Name = '*') {
$script:emojis | Where-Object Name -like $Name | ForEach-Object Symbol
}
function Get-Emoji ([string]$Name = '*') {
$script:emojis | Where-Object Name -like $Name | ForEach-Object Symbol
}

function Get-EmojiKind {
param(
[Parameter(Mandatory = $true, ValueFromPipeline = $true)]
[string]$Emoji
)
process {
$script:emojis | Where-Object Symbol -eq $Emoji | Foreach-Object Kind
}
}
function Get-EmojiKind {
param(
[Parameter(Mandatory = $true, ValueFromPipeline = $true)]
[string]$Emoji
)
process {
$script:emojis | Where-Object Symbol -eq $Emoji | Foreach-Object Kind
}
}

$fruitBasket = [System.Collections.ArrayList]@('🍎','🍌','🥝','🥑','🍇','🍐')
$fruitBasket = [System.Collections.ArrayList]@('🍎','🍌','🥝','🥑','🍇','🍐')

function Get-FruitBasket {
$script:fruitBasket
}
function Get-FruitBasket {
$script:fruitBasket
}

function Remove-FruitBasket {
param(
[Parameter(Mandatory = $true)]
[string]$Item
)
$script:fruitBasket.Remove($Item)
}
function Remove-FruitBasket {
param(
[Parameter(Mandatory = $true)]
[string]$Item
)
$script:fruitBasket.Remove($Item)
}

function Reset-FruitBasket {
$script:fruitBasket = [System.Collections.ArrayList]@('🍎','🍌','🥝','🥑','🍇','🍐')
}
} | Import-Module
```
function Reset-FruitBasket {
$script:fruitBasket = [System.Collections.ArrayList]@('🍎','🍌','🥝','🥑','🍇','🍐')
}
} | Import-Module
```
</div>
</details>
4 changes: 2 additions & 2 deletions docs/usage/importing-tested-functions.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ BeforeAll {

This avoids spelling out the name of the referenced file every time.

:::caution
:::warning
The code above is using `string.Replace()` method which is case sensitive. Make sure you say `Tests` and that the test file is named `.Tests.ps1`.
:::

:::caution
:::warning
Pester v4 users might be inclined not to use the `BeforeAll` block or to use `$MyInvocation.MyCommand.Path` in `BeforeAll`. Neither will work. See [Migrating from Pester v4](#migrating-from-pester-v4).
:::

Expand Down
2 changes: 1 addition & 1 deletion docs/usage/modules.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ Describe "Unit testing the module's internal Build function:" {

Notice that when using `InModuleScope`, you no longer need to specify a `-ModuleName` parameter when calling `Mock` or `Should -Invoke` for commands within that module. You are also able to directly call the `Build` function, which the module does not export.

:::caution Avoid putting in InModuleScope around your Describe and It blocks.
:::warning Avoid putting in InModuleScope around your Describe and It blocks.

`InModuleScope` is a simple way to expose your internal module functions to be tested, but it prevents you from properly testing your published functions, does not ensure that your functions are actually published and slows down test discovery by loading the module. Aim to avoid it altogether by using `-ModuleName` on `Mock` when possible or at least limit it to inside the It block like the sample above.
:::
Expand Down
2 changes: 1 addition & 1 deletion docs/usage/skip.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ Tests completed in 1.03s
Tests Passed: 1, Failed: 0, Skipped: 4, Total: 5, NotRun: 0
```

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

Expand Down
2 changes: 1 addition & 1 deletion docs/usage/test-file-structure.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Describe "Get-Emoji" {
}
```

:::caution
:::warning
Put all your code into `It`, `BeforeAll`, `BeforeEach`, `AfterAll` or `AfterEach`. Put no code directly into `Describe`, `Context` or on the top of your file, without wrapping it in one of these blocks, unless you have a good reason to do so.

All misplaced code will run during Discovery, and its results won't be available during Run which will lead to confusing results.
Expand Down
2 changes: 1 addition & 1 deletion docs/usage/testdrive.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Basic scoping rules are implemented for the TestDrive:
3. When exiting a block, files and folders created during it's lifetime will be removed. Modifications to items created in parent blocks are not reversed, see caution below.
4. When the whole container is finished, the TestDrive and all files and folders inside it is deleted.

:::caution Modifications to existing items are not reversed
:::warning Modifications to existing items are not reversed
Be aware that the TestDrive content is tracked by paths. When entering a block, all paths which already exists will be excluded during cleanup when exiting the block.
In practice this means that if you create a file in the Describe block and then change its content inside the Context block, the modifications or deletions are preserved even after you left the Context block.
:::
Expand Down
14 changes: 7 additions & 7 deletions docusaurus.config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
/**
* Please note that the syntax highlighting theme CANNOT be configured here,
* it MUST be configured in swizzled shadow component `/src/theme/index.js`
*/
const { themes } = require('prism-react-renderer');

module.exports = {
title: 'Pester',
tagline: 'The ubiquitous test and mock framework for PowerShell',
Expand Down Expand Up @@ -59,10 +57,12 @@ module.exports = {
],
},
prism: {
theme: require('prism-react-renderer/themes/github'),
darkTheme: require('prism-react-renderer/themes/oceanicNext'),
theme: themes.github,
darkTheme: themes.oceanicNext,
additionalLanguages: [
'powershell'
'bash',
'powershell',
'yaml'
]
},
// Please note that the Algolia DocSearch crawler only runs once every 24 hours.
Expand Down
15 changes: 6 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,14 @@
"write-heading-ids": "docusaurus write-heading-ids"
},
"dependencies": {
"@docusaurus/core": "^2.4.1",
"@docusaurus/preset-classic": "^2.4.1",
"@mdx-js/react": "^1.6.22",
"@svgr/webpack": "^5.5.0",
"@docusaurus/core": "^3.0.0",
"@docusaurus/preset-classic": "^3.0.0",
"@mdx-js/react": "^3.0.0",
"@tanstack/react-table": "^8.10.0",
"classnames": "^2.2.6",
"clsx": "^1.2.1",
"file-loader": "^6.2.0",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"url-loader": "^4.1.1"
"prism-react-renderer": "^2.1.0",
"react": "^18.2.0",
"react-dom": "^18.2.0"
},
"browserslist": {
"production": [
Expand Down
Loading