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