enable to run the tests on a different port.
[mkws-moved-to-github.git] / test / Makefile
1 # Copyright (c) 2013-2014 IndexData 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_URL=http://localhost:${APACHE_PORT}/jasmine-local-popup.html
10 PHANTOMJS_TIMEOUT=16
11
12 NPM_INSTALL_FLAGS=-q
13 JASMINE_NODE=   ./node_modules/jasmine-node/bin/jasmine-node
14 PHANTOMJS=      ./node_modules/phantomjs/bin/phantomjs
15 IMAGES= ./images
16 SCREENSHOT_WIDTH=       360 480 640 768 1024 1200 1440 2048
17 PERL_SCRIPTS=   bin/bomb.pl
18 TMP_DIR=        ./logs
19 APACHE_HTTPD:=  $(shell env PATH=$$PATH:/usr/sbin which apache2 httpd false | head -1 )
20
21 all: check
22
23 clean:
24         rm -f mkws-error.png mkws-error.html 
25         rm -f images/*.png
26
27 distclean: clean clean-tmp clean-error
28         rm -rf node_modules
29         rm -f ${TMP_DIR}/jasmine-dev
30
31 clean-error:
32         rm -f mkws-error.png.* mkws-error.html.*
33
34 clean-tmp:
35         rm -rf ${TMP_DIR}
36         mkdir -p ${TMP_DIR}
37         touch ${TMP_DIR}/.gitkeep
38
39 mkws-complete-syntax-check:
40         ${MAKE} -C../tools/htdocs mkws-complete.min.js
41
42 check: mkws-complete-syntax-check
43         @if [ ! -e node_modules ]; then echo "please run first: make node-modules"; exit 1; fi 
44         ${JASMINE_NODE} --noColor --captureExceptions --forceexit ./spec
45
46 test: check
47
48 terse:
49         $(MIKE) jasmine-node --noColor --captureExceptions --forceexit spec
50
51 phantomjs p: apache-stop apache-start _phantomjs 
52         ${MAKE} apache-stop
53
54 _phantomjs:
55         perl ./bin/bomb.pl --timeout="${PHANTOMJS_TIMEOUT}.5" ${PHANTOMJS} phantom/run-jasmine.js ${PHANTOMJS_URL} ${PHANTOMJS_TIMEOUT}
56
57 mike-test:
58         $(MAKE) _phantomjs PHANTOMJS_URL=http://x.example.indexdata.com/jasmine-popup.html
59
60 screenshot:
61         ${PHANTOMJS} phantom/screenshot.js ${PHANTOMJS_URL} ${IMAGES}/screenshot.png 1200 1000
62
63 screenshot-mkws:
64         for i in ${SCREENSHOT_WIDTH}; do \
65             ${PHANTOMJS} phantom/screenshot.js http://mkws.indexdata.com ${IMAGES}/mkws-$$i.png $$i 1000 &  \
66         done; wait
67         ls -l ${IMAGES}
68
69 screenshot-indexdata:
70         for i in ${SCREENSHOT_WIDTH}; do \
71             ${PHANTOMJS} phantom/screenshot.js http://www.indexdata.com ${IMAGES}/indexdata-$$i.png $$i 1000 &  \
72         done; wait
73         ls -l ${IMAGES}
74
75 jsbeautifier jsb indent:
76         for i in package.json ./spec*/*.js ./js/*.js ./phantom/*.js; do \
77           jsbeautifier -j $$i > $@.tmp && mv -f $@.tmp $$i; \
78         done
79
80 perltidy:
81         @ls ${PERL_SCRIPTS} | xargs -n1 -P16 perl -c 2>/dev/null
82         @ls ${PERL_SCRIPTS} | xargs -n2 -P8 perltidy -b
83
84
85 node_modules node-modules:
86         npm install ${NPM_INSTALL_FLAGS}
87
88 apache-start:
89         bin/apache-template-update
90         ${APACHE_HTTPD} -f `pwd`/${TMP_DIR}/jasmine-dev
91
92 apache-stop:
93         @-if [ -e ${TMP_DIR}/mkws-jasmine.pid ]; then \
94            kill `cat ${TMP_DIR}/mkws-jasmine.pid`; \
95         else \
96            killall apache2 2> /dev/null; \
97         fi
98         @sleep 0.3
99         rm -f ${TMP_DIR}/mkws-jasmine.pid
100
101 help:
102         @echo "make [ all | check | clean | distclean ]"
103         @echo "     [ phantomjs | screenshot ]"
104         @echo "     [ jsbeautifier | perltidy ]"
105         @echo "     [ node-modules ]"
106         @echo "     [ apache-stop apache-start ]"
107         @echo ""
108         @echo "DEBUG=1 make phantomjs PHANTOMJS_TIMEOUT=12 PHANTOMJS_URL=${PHANTOMJS_URL}"
109