Skip to content

Commit 12c11d2

Browse files
🩹 [Patch]: Improve README formatting for clarity on testing setup and teardown scripts
1 parent 7e38e21 commit 12c11d2

File tree

1 file changed

+33
-38
lines changed

1 file changed

+33
-38
lines changed

‎README.md‎

Lines changed: 33 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -31,19 +31,23 @@ Depending on the labels in the pull requests, the workflow will result in differ
3131
- [Build module](./.github/workflows/Build-Module.yml)
3232
- Compiles the module source code into a PowerShell module.
3333
- [Test source code](./.github/workflows/Test-SourceCode.yml)
34-
- Tests the source code in parallel (matrix) using [PSModule framework settings for style and standards for source code](https://github.com/PSModule/Test-PSModule?tab=readme-ov-file#sourcecode-tests)
34+
- Tests the source code in parallel (matrix) using:
35+
- [PSModule framework settings for style and standards for source code](https://github.com/PSModule/Test-PSModule?tab=readme-ov-file#sourcecode-tests)
3536
- This produces a json based report that is used to later evaluate the results of the tests.
3637
- [Lint source code](./.github/workflows/Lint-SourceCode.yml)
37-
- Lints the source code in parallel (matrix) using [PSScriptAnalyzer rules](https://github.com/PSModule/Invoke-ScriptAnalyzer).
38+
- Lints the source code in parallel (matrix) using:
39+
- [PSScriptAnalyzer rules](https://github.com/PSModule/Invoke-ScriptAnalyzer).
3840
- This produces a json based report that is used to later evaluate the results of the linter.
3941
- [Framework test](./.github/workflows/Test-Module.yml)
40-
- Tests and lints the module in parallel (matrix) using [PSModule framework settings for style and standards foor modules](https://github.com/PSModule/Test-PSModule?tab=readme-ov-file#module-tests) + [PSScriptAnalyzer rules](https://github.com/PSModule/Invoke-ScriptAnalyzer).
42+
- Tests and lints the module in parallel (matrix) using:
43+
- [PSModule framework settings for style and standards for modules](https://github.com/PSModule/Test-PSModule?tab=readme-ov-file#module-tests)
44+
- [PSScriptAnalyzer rules](https://github.com/PSModule/Invoke-ScriptAnalyzer).
4145
- This produces a json based report that is used to later evaluate the results of the tests.
4246
- [Test module](./.github/workflows/Test-ModuleLocal.yml)
4347
- Import and tests the module in parallel (matrix) using Pester tests from the module repository.
4448
- 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)
49+
- `BeforeAll`: Runs once before all test matrix jobs to set up test environment (e.g., deploy infrastructure, download test data)
50+
- `AfterAll`: Runs once after all test matrix jobs complete to clean up test environment (e.g., remove test resources, cleanup databases)
4751
- Setup/teardown scripts are automatically detected in test directories and executed with the same environment variables as tests
4852
- This produces a json based report that is used to later evaluate the results of the tests.
4953
- [Get test results](./.github/workflows/Get-TestResults.yml)
@@ -53,16 +57,19 @@ Depending on the labels in the pull requests, the workflow will result in differ
5357
- Gathers the code coverage from the previous steps and creates a summary of the results.
5458
- If the code coverage is below the target, the workflow will fail here.
5559
- [Build docs](./.github/workflows/Build-Docs.yml)
56-
- Generates documentation and lints the documentation using [super-linter](https://github.com/super-linter/super-linter).
60+
- Generates documentation and lints the documentation using:
61+
- [super-linter](https://github.com/super-linter/super-linter).
5762
- [Build site](./.github/workflows/Build-Site.yml)
58-
- Generates a static site using [Material for MkDocs](https://squidfunk.github.io/mkdocs-material/).
63+
- Generates a static site using:
64+
- [Material for MkDocs](https://squidfunk.github.io/mkdocs-material/).
5965
- [Publish site](./.github/workflows/Publish-Site.yml)
6066
- Publishes the static site with the module documentationto GitHub Pages.
6167
- [Publish module](./.github/workflows/Publish-Module.yml)
6268
- Publishes the module to the PowerShell Gallery.
6369
- Creates a release on the GitHub repository.
6470

6571
To use the workflow, create a new file in the `.github/workflows` directory of the module repository and add the following content.
72+
6673
<details>
6774
<summary>Workflow suggestion</summary>
6875

@@ -265,19 +272,18 @@ Build:
265272

266273
The workflow supports automatic execution of setup and teardown scripts for module tests:
267274

268-
#### BeforeAll.ps1
269-
- **Location**: Place in your test directories (e.g., `tests/BeforeAll.ps1`)
270-
- **Purpose**: Runs once before all test matrix jobs to prepare the test environment
271-
- **Use cases**: Deploy test infrastructure, download test data, initialize databases, configure services
272-
- **Environment**: Has access to the same environment variables as your tests (secrets, GitHub token, etc.)
275+
- Scripts are automatically detected and executed if present
276+
- If no scripts are found, the workflow continues normally
277+
278+
#### Setup - `BeforeAll.ps1`
273279

274-
#### AfterAll.ps1
275-
- **Location**: Place in your test directories (e.g., `tests/AfterAll.ps1`)
276-
- **Purpose**: Runs once after all test matrix jobs complete to clean up the test environment
277-
- **Use cases**: Remove test resources, cleanup databases, stop services, upload artifacts
278-
- **Environment**: Has access to the same environment variables as your tests
280+
- Place in your test directories (`tests/BeforeAll.ps1`)
281+
- Runs once before all test matrix jobs to prepare the test environment
282+
- Deploy test infrastructure, download test data, initialize databases, configure services
283+
- Has access to the same environment variables as your tests (secrets, GitHub token, etc.)
284+
285+
##### Example - `BeforeAll.ps1`
279286

280-
**Example BeforeAll.ps1:**
281287
```powershell
282288
Write-Host "Setting up test environment..."
283289
# Deploy test infrastructure
@@ -286,7 +292,15 @@ Write-Host "Setting up test environment..."
286292
Write-Host "Test environment ready!"
287293
```
288294

289-
**Example AfterAll.ps1:**
295+
#### Teardown - `AfterAll.ps1`
296+
297+
- Place in your test directories (`tests/AfterAll.ps1`)
298+
- Runs once after all test matrix jobs complete to clean up the test environment
299+
- Remove test resources, cleanup databases, stop services, upload artifacts
300+
- Has access to the same environment variables as your tests
301+
302+
##### Example - `AfterAll.ps1`
303+
290304
```powershell
291305
Write-Host "Cleaning up test environment..."
292306
# Remove test resources
@@ -295,25 +309,6 @@ Write-Host "Cleaning up test environment..."
295309
Write-Host "Cleanup completed!"
296310
```
297311

298-
**Notes:**
299-
- Scripts are automatically detected and executed if present
300-
- Each unique test directory path is processed only once
301-
- Scripts run with PowerShell and have access to PSModuleHelpers
302-
- If no scripts are found, the workflow continues normally
303-
304-
**Execution Order:**
305-
306-
The workflow executes setup and teardown scripts using separate dedicated jobs with the following order:
307-
308-
```plaintext
309-
BeforeAll-ModuleLocal → Test-ModuleLocal (matrix) → AfterAll-ModuleLocal → Get-TestResults/Get-CodeCoverage
310-
```
311-
312-
- **BeforeAll-ModuleLocal**: Runs once before all test matrix jobs
313-
- **Test-ModuleLocal**: Runs tests in parallel matrix configuration
314-
- **AfterAll-ModuleLocal**: Runs once after all test matrix jobs complete (always executes for cleanup, even if tests fail)
315-
- **Get-TestResults/Get-CodeCoverage**: Process results after cleanup is complete
316-
317312
### Secrets
318313

319314
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)