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