Skip to content

Commit 87ac2eb

Browse files
Update documentation to reflect separate BeforeAll/AfterAll job architecture
Co-authored-by: MariusStorhaug <[email protected]>
1 parent 7b69fe7 commit 87ac2eb

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

README.md

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@ Depending on the labels in the pull requests, the workflow will result in differ
4141
- This produces a json based report that is used to later evaluate the results of the tests.
4242
- [Test module](./.github/workflows/Test-ModuleLocal.yml)
4343
- Import and tests the module in parallel (matrix) using Pester tests from the module repository.
44-
- Supports setup and teardown scripts:
45-
- **BeforeAll.ps1**: Runs before each test execution to set up test environment (e.g., deploy infrastructure, download test data)
46-
- **AfterAll.ps1**: Runs after each test execution to clean up test environment (e.g., remove test resources, cleanup databases)
44+
- Supports setup and teardown scripts executed via separate dedicated jobs:
45+
- **BeforeAll.ps1**: Runs once before all test matrix jobs to set up test environment (e.g., deploy infrastructure, download test data)
46+
- **AfterAll.ps1**: Runs once after all test matrix jobs complete to clean up test environment (e.g., remove test resources, cleanup databases)
4747
- Setup/teardown scripts are automatically detected in test directories and executed with the same environment variables as tests
4848
- This produces a json based report that is used to later evaluate the results of the tests.
4949
- [Get test results](./.github/workflows/Get-TestResults.yml)
@@ -267,13 +267,13 @@ The workflow supports automatic execution of setup and teardown scripts for modu
267267

268268
#### BeforeAll.ps1
269269
- **Location**: Place in your test directories (e.g., `tests/BeforeAll.ps1`)
270-
- **Purpose**: Runs before each test execution to prepare the test environment
270+
- **Purpose**: Runs once before all test matrix jobs to prepare the test environment
271271
- **Use cases**: Deploy test infrastructure, download test data, initialize databases, configure services
272272
- **Environment**: Has access to the same environment variables as your tests (secrets, GitHub token, etc.)
273273

274274
#### AfterAll.ps1
275275
- **Location**: Place in your test directories (e.g., `tests/AfterAll.ps1`)
276-
- **Purpose**: Runs after each test execution to clean up the test environment
276+
- **Purpose**: Runs once after all test matrix jobs complete to clean up the test environment
277277
- **Use cases**: Remove test resources, cleanup databases, stop services, upload artifacts
278278
- **Environment**: Has access to the same environment variables as your tests
279279

@@ -301,6 +301,17 @@ Write-Host "Cleanup completed!"
301301
- Scripts run with PowerShell and have access to PSModuleHelpers
302302
- If no scripts are found, the workflow continues normally
303303

304+
**Execution Order:**
305+
The workflow executes setup and teardown scripts using separate dedicated jobs with the following order:
306+
```
307+
BeforeAll-ModuleLocal → Test-ModuleLocal (matrix) → AfterAll-ModuleLocal → Get-TestResults/Get-CodeCoverage
308+
```
309+
310+
- **BeforeAll-ModuleLocal**: Runs once before all test matrix jobs
311+
- **Test-ModuleLocal**: Runs tests in parallel matrix configuration
312+
- **AfterAll-ModuleLocal**: Runs once after all test matrix jobs complete (always executes for cleanup, even if tests fail)
313+
- **Get-TestResults/Get-CodeCoverage**: Process results after cleanup is complete
314+
304315
### Secrets
305316

306317
The following secrets are used by the workflow. They can be automatically provided (if available) by setting the `secrets: inherit`

0 commit comments

Comments
 (0)