Skip to content
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

Run Pester Tests only on changed files (Git) #2600

Open
3 tasks done
crlgb opened this issue Jan 9, 2025 · 3 comments
Open
3 tasks done

Run Pester Tests only on changed files (Git) #2600

crlgb opened this issue Jan 9, 2025 · 3 comments
Labels

Comments

@crlgb
Copy link

crlgb commented Jan 9, 2025

Checklist

Summary of the feature request

As a user, I would like to be able to run pester tests only on changed files. These may either be the git differences between the current and last commit, or the current changes in the workspace.

In cases where the number and runtime of tests in a repository is very large, this would be extra helpful to test only the changes one made, before holistic testing is ran on CI/CD.

How should it work?

Invoke-Pester -GitChanges

@crlgb crlgb added the Feature label Jan 9, 2025
@nohwnd
Copy link
Member

nohwnd commented Jan 9, 2025

#607 is your request similar to this?

@crlgb
Copy link
Author

crlgb commented Jan 10, 2025

Similar, but not quite the same. The file system watcher is great for local development. The -GitChanges parameter would also allow Pester to be run only on changed files in CI/CD, e.g. on a new commit.

@fflaten
Copy link
Collaborator

fflaten commented Jan 11, 2025

Thank you for the suggestion. I'm a bit confused about the intended behavior. Should it track local uncommited changes or compare commit/branches (CI)?

These may either be the git differences between the current and last commit, or the current changes in the workspace.

Running e.g. Invoke-Pester -Path (@(git ls-files -m) -like 'tst/*.Tests.ps1') would test modified unstaged test files locally. Handling staged files, new files, exclude deleted etc. requires different commands though.

The -GitChanges parameter would also allow Pester to be run only on changed files in CI/CD, e.g. on a new commit.

With CI we'd have to diff the commit/target and base ref, e.g. (git diff --name-status target base) -match '^(A|M).*\.Tests.ps1$' -replace '^\S\s+'. The refs are provided in different environment variables specific to each CI platform.

Using git diff or a predefined action/task like https://github.com/marketplace/actions/changed-files in a workflow is an easy alternative for users.

Running only modified test files feels like a rare scenario for a CI, as you'd likely want to catch unexpected changes by testing the complete solution.

In general, we'd be taking a dependency on git and different CI-platforms which adds risk/support/maintenance, for a feature that is opinionated and very environment-specific. Would a documented example be a valid alternative?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants