Skip to content

🚀[Feature]: Add support for running setup and teardown scripts during tests #177

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

Copilot
Copy link

@Copilot Copilot AI commented Jul 4, 2025

This PR implements support for BeforeAll.ps1 and AfterAll.ps1 setup and teardown scripts during the Test-ModuleLocal workflow, as requested in issue #169.

Changes Made

Workflow Enhancements

  • Added BeforeAll-ModuleLocal job: Runs once before all Test-ModuleLocal matrix jobs to execute setup scripts
  • Added AfterAll-ModuleLocal job: Runs once after all Test-ModuleLocal matrix jobs complete to execute teardown scripts
  • Updated job dependencies: Modified Get-TestResults and Get-CodeCoverage to depend on AfterAll-ModuleLocal for proper execution order

Script Detection and Execution

  • Automatic detection of BeforeAll.ps1/AfterAll.ps1 scripts in test directories
  • Conditional execution - jobs only run setup/teardown steps when scripts are present
  • Scripts execute with the same environment variables and context as regular tests
  • Each unique test directory path is processed only once to avoid duplicate executions

Example Usage

Place BeforeAll.ps1 and/or AfterAll.ps1 scripts in your test directories:

# tests/BeforeAll.ps1
Write-Host "Setting up test environment..."
# Deploy test infrastructure
# Download test data
# Initialize test databases
Write-Host "Test environment ready!"
# tests/AfterAll.ps1
Write-Host "Cleaning up test environment..."
# Remove test resources
# Cleanup databases
# Stop services
Write-Host "Cleanup completed!"

Documentation

  • Updated README.md with comprehensive documentation
  • Added detailed "Setup and Teardown Scripts" section with examples
  • Documented script locations, purposes, and common use cases

Test Coverage

  • Created example BeforeAll.ps1 and AfterAll.ps1 scripts across all test directories
  • Validated script detection logic with various scenarios
  • Tested conditional execution with mixed directory scenarios

Workflow Execution Order

BeforeAll-ModuleLocal → Test-ModuleLocal (matrix) → AfterAll-ModuleLocal → Get-TestResults/Get-CodeCoverage

This implementation provides exactly the functionality requested in the issue, allowing users to run setup scripts before tests (for deploying infrastructure, downloading data, etc.) and teardown scripts after tests (for cleanup, removing resources, etc.).

Fixes #169.


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

@Copilot Copilot AI changed the title [WIP] 🚀[Feature]: Add support for running setup and teardown scripts during tests 🚀[Feature]: Add support for running setup and teardown scripts during tests Jul 4, 2025
@Copilot Copilot AI requested a review from MariusStorhaug July 4, 2025 13:44
Copilot finished work on behalf of MariusStorhaug July 4, 2025 13:44
@MariusStorhaug
Copy link
Member

Rework so that it runs PowerShell based steps.

Copy link
Author

Copilot AI commented Jul 6, 2025

Rework so that it runs PowerShell based steps.

Reworked the implementation to use PowerShell-based steps as requested. The new approach removes the separate bash-based BeforeAll-ModuleLocal and AfterAll-ModuleLocal jobs and instead adds simple PowerShell steps directly to the Test-ModuleLocal.yml workflow that check for and execute BeforeAll.ps1/AfterAll.ps1 scripts. This is now fully PowerShell-based and consistent with the existing testing infrastructure. (2027a0b)

Copilot finished work on behalf of MariusStorhaug July 6, 2025 06:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

🚀[Feature]: Add support for running setup and teardown scripts during tests
2 participants