Skip to content

Instantly share code, notes, and snippets.

@jagoncalves14
Last active March 23, 2022 12:01
Show Gist options
  • Save jagoncalves14/1a45fffe0994cc8d760285ddc0f7f8fe to your computer and use it in GitHub Desktop.
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
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