You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Find the repository root from the session location, not the process working directory
Run.RepoRoot decides which Pester.BeforeContainer.ps1 files apply, and its default is found
by walking up for a .git directory. The walk ran in C# from Directory.GetCurrentDirectory(),
the process working directory, and Set-Location does not change that. So a session that
started somewhere else and then changed directory into a repository kept a RepoRoot pointing
at the old place, and the whole setup chain silently did not apply, with nothing to say why:
pwsh # process working directory is now ~
cd ~/p/myrepo
Invoke-Pester ./tests # RepoRoot was ~, no Pester.BeforeContainer.ps1 applied
FindRepoRoot takes the directory to start from now, and Invoke-Pester resolves RepoRoot from
$ExecutionContext.SessionState.Path.CurrentFileSystemLocation before the run, next to where
the shuffle seed is resolved. Same place Pester.Parallel.ps1 already takes the working
directory it hands to workers. Only when the option was not set, an explicit RepoRoot is the
user's to decide and is left alone.
The parameterless overload stays as the value an unused configuration object shows, so
[PesterConfiguration]::Default still reports a directory rather than nothing.
Tests: the cascade applies after Set-Location with no RepoRoot set, and the test asserts the
two locations actually disagree so it cannot pass by accident; an explicit RepoRoot survives
the run; FindRepoRoot falls back to the directory it started from when there is no .git.
Verified the first one fails without the change (43/44) and passes with it (44/44). Full
suite on PS 7.5 macOS: P phase clean, RSpec 2921 passed, 0 failed, 3 skipped.
about_PesterConfiguration.help.txt is regenerated by build.ps1 -Clean, so it is in the same
commit.
🤖
Copy file name to clipboardExpand all lines: src/csharp/Pester/RunConfiguration.cs
+21-5Lines changed: 21 additions & 5 deletions
Original file line number
Diff line number
Diff line change
@@ -86,7 +86,7 @@ public RunConfiguration(IDictionary configuration) : this()
86
86
FailOnNullOrEmptyForEach=newBoolOption("Fails discovery when -ForEach is provided $null or @() in a block or test. Can be overridden for a specific Describe/Context/It using -AllowNullOrEmptyForEach.",true);
87
87
Shuffle=newBoolOption("EXPERIMENTAL: Shuffle the order in which test files, and the blocks (Describe/Context) and tests (It) inside them, are executed. Items are only reordered within their own level. Uses Run.ShuffleSeed so a run can be repeated, and helps surface hidden dependencies between tests. A single file can opt out with a '#pester:no-shuffle' comment.",false);
88
88
ShuffleSeed=newIntOption("EXPERIMENTAL: Seed used to shuffle execution order when Run.Shuffle is enabled. The default 0 picks a new seed for each run and reports it at the start, so the run can be repeated by setting Run.ShuffleSeed to that value.",0);
89
-
RepoRoot=newStringOption("EXPERIMENTAL: Root directory of the repository. Found by searching for the .git directory recursively. When not found, the current working directory is used. Before each test file is discovered and run - in both sequential and parallel runs - Pester dot-sources every 'Pester.BeforeContainer.ps1' found from this directory down to the test file's own folder, outermost first, so helper modules or dot-sourced setup the parent session would normally provide are available to every container. Setup shared by all tests can live at the root while setup only some tests need lives in their folder. The files run before each container and must be safe to run more than once. This is especially useful in parallel runs where each worker starts from a clean runspace and re-runs them.",FindRepoRoot());
89
+
RepoRoot=newStringOption("EXPERIMENTAL: Root directory of the repository. Found when the run starts, by searching for the .git directory upwards from the current location. When not found, the current location is used. Before each test file is discovered and run - in both sequential and parallel runs - Pester dot-sources every 'Pester.BeforeContainer.ps1' found from this directory down to the test file's own folder, outermost first, so helper modules or dot-sourced setup the parent session would normally provide are available to every container. Setup shared by all tests can live at the root while setup only some tests need lives in their folder. The files run before each container and must be safe to run more than once. This is especially useful in parallel runs where each worker starts from a clean runspace and re-runs them.",FindRepoRoot());
90
90
}
91
91
92
92
publicStringArrayOptionPath
@@ -345,21 +345,37 @@ public IntOption ShuffleSeed
345
345
}
346
346
}
347
347
348
-
privatestaticstringFindRepoRoot()
348
+
/// <summary>
349
+
/// Walks up from startDirectory looking for a .git directory and returns the first directory
350
+
/// that has one, or startDirectory when there is none above it.
Copy file name to clipboardExpand all lines: src/en-US/about_PesterConfiguration.help.txt
+1-1Lines changed: 1 addition & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -81,7 +81,7 @@ SECTIONS AND OPTIONS
81
81
Type: bool
82
82
Default value: $true
83
83
84
-
RepoRoot: EXPERIMENTAL: Root directory of the repository. Found by searching for the .git directory recursively. When not found, the current working directory is used. Before each test file is discovered and run - in both sequential and parallel runs - Pester dot-sources every 'Pester.BeforeContainer.ps1' found from this directory down to the test file's own folder, outermost first, so helper modules or dot-sourced setup the parent session would normally provide are available to every container. Setup shared by all tests can live at the root while setup only some tests need lives in their folder. The files run before each container and must be safe to run more than once. This is especially useful in parallel runs where each worker starts from a clean runspace and re-runs them.
84
+
RepoRoot: EXPERIMENTAL: Root directory of the repository. Found when the run starts, by searching for the .git directory upwards from the current location. When not found, the current location is used. Before each test file is discovered and run - in both sequential and parallel runs - Pester dot-sources every 'Pester.BeforeContainer.ps1' found from this directory down to the test file's own folder, outermost first, so helper modules or dot-sourced setup the parent session would normally provide are available to every container. Setup shared by all tests can live at the root while setup only some tests need lives in their folder. The files run before each container and must be safe to run more than once. This is especially useful in parallel runs where each worker starts from a clean runspace and re-runs them.
0 commit comments