-
Notifications
You must be signed in to change notification settings - Fork 7
Open
Labels
Description
Describe the change
Now that Process-PSModule supports BeforeAll and AfterAll scripts, that run once before and after all the parallel tests, we should move some of the setup/teardown tasks to these. This will hopefully speed up the testing process, and result in fewer failures due to ratelimiting.
Current Test Structure
Each test file currently performs repeated setup/teardown in individual Context blocks:
- Creates unique test resources (repos, teams, orgs) per Context
- Connects/disconnects GitHub accounts multiple times
- Cleans up resources after each Context
Proposed Changes
tests/BeforeAll.ps1 - Infrastructure Setup
Create shared test infrastructure that ALL tests can use:
- Test Organizations - Pre-create test organizations for different auth scenarios
- Test Repositories - Pre-create base repositories for testing
- Test Environments - Pre-create deployment environments
- Test Teams - Pre-create teams with different permission levels
- Cleanup old artifacts - Remove stale resources from previous failed runs
Important: This does NOT replace the BeforeAll blocks in test files, which are still needed for:
- Authentication (Connect-GitHubAccount, Connect-GitHubApp)
- Context-specific setup
- Loading test data (AuthCases.ps1)
tests/AfterAll.ps1 - Infrastructure Teardown
Clean up all shared test infrastructure:
- Remove all test organizations created in BeforeAll
- Remove all test repositories
- Remove all test teams and environments
- Generate cleanup report
Test Files - Keep Existing BeforeAll/AfterAll Blocks
Test file Context blocks should continue to:
- BeforeAll: Connect to GitHub with appropriate credentials (this stages the runner)
- AfterAll: Disconnect GitHub sessions
- Use the pre-created infrastructure instead of creating their own
Benefits
- Speed: Infrastructure created once instead of repeatedly per Context
- Rate Limiting: Significantly fewer API calls during test execution
- Reliability: Consistent test infrastructure across all test runs
- Cost: Fewer parallel operations hitting API limits
- Maintainability: Centralized infrastructure definitions
Implementation Strategy
- Analyze current test patterns to identify common infrastructure needs
- Create
tests/BeforeAll.ps1with infrastructure provisioning - Create
tests/AfterAll.ps1with cleanup logic - Update test files to consume shared infrastructure instead of creating their own
- Maintain existing authentication logic in test file BeforeAll/AfterAll blocks
Test Files Affected
All 15 test files will need updates to use shared infrastructure:
- Apps.Tests.ps1
- Artifacts.Tests.ps1
- Emojis.Tests.ps1
- Enterprise.Tests.ps1
- Environments.Tests.ps1
- GitHub.Tests.ps1
- GitHubFormatter.Tests.ps1
- Organizations.Tests.ps1
- Permissions.Tests.ps1
- Releases.Tests.ps1
- Repositories.Tests.ps1
- Secrets.Tests.ps1
- Teams.Tests.ps1
- Users.Tests.ps1
- Variables.Tests.ps1
Copilot
Metadata
Metadata
Assignees
Labels
Type
Projects
Status
Todo