From 4d19f913e18bbd87a6ec8d57cc5504c26ecc886a Mon Sep 17 00:00:00 2001 From: Alex Kup <116945542+Lifailon@users.noreply.github.com> Date: Tue, 20 Feb 2024 21:52:10 +0300 Subject: [PATCH] Add example pester --- README.md | 73 ++++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 70 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index dd5500b..f71cbde 100644 --- a/README.md +++ b/README.md @@ -103,6 +103,7 @@ - [VideoCDN](#videocdn) - [Telegram](#telegram) - [Discord](#discord) +- [Pester](#pester) # Help @@ -149,10 +150,23 @@ ```PowerShell Install-Module themes-performance -Repository NuGet Import-Module themes-performance -Set-PoshTheme -Theme System-Sensors -Set-PoshTheme -Theme System-Performance -Set-PoshTheme -Theme Pwsh-Process-Performance +Set-PoshTheme -Theme System-Sensors # -Save +Set-PoshTheme -Theme System-Performance # -Save +Set-PoshTheme -Theme Pwsh-Process-Performance # -Save ``` +### Terminal-Icons + +`Install-Module -Name Terminal-Icons -Repository PSGallery` \ +`scoop bucket add extras` \ +`scoop install terminal-icons` + +`notepad $PROFILE` \ +`Import-Module -Name Terminal-Icons` + +Использует шрифты, которые необходимо установить и настроить в параметрах профиля PowerShell: [Nerd Fonts](https://github.com/ryanoasis/nerd-fonts) \ +Список шрифтов: https://www.nerdfonts.com/font-downloads \ +Скачать и установить шрифт похожий на Cascadia Code - [CaskaydiaCove](https://github.com/ryanoasis/nerd-fonts/releases/download/v3.1.1/CascadiaCode.zip) + # Object ### Variable @@ -7168,3 +7182,56 @@ $Client.ConnectionState $Client.LogoutAsync().GetAwaiter().GetResult() $Client.Dispose() ``` +# Pester + +[Pester](https://github.com/pester/Pester) + +`Install-Module -Name Pester -Repository PSGallery -Force -AllowClobber` \ +`Import-Module Pester` \ +`$(Get-Module Pester -ListAvailable).Version` + +`.Tests.ps1` +```PowerShell +function Add-Numbers { + param ( + [int]$a, + [int]$b + ) + $a + $b +} +Describe "Add-Numbers" { + Context "При сложении двух чисел" { + It "Должна вернуться правильная сумма" { + $result = Add-Numbers -a 3 -b 4 + $result | Should -Be 7 + } + } + Context "При сложении двух чисел" { + It "Должна вернуться ошибка (5+0 -ne 4)" { + $result = Add-Numbers -a 5 -b 0 + $result | Should -Be 4 + } + } +} + +function Get-RunningProcess { + return Get-Process | Select-Object -ExpandProperty Name +} +Describe "Get-RunningProcess" { + Context "При наличии запущенных процессов" { + It "Должен возвращать список имен процессов" { + $result = Get-RunningProcess + $result | Should -Contain "svchost" + $result | Should -Contain "explorer" + } + } + Context "Когда нет запущенных процессов" { + It "Должен возвращать пустой список" { + # Замокать функцию Get-Process, чтобы она всегда возвращала пустой список процессов + Mock Get-Process { return @() } + $result = Get-RunningProcess + $result | Should -BeEmpty + } + } +} +```