-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathember_helpers
85 lines (80 loc) · 2.74 KB
/
ember_helpers
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#!/bin/bash
#######################################
# Run ember exam against a set of files
# Flags:
# -c: (default) run test files from git unstaged changes, i.e., test files you seen in 'git status'
# -d: run test files in from git head
# -h: help
# -s: append the `--server` flag
# files[,files]: run supplied test files
#######################################
emberTests() {
gitHead_flag=''
gitChanges_flag=''
help_flag=''
listOfTestFiles=''
finalTestFiles=''
filter=''
server_flag=''
while getopts f:cdhs opt; do
case $opt in
f) filter=$OPTARG ;;
c) gitChanges_flag=1 ;;
d) gitHead_flag=1 ;;
h) help_flag=1 ;;
s) server_flag="--server" ;;
'?')
# looks like a param was passed that was not caught here
echo >&2 "Invalid option: ${@:$OPTIND:1}"
echo "Unrecognized parameter. Trying running the command with the help (-h) flag"
return 1
;;
esac
shift $OPTIND-1
done
[[ $1 = -- ]] && shift
# determine which (if any) test files we're going to run
if [[ $OPTIND -eq 0 ]] ; then
# default to '-c' param if no arguments passed in
echo "defaulting to `emberTests -c` since no arguments found"
emberTests -c
return 1
elif [[ "$gitChanges_flag" == 1 ]]; then
echo "Testing files in git status:"
listOfTestFiles=$(git status --porcelain | sed s/^...// | grep test)
echo "$listOfTestFiles"
finalTestFiles=$(echo "$listOfTestFiles" | tr '\n' ',' | sed 's/.$//')
elif [[ "$gitHead_flag" == 1 ]]; then
echo "Testing files in git HEAD:"
listOfTestFiles=$(git diff HEAD^ HEAD --name-only -- '*test*')
echo "$listOfTestFiles"
finalTestFiles=$(echo "$listOfTestFiles" | tr '\n' ',' | sed 's/.$//' | xargs echo)
elif [[ "$help_flag" == 1 ]]; then
echo "emberTests is a helper for plugging a set of test files into 'ember exam --path dist --file-path'"
echo ""
echo "Usage:"
echo "-c (default) - run test files from git unstaged changes (see 'git status')"
echo "-d - run test files from files in git head"
echo "\"filePath[,otherFilePath]\" - file paths of tests to run"
echo "-f \"filter string\": filter to apply to limit tests in supplied file set"
echo "-s - append the `--server` flag"
else
echo "Assuming you\'ve passed in a file/files"
echo "Passing the following to ember exam:"
finalTestFiles=$1
echo $finalTestFiles
fi
# exit early since there are no files to test and we'll wait forever if this gets passed to ember exam
if [[ -z "$finalTestFiles" ]]; then
return 1
fi
# run the tests
if [[ -z $filter ]]; then
ember exam --path dist --file-path ${finalTestFiles} ${server_flag}
else
echo ""
echo "Filtering for: ${filter}"
echo ""
ember exam --path dist --file-path ${finalTestFiles} --filter ${filter} ${server_flag}
fi
}