put port number in config/log filenames
[mkws-moved-to-github.git] / test / Makefile
1 # Copyright (c) 2013-2014 Index Data ApS. http://indexdata.com
2
3 # For running on Mike's local install of node.js
4 MIKE = PATH=$$PATH:/usr/local/lib/node-v0.10.24-linux-x64/bin
5
6 APACHE_PORT:= $(shell echo $${APACHE_PORT-4040})
7
8 #PHANTOMJS_URL=https://mkws-dev.indexdata.com/jasmine-popup.html        
9 PHANTOMJS_PATH=jasmine-local-popup.html
10 PHANTOMJS_URL=http://localhost:${APACHE_PORT}/${PHANTOMJS_PATH}
11 PHANTOMJS_TIMEOUT=18
12
13 NPM_INSTALL_FLAGS=-q
14 JASMINE_NODE=   ./node_modules/jasmine-node/bin/jasmine-node
15 PHANTOMJS=      ./node_modules/phantomjs/bin/phantomjs
16 IMAGES= ./images
17 SCREENSHOT_WIDTH=       360 480 640 768 1024 1200 1440 2048
18 PERL_SCRIPTS=   bin/bomb.pl
19 TMP_DIR=        ./logs
20 APACHE_HTTPD:=  $(shell env PATH=$$PATH:/usr/sbin which apache2 httpd false | head -1 )
21 APACHE_PORT ?= 4040
22
23 all: check
24
25 clean:
26         rm -f mkws-error.png mkws-error.html 
27         rm -f images/*.png
28
29 distclean: clean clean-tmp clean-error
30         rm -rf node_modules
31         rm -f ${TMP_DIR}/jasmine-dev*.conf
32         rm -f libexec
33         make -C./widgets $@
34
35 clean-error:
36         rm -f mkws-error.png.* mkws-error.html.*
37
38 clean-tmp:
39         rm -rf ${TMP_DIR}
40         mkdir -p ${TMP_DIR}
41         touch ${TMP_DIR}/.gitkeep
42
43 mkws-complete-syntax-check:
44         ${MAKE} -C../tools/htdocs mkws-complete.min.js
45
46 check: mkws-complete-syntax-check
47         @if [ ! -e node_modules ]; then echo "please run first: make node-modules"; exit 1; fi 
48         ${JASMINE_NODE} --noColor --captureExceptions --forceexit ./spec
49
50 test: check
51
52 terse:
53         $(MIKE) jasmine-node --noColor --captureExceptions --forceexit spec
54
55 phantomjs p: apache-stop apache-start _phantomjs 
56         ${MAKE} apache-stop
57
58 _phantomjs:
59         perl ./bin/bomb.pl --timeout="${PHANTOMJS_TIMEOUT}.5" ${PHANTOMJS} phantom/run-jasmine.js ${PHANTOMJS_URL} ${PHANTOMJS_TIMEOUT}
60
61 phantomjs-all p-all:
62         ${MAKE} phantomjs PHANTOMJS_PATH=jasmine-local-popup.html
63         ${MAKE} phantomjs PHANTOMJS_PATH=jasmine-popup.html
64         ${MAKE} phantomjs PHANTOMJS_PATH=jasmine-cors-popup.html
65         ${MAKE} phantomjs PHANTOMJS_PATH=jasmine.html
66
67 mike-test:
68         $(MAKE) _phantomjs PHANTOMJS_URL=http://x.example.indexdata.com/jasmine-popup.html
69
70 screenshot:
71         ${PHANTOMJS} phantom/screenshot.js ${PHANTOMJS_URL} ${IMAGES}/screenshot.png 1200 1000
72
73 screenshot-mkws:
74         for i in ${SCREENSHOT_WIDTH}; do \
75             ${PHANTOMJS} phantom/screenshot.js http://mkws.indexdata.com ${IMAGES}/mkws-$$i.png $$i 1000 &  \
76         done; wait
77         ls -l ${IMAGES}
78
79 screenshot-indexdata:
80         for i in ${SCREENSHOT_WIDTH}; do \
81             ${PHANTOMJS} phantom/screenshot.js http://www.indexdata.com ${IMAGES}/indexdata-$$i.png $$i 1000 &  \
82         done; wait
83         ls -l ${IMAGES}
84
85 screenshots:
86         make -C ./widgets $@
87
88 jsbeautifier jsb indent:
89         for i in package.json ./spec*/*.js ./js/*.js ./phantom/*.js; do \
90           jsbeautifier -j $$i > $@.tmp && mv -f $@.tmp $$i; \
91         done
92
93 perltidy:
94         @ls ${PERL_SCRIPTS} | xargs -n1 -P16 perl -c 2>/dev/null
95         @ls ${PERL_SCRIPTS} | xargs -n2 -P8 perltidy -b
96
97
98 node_modules node-modules:
99         npm install ${NPM_INSTALL_FLAGS}
100
101 apache-start:
102         bin/apache-template-update
103         ${APACHE_HTTPD} -f `pwd`/${TMP_DIR}/jasmine-dev-${APACHE_PORT}.conf
104
105 APACHE_PID_FILE=${TMP_DIR}/mkws-jasmine-${APACHE_PORT}.pid 
106 apache-stop:
107         @-if [ -e ${APACHE_PID_FILE} ]; then \
108            kill `cat ${APACHE_PID_FILE}`; \
109         else \
110            killall apache2 2> /dev/null; \
111         fi
112         @sleep 0.6
113         rm -f ${APACHE_PID_FILE}
114
115 help:
116         @echo "make [ all | check | clean | distclean ]"
117         @echo "     [ phantomjs | phantomjs-all ]"
118         @echo "     [ jsbeautifier | perltidy | screenshot ]"
119         @echo "     [ screenshots ]"
120         @echo "     [ node-modules ]"
121         @echo "     [ apache-stop apache-start ]"
122         @echo ""
123         @echo "Examples: "
124         @echo ""
125         @echo "make phantomjs PHANTOMJS_PATH=${PHANTOMJS_PATH}"
126         @echo "DEBUG=0 APACHE_PORT=5050 make -s phantomjs PHANTOMJS_TIMEOUT=12 PHANTOMJS_PATH=${PHANTOMJS_PATH}"
127         @echo "DEBUG=2 make phantomjs PHANTOMJS_TIMEOUT=12 PHANTOMJS_URL=${PHANTOMJS_URL}"
128         @echo ""
129         @echo "make phantomjs-all"
130         @echo ""
131