Skip to content

Instantly share code, notes, and snippets.

@rosano
Last active October 11, 2019 01:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rosano/9acc5fcaa4c91acc8a958740c771d6e8 to your computer and use it in GitHub Desktop.
Save rosano/9acc5fcaa4c91acc8a958740c771d6e8 to your computer and use it in GitHub Desktop.
roco_file_extensions() {
local extensions=()
function join_by { local IFS="$1"; shift; echo "$*"; }
while IFS=',' read -ra ADDR; do
for e in "${ADDR[@]}"; do
if ! [[ $e =~ "." ]]; then
continue
fi
extensions+=("${e##*.}")
done
done <<< "$1"
echo $(join_by , "${extensions[@]}")
}
roco__bash_find_standard_ignore() {
ROCO_STANDARD_IGNORE='.*(\.git|DS_Store|node_modules|vendor|__).*'
}
roco_bash_find() {
roco__bash_find_standard_ignore
find -E "$1" -type f -not -iregex $ROCO_STANDARD_IGNORE ${@:2}
}
roco_tests() {
sourcePaths=$(roco_bash_find . -name '*-tests.js' | sed 's/-tests//g' | grep -v 'style' | sed $([[ $PWD == *Apps/Terminal* ]] && echo 's/main.js/main.sh/g' || echo 's/_IGNORE_/_IGNORE_/g'))
testPaths=$(roco_bash_find . -name '*-tests.js')
roco__mocha "$sourcePaths" "$testPaths" $@
}
roco_ui_tests() {
roco__bash_find_standard_ignore
sourcePaths=$(find -E . -name 'ui-behaviour.js' -o -name '*view.ejs' -not -iregex $(echo $ROCO_STANDARD_IGNORE | sed 's/__/__external/g'))
testPaths=$(roco_bash_find . -name 'ui-test-*.js')
if [[ $ROCO_UI_TESTS_MATCH != "" ]]; then
testPaths=$(roco_bash_find . -name 'ui-test-*.js' | grep $ROCO_UI_TESTS_MATCH -i)
fi
OLSK_TESTING_BEHAVIOUR=true roco__mocha "$sourcePaths" "$testPaths" $@
}
roco__mocha() {
local watchItems="${1//$'\n'/,},${2//$'\n'/,}"
supervisor --watch $watchItems --extensions $(roco_file_extensions $watchItems) --no-restart-on exit --quiet --exec mocha -- $2 $([[ $3 == "" ]] && echo '--reporter min' || echo '') ${@:3} $([ -f mocha-start.js ] && echo "--file ./mocha-start.js" || echo '') --timeout 1000
}
[[ $1 == 'ui' ]] && roco_ui_tests || roco_tests
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment