4fbc15d9c860615e5a699c2bb18cdd409bb4604a
[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_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
22 all: check
23
24 clean:
25         rm -f mkws-error.png mkws-error.html 
26         rm -f images/*.png
27
28 distclean: clean clean-tmp clean-error
29         rm -rf node_modules
30         rm -f ${TMP_DIR}/jasmine-dev
31         rm -f libexec
32
33 clean-error:
34         rm -f mkws-error.png.* mkws-error.html.*
35
36 clean-tmp:
37         rm -rf ${TMP_DIR}
38         mkdir -p ${TMP_DIR}
39         touch ${TMP_DIR}/.gitkeep
40
41 mkws-complete-syntax-check:
42         ${MAKE} -C../tools/htdocs mkws-complete.min.js
43
44 check: mkws-complete-syntax-check
45         @if [ ! -e node_modules ]; then echo "please run first: make node-modules"; exit 1; fi 
46         ${JASMINE_NODE} --noColor --captureExceptions --forceexit ./spec
47
48 test: check
49
50 terse:
51         $(MIKE) jasmine-node --noColor --captureExceptions --forceexit spec
52
53 phantomjs p: apache-stop apache-start _phantomjs 
54         ${MAKE} apache-stop
55
56 _phantomjs:
57         perl ./bin/bomb.pl --timeout="${PHANTOMJS_TIMEOUT}.5" ${PHANTOMJS} phantom/run-jasmine.js ${PHANTOMJS_URL} ${PHANTOMJS_TIMEOUT}
58
59 phantomjs-all p-all:
60         ${MAKE} phantomjs PHANTOMJS_PATH=jasmine.html
61         ${MAKE} phantomjs PHANTOMJS_PATH=jasmine-cors-popup.html
62         ${MAKE} phantomjs PHANTOMJS_PATH=jasmine-local-popup.html
63         ${MAKE} phantomjs PHANTOMJS_PATH=jasmine-popup.html
64
65 mike-test:
66         $(MAKE) _phantomjs PHANTOMJS_URL=http://x.example.indexdata.com/jasmine-popup.html
67
68 screenshot:
69         ${PHANTOMJS} phantom/screenshot.js ${PHANTOMJS_URL} ${IMAGES}/screenshot.png 1200 1000
70
71 screenshot-mkws:
72         for i in ${SCREENSHOT_WIDTH}; do \
73             ${PHANTOMJS} phantom/screenshot.js http://mkws.indexdata.com ${IMAGES}/mkws-$$i.png $$i 1000 &  \
74         done; wait
75         ls -l ${IMAGES}
76
77 screenshot-indexdata:
78         for i in ${SCREENSHOT_WIDTH}; do \
79             ${PHANTOMJS} phantom/screenshot.js http://www.indexdata.com ${IMAGES}/indexdata-$$i.png $$i 1000 &  \
80         done; wait
81         ls -l ${IMAGES}
82
83 jsbeautifier jsb indent:
84         for i in package.json ./spec*/*.js ./js/*.js ./phantom/*.js; do \
85           jsbeautifier -j $$i > $@.tmp && mv -f $@.tmp $$i; \
86         done
87
88 perltidy:
89         @ls ${PERL_SCRIPTS} | xargs -n1 -P16 perl -c 2>/dev/null
90         @ls ${PERL_SCRIPTS} | xargs -n2 -P8 perltidy -b
91
92
93 node_modules node-modules:
94         npm install ${NPM_INSTALL_FLAGS}
95
96 apache-start:
97         bin/apache-template-update
98         ${APACHE_HTTPD} -f `pwd`/${TMP_DIR}/jasmine-dev
99
100 apache-stop:
101         @-if [ -e ${TMP_DIR}/mkws-jasmine.pid ]; then \
102            kill `cat ${TMP_DIR}/mkws-jasmine.pid`; \
103         else \
104            killall apache2 2> /dev/null; \
105         fi
106         @sleep 0.6
107         rm -f ${TMP_DIR}/mkws-jasmine.pid
108
109 help:
110         @echo "make [ all | check | clean | distclean ]"
111         @echo "     [ phantomjs | phantomjs-all ]"
112         @echo "     [ jsbeautifier | perltidy | screenshot ]"
113         @echo "     [ node-modules ]"
114         @echo "     [ apache-stop apache-start ]"
115         @echo ""
116         @echo "Examples: "
117         @echo ""
118         @echo "make phantomjs PHANTOMJS_PATH=${PHANTOMJS_PATH}"
119         @echo "DEBUG=0 APACHE_PORT=5050 make -s phantomjs PHANTOMJS_TIMEOUT=12 PHANTOMJS_PATH=${PHANTOMJS_PATH}"
120         @echo "DEBUG=2 make phantomjs PHANTOMJS_TIMEOUT=12 PHANTOMJS_URL=${PHANTOMJS_URL}"
121         @echo ""
122         @echo "make phantomjs-all"
123         @echo ""
124