Last active
March 23, 2022 12:01
-
-
Save jagoncalves14/1a45fffe0994cc8d760285ddc0f7f8fe to your computer and use it in GitHub Desktop.
ZSH: Function to run unit tests for Git's staged and unstaged files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function testchanges() { | |
/** | |
* GET THE STAGED AND UNSTAGED FILES | |
*/ | |
STAGED_FILES=$(git status --porcelain | awk '{ print $2 }') | |
/** | |
* ADJUST FILES AS NEEDED | |
* Removing .vue or .ts extensions from each file name | |
*/ | |
TRIMMED_VUE=${STAGED_FILES//.vue/} | |
TRIMMED_TS=${TRIMMED_VUE//.ts/} | |
TRIMMED_FILES=${TRIMMED_TS} | |
/** | |
* LIST FILES | |
* Turning the list into array and then echoing as string. | |
* This is required so that each file name in the list is wrapped around quotation marks | |
*/ | |
STAGED_FILES_LIST=(`echo ${TRIMMED_FILES}`) | |
/** | |
* RUN UNIT TESTS | |
*/ | |
pnpm run unit ${STAGED_FILES_LIST} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment