Skip to content

Instantly share code, notes, and snippets.

@DavidWells
Created February 20, 2025 18:41
Show Gist options
  • Save DavidWells/f77e35cbb1bbff49d0c2ef39dfb32c73 to your computer and use it in GitHub Desktop.
Save DavidWells/f77e35cbb1bbff49d0c2ef39dfb32c73 to your computer and use it in GitHub Desktop.
Bash for VSCode* to run tests in current file. E.g. Inside file.js will run file.test.js, inside file.test.js it runs itself
#!/bin/bash
if [[ "${relativeFile}" == *.test.js ]]; then
FILE="${relativeFile}"
elif [ -f "${fileDirname}/${fileBasenameNoExtension}.test.js" ]; then
FILE="${fileDirname}/${fileBasenameNoExtension}.test.js"
elif [ -f "${fileDirname}/$(basename "${fileDirname}").test.js" ]; then
FILE="${fileDirname}/$(basename "${fileDirname}").test.js"
else
FILE="${relativeFile}"
fi
echo "running file $FILE"
node "$FILE"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment