-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path_before-test.sh
executable file
·81 lines (68 loc) · 2.47 KB
/
_before-test.sh
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
#!/bin/bash
set -x;
echo "Note: When sourcing this script, you must reside within the tests folder of the component you want to test"
echo "Assuming running sourced"
script_path=$(pwd)
if [ "$(cd $script_path/..;basename $(pwd))" == "dna" ]; then
# assume we are testing the dna
export PROJECT_BASEPATH=$(pwd)/../..
else
# assume we are testing a yiiapp under yiiapps/
export PROJECT_BASEPATH=$(pwd)/../../..
fi
export TESTS_BASEPATH=$(pwd)
export TESTS_FRAMEWORK_BASEPATH=$PROJECT_BASEPATH/vendor/neam/yii-dna-test-framework
export TESTS_BASEPATH_REL=$(python -c "import os.path; print os.path.relpath('$TESTS_BASEPATH', '$TESTS_FRAMEWORK_BASEPATH')")
# defaults
if [ "$COVERAGE" == "" ]; then
export COVERAGE=full
fi
if [[ "$DATA" != test-* ]]; then
echo "* Prefixing the current data profile with test-, so that there is less risk that tests run against live data";
export DATA=test-$DATA
fi
cd $PROJECT_BASEPATH
source vendor/neam/php-app-config/shell-export.sh
cd -
cd $TESTS_FRAMEWORK_BASEPATH
erb $TESTS_FRAMEWORK_BASEPATH/codeception.yml.erb > $TESTS_BASEPATH/codeception.yml
cd $TESTS_BASEPATH
./generate-local-codeception-config.sh
$TESTS_FRAMEWORK_BASEPATH/vendor/bin/codecept build
#XDEBUG_PROFILING_PREFIX="php -dxdebug.profiler_enable=1"
XDEBUG_PROFILING_PREFIX=""
# function codecept for easy access to codecept binary running with proper config
function codecept () {
echo time $XDEBUG_PROFILING_PREFIX $TESTS_FRAMEWORK_BASEPATH/vendor/bin/codecept $@;
time $XDEBUG_PROFILING_PREFIX $TESTS_FRAMEWORK_BASEPATH/vendor/bin/codecept $@
}
export -f codecept
# helper functions
function activate_test_config () {
sed -i 's/#CONFIG_ENVIRONMENT=test/CONFIG_ENVIRONMENT=test/g' $PROJECT_BASEPATH/.env
}
export -f activate_test_config
function inactivate_test_config () {
sed -i 's/CONFIG_ENVIRONMENT=test/#CONFIG_ENVIRONMENT=test/g' $PROJECT_BASEPATH/.env
}
export -f inactivate_test_config
function test_console () {
$PROJECT_BASEPATH/vendor/bin/yii-dna-pre-release-testing-console $@
}
export -f test_console
function stop_api_mock_server () {
pid=$(ps aux | grep node/bin/api-mock | grep -v grep | head -n 1 | awk '{ print $2 }')
if [ "$pid" != "" ]; then
kill $pid
fi
}
export -f stop_api_mock_server
function start_api_mock_server () {
installed=$(which api-mock || true)
if [ "$installed" == "" ]; then
npm -g install api-mock
fi
stop_api_mock_server
api-mock $@ --port 3000 &
}
export -f start_api_mock_server