Skip to content

Commit 781fa8b

Browse files
committed
test: 为慢速测试添加标记并优化测试脚本
- 为 Unix Profile 性能基准和 DryRun 测试添加 'Slow' 标签,便于单独运行 - 将 Sync-PathFromBash 测试中的模块导入移至 BeforeAll 块,确保测试隔离 - 修复 package.json 中测试命令的转义和环境变量语法,确保跨平台一致性 - 将 qa:pwsh 命令默认使用 test:fast 以加速代码质量检查流程
1 parent bd67410 commit 781fa8b

4 files changed

Lines changed: 12 additions & 11 deletions

File tree

package.json

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,19 @@
2020
"pwsh:install": "pwsh -File ./install.ps1",
2121
"pester:install": "pwsh -NoProfile -Command \"Install-Module -Name Pester -Scope CurrentUser -Force -SkipPublisherCheck -AllowClobber\"",
2222
"pester:update": "pwsh -NoProfile -Command \"Update-Module -Name Pester -Force -ErrorAction Stop\"",
23-
"test": "pwsh -Command \"Invoke-Pester -Configuration ( ./PesterConfiguration.ps1 )\"",
24-
"test:full": "pwsh -Command \"$env:PWSH_TEST_MODE='full'; Invoke-Pester -Configuration ( ./PesterConfiguration.ps1 )\"",
25-
"test:fast": "pwsh -NoProfile -Command \"$env:PWSH_TEST_MODE='fast'; Invoke-Pester -Configuration ( ./PesterConfiguration.ps1 )\"",
26-
"test:serial": "pwsh -NoProfile -Command \"$env:PWSH_TEST_MODE='serial'; Invoke-Pester -Configuration ( ./PesterConfiguration.ps1 )\"",
27-
"test:debug": "pwsh -NoProfile -Command \"$env:PWSH_TEST_MODE='debug'; Invoke-Pester -Configuration ( ./PesterConfiguration.ps1 )\"",
28-
"test:serial:debug": "pwsh -NoProfile -Command \"$env:PWSH_TEST_MODE='serial'; $env:PWSH_TEST_VERBOSE='1'; Invoke-Pester -Configuration ( ./PesterConfiguration.ps1 )\"",
29-
"test:profile": "pwsh -NoProfile -Command \"$env:PWSH_TEST_MODE='serial'; $env:PWSH_TEST_PATH='./tests/ProfileMode.Tests.ps1'; $env:PWSH_TEST_VERBOSE='1'; Invoke-Pester -Configuration ( ./PesterConfiguration.ps1 )\"",
23+
"test": "pwsh -NoProfile -Command \"Invoke-Pester -Configuration ( ./PesterConfiguration.ps1 )\"",
24+
"test:full": "pwsh -Command \"\\$env:PWSH_TEST_MODE='full'; Invoke-Pester -Configuration ( ./PesterConfiguration.ps1 )\"",
25+
"test:fast": "pwsh -NoProfile -Command \"\\$env:PWSH_TEST_MODE='fast'; Invoke-Pester -Configuration ( ./PesterConfiguration.ps1 )\"",
26+
"test:serial": "pwsh -NoProfile -Command \"\\$env:PWSH_TEST_MODE='serial'; Invoke-Pester -Configuration ( ./PesterConfiguration.ps1 )\"",
27+
"test:debug": "pwsh -NoProfile -Command \"\\$env:PWSH_TEST_MODE='debug'; Invoke-Pester -Configuration ( ./PesterConfiguration.ps1 )\"",
28+
"test:serial:debug": "pwsh -NoProfile -Command \"\\$env:PWSH_TEST_MODE='serial'; \\$env:PWSH_TEST_VERBOSE='1'; Invoke-Pester -Configuration ( ./PesterConfiguration.ps1 )\"",
29+
"test:profile": "pwsh -NoProfile -Command \"\\$env:PWSH_TEST_MODE='serial'; \\$env:PWSH_TEST_PATH='./tests/ProfileMode.Tests.ps1'; \\$env:PWSH_TEST_VERBOSE='1'; Invoke-Pester -Configuration ( ./PesterConfiguration.ps1 )\"",
3030
"test:detailed": "pwsh -Command \"Invoke-Pester -Output Detailed\"",
3131
"scripts:install": "pwsh -File ./install.ps1",
3232
"scoop:update": "scoop update -a",
3333
"choco:update": "choco upgrade all -y",
3434
"nb:clean": "pwsh -NoProfile -Command \"fd -e ipynb |ForEach-Object { nbstripout $_ }\"",
35-
"qa:pwsh": "pnpm format:pwsh && pnpm test",
35+
"qa:pwsh": "pnpm format:pwsh && pnpm test:fast",
3636
"qa": "node ./scripts/qa.mjs changed",
3737
"qa:all": "node ./scripts/qa.mjs all",
3838
"qa:verbose": "node ./scripts/qa.mjs changed --verbose",

psutils/tests/profile_unix.Tests.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
param()
22

3-
Describe 'Unix Profile 性能基准' -Tag 'profile', 'performance', 'unix' {
3+
Describe 'Unix Profile 性能基准' -Tag 'profile', 'performance', 'unix', 'Slow' {
44
BeforeAll {
55
$RepoRoot = (Resolve-Path (Join-Path $PSScriptRoot '..' '..')).Path
66
$script:ProfilePath = Join-Path $RepoRoot 'profile' 'profile_unix.ps1'

tests/Switch-Mirrors.Tests.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ Describe 'Switch-Mirrors.ps1' {
1818
$r.Success | Should -BeFalse
1919
}
2020

21-
It 'DryRun 写入不应实际修改文件(仅输出)' {
21+
It 'DryRun 写入不应实际修改文件(仅输出)' -Tag 'Slow' {
2222
$scriptPath = Join-Path $PSScriptRoot '..' 'scripts' 'pwsh' 'misc' 'Switch-Mirrors.ps1'
2323
$daemon = if ($IsLinux) { '/etc/docker/daemon.json' } elseif ($IsWindows) { Join-Path $env:ProgramData 'Docker\config\daemon.json' } else { Join-Path $HOME '.docker/daemon.json' }
2424
$before = if (Test-Path -LiteralPath $daemon) { Get-Content -LiteralPath $daemon -Raw } else { '' }

tests/Sync-PathFromBash.Tests.ps1

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
Set-StrictMode -Version Latest
2-
Import-Module "$PSScriptRoot/../psutils/modules/env.psm1" -Force
32

43
Describe 'Sync-PathFromBash basic behavior' {
54
BeforeAll {
5+
Import-Module "$PSScriptRoot/../psutils/modules/env.psm1" -Force
66
$script:OriginalMockPath = $env:PWSH_TEST_BASH_PATH
77
$env:PWSH_TEST_BASH_PATH = "C:\Fake\Bin;C:\Windows\System32"
88
}
@@ -34,6 +34,7 @@ Describe 'Sync-PathFromBash basic behavior' {
3434

3535
Describe 'Sync-PathFromBash cache and error semantics' {
3636
BeforeAll {
37+
Import-Module "$PSScriptRoot/../psutils/modules/env.psm1" -Force
3738
$script:OriginalMockPath = $env:PWSH_TEST_BASH_PATH
3839
$env:PWSH_TEST_BASH_PATH = "C:\Fake\Bin;C:\Windows\System32"
3940
}

0 commit comments

Comments
 (0)