UNPKG

10.2 kBapplication/x-shView Raw
1#!/usr/bin/env bash
2CWD=`dirname $0`
3CWD=`cd "$APP_DIR";pwd`
4W="${CWD}/bin/whiskey"
5E="${CWD}/example"
6ANY_SUITE="--tests $E/test-skipped.js"
7echo $ANY_SUITE
8
9$W -g ./example/global-setup.js ${ANY_SUITE} >/tmp/output 2>&1
10if [ $? -ne 0 ]; then
11 echo "-g/--global-setup-teardown must base its paths from the invoking CWD"
12 exit 1
13fi
14
15$W --tests $E/global-teardown.js >/tmp/output 2>&1
16if [ $? -ne 0 ]; then
17 echo "A test suite without any tests should not break Whiskey."
18 exit 1
19fi
20grep "globalTearDown was here" /tmp/output >/dev/null 2>&1
21if [ $? -ne 1 ]; then
22 echo "Expected globalTearDown to be ignored."
23 exit 1
24fi
25
26$W --tests $E/global-setup.js >/tmp/output 2>&1
27if [ $? -ne 0 ]; then
28 echo "A test suite without any tests should not break Whiskey."
29 exit 1
30fi
31grep "globalSetUp was here" /tmp/output >/dev/null 2>&1
32if [ $? -ne 1 ]; then
33 echo "Expected globalSetUp to be ignored."
34 exit 1
35fi
36
37$W -g $E/local-teardown.js ${ANY_SUITE} >/tmp/output 2>&1
38if [ $? -ne 0 ]; then
39 echo "A file with a 'localTearDown' procedure should not kill Whiskey"
40 exit 1
41fi
42grep "globalTearDown was here" /tmp/output >/dev/null 2>&1
43if [ $? -ne 1 ]; then
44 echo "Expected localTearDown to have been ignored."
45 exit 1
46fi
47
48$W -g $E/global-teardown-with-exception.js ${ANY_SUITE} >/tmp/output 2>&1
49if [ $? -ne 0 ]; then
50 echo "Exceptions raised in globalTearDown should not kill Whiskey run."
51 exit 1
52fi
53
54$W -g $E/global-teardown.js ${ANY_SUITE} >/tmp/output 2>&1
55if [ $? -ne 0 ]; then
56 echo "Expected invokation of global teardown to not harm Whiskey."
57 exit 1
58fi
59grep "globalTearDown was here" /tmp/output >/dev/null 2>&1
60if [ $? -ne 0 ]; then
61 echo "Expected globalTearDown to have been invoked."
62 exit 1
63fi
64
65$W -g $E/global-setup-with-failed-assertion.js ${ANY_SUITE}
66if [ $? -eq 0 ]; then
67 echo "An assertion failure inside a global setup procedure should cause a test failure."
68 exit 1
69fi
70
71$W -g $E/global-setup-with-exception.js ${ANY_SUITE}
72if [ $? -eq 0 ]; then
73 echo "An exception inside a global setup procedure should cause a test failure."
74 exit 1
75fi
76
77$W -g $E/local-setup.js ${ANY_SUITE} >/tmp/output 2>&1
78if [ $? -ne 0 ]; then
79 echo "Expected invokation of global setup to not harm Whiskey."
80 exit 1
81fi
82grep "globalSetUp was here" /tmp/output >/dev/null 2>&1
83if [ $? -ne 1 ]; then
84 echo "Expected localSetUp to have been ignored."
85 exit 1
86fi
87
88$W -g $E/global-setup.js ${ANY_SUITE} >/tmp/output 2>&1
89if [ $? -ne 0 ]; then
90 echo "Expected invokation of global setup to not harm Whiskey."
91 exit 1
92fi
93grep "globalSetUp was here" /tmp/output >/dev/null 2>&1
94if [ $? -ne 0 ]; then
95 echo "Expected globalSetUp to have been invoked."
96 exit 1
97fi
98
99$W -g ${ANY_SUITE}
100if [ $? -eq 0 ]; then
101 echo "Missing parameter should cause whiskey to fail."
102 exit 1
103fi
104
105$W --global-setup-teardown ${ANY_SUITE}
106if [ $? -eq 0 ]; then
107 echo "Missing parameter should cause whiskey to fail."
108 exit 1
109fi
110
111$W -g $E/empty-global-setup-teardown.js ${ANY_SUITE}
112if [ $? -ne 0 ]; then
113 echo "An empty global setup/teardown file should be syntactically correct."
114 echo "Also, a file used as such, but which doesn't export the appropriate"
115 echo "procedures (globalSetUp or globalTearDown) should behave the same way."
116 exit 1
117fi
118
119$W --global-setup-teardown $E/empty-global-setup-teardown.js ${ANY_SUITE}
120if [ $? -ne 0 ]; then
121 echo "An empty global setup/teardown file should be syntactically correct."
122 echo "Also, a file used as such, but which doesn't export the appropriate"
123 echo "procedures (globalSetUp or globalTearDown) should behave the same way."
124 exit 1
125fi
126
127$W -g $E/malformed-javascript-source.js ${ANY_SUITE}
128if [ $? -eq 0 ]; then
129 echo "A malformed source should cause Whiskey to die early."
130 exit 1
131fi
132
133START=$(date +%s)
134$W -m 2 --independent-tests "$E/test-long-running-1.js $E/test-long-running-2.js"
135if [ $? -ne 0 ]; then
136 echo "long-running tests should pass"
137 exit 1
138fi
139END=$(date +%s)
140DIFF=$(( $END - $START ))
141if [ $DIFF -ge 7 ]; then
142 echo "Total test execution time should be less than 6 seconds (assuming code hasn't been changed.)"
143 exit 1
144fi
145
146$W --independent-tests "$E/test-long-running-1.js $E/test-long-running-2.js $E/test-failure.js"
147if [ $? -ne 2 ]; then
148 echo "2 tests should fail when running tests independently."
149 exit 1
150fi
151
152$W --tests "$E/test-success.js"
153
154if [ $? -ne 0 ]; then
155 echo "tests should pass"
156 exit 1
157fi
158
159$W --tests "$E/test-failure.js"
160
161if [ $? -ne 2 ]; then
162 echo "2 tests should fail"
163 exit 1
164fi
165
166$W --failfast --timeout 500 \
167 --tests --concurrency 100 "$E/test-failure.js $E/test-timeout.js"
168
169if [ $? -ne 1 ]; then
170 echo "1 test should fail"
171 exit 1
172fi
173
174$W --failfast --timeout 500 \
175 --tests "$E/test-timeout.js $E/test-failure.js $E/test-timeout.js"
176
177if [ $? -ne 1 ]; then
178 echo "1 test should fail"
179 exit 1
180fi
181
182$W --timeout 1000 --tests "$E/test-timeout.js"
183
184if [ ! $? -eq 1 ]; then
185 echo "test should time out"
186 exit 1
187fi
188
189$W --timeout 1000 --tests "$E/test-timeout-blocking.js"
190
191if [ ! $? -eq 1 ]; then
192 echo "test should time out"
193 exit 1
194fi
195
196$W --tests "$E/test-setup-and-teardown.js"
197
198if [ $? -ne 0 ]; then
199 echo "test should pass"
200 exit 1
201fi
202
203# Test file does not exist
204$W --tests "$E/test-inexistent.js"
205
206if [ $? -ne 1 ]; then
207 echo "1 test should fail"
208 exit 1
209fi
210
211$W --tests "$E/test-setup-fail.js"
212
213if [ $? -ne 3 ]; then
214 echo "3 tests should fail"
215 exit 1
216fi
217
218# Test relative path
219$W --tests "example/test-success.js"
220
221if [ $? -ne 0 ]; then
222 echo "tests should pass."
223 exit 1
224fi
225
226# Test multiple files
227$W --tests "$E/test-success.js $E/test-failure.js"
228
229if [ ! $? -gt 0 ]; then
230 echo "2 tests should fail"
231 exit 1
232fi
233
234# Test test init file
235FOLDER_EXISTS=0
236rm -rf $E/test-123456
237
238$W --test-init-file "$E/init.js" --tests "$E/test-success.js"
239
240if [ -d $E/test-123456 ]; then
241 FOLDER_EXISTS=1
242fi
243
244rm -rf $E/test-123456
245
246if [ $? -ne 0 ] || [ ${FOLDER_EXISTS} -ne 1 ]; then
247 echo ${FOLDER_EXISTS}
248 echo "test should pass m"
249 exit 1
250fi
251
252# test uncaught exceptions
253$W --tests "$E/test-uncaught.js"
254
255if [ $? -ne 5 ]; then
256 echo "5 tests should fail"
257 exit 1
258fi
259
260# Test chdir
261$W --tests "$E/test-chdir.js"
262
263if [ $? -ne 1 ]; then
264 echo "1 test should fail"
265 exit 1
266fi
267
268$W --tests "$E/test-chdir.js" --chdir "$E/"
269
270if [ $? -ne 0 ]; then
271 echo "tests should pass y"
272 exit 1
273fi
274
275# Test per test init function
276$W --test-init-file "$E/init-test.js" --tests "$E/test-init-function.js"
277
278if [ $? -ne 0 ]; then
279 echo "tests should pass x"
280 exit 1
281fi
282
283# Test init function timeout (callback in init function is not called)
284$W --timeout 2000 --test-init-file "$E/init-timeout.js" --tests "$E/test-failure.js"
285
286if [ $? -ne 1 ]; then
287 echo "1 test should fail (callback in init function is not called)"
288 exit 1
289fi
290
291# Test setUp function timeout (setUp function .finish() is not called)
292$W --timeout 1000 --tests "$E/test-setup-timeout.js" --chdir "$E/"
293
294if [ $? -ne 1 ]; then
295 echo "1 test should fail (setUp timeout)"
296 exit 1
297fi
298
299# Test tearDown function timeout (tearDown function .finish() is not called)
300$W --timeout 2000 --tests "$E/test-teardown-timeout.js" --chdir "$E/"
301
302if [ $? -ne 2 ]; then
303 echo "1 test should fail (tearDown timeout)"
304 exit 1
305fi
306
307$W --timeout 2000 --tests "$E/test-custom-assert-functions.js"
308
309if [ $? -ne 2 ]; then
310 echo "2 tests should fail"
311 exit 1
312fi
313
314$W --timeout 2000 \
315 --tests "$E/test-custom-assert-functions.js" \
316 --custom-assert-module "$E/custom-assert-functions.js"
317
318if [ $? -ne 1 ]; then
319 echo "1 test should fail"
320 exit 1
321fi
322
323"$E/test-stdout-and-stderr-is-captured-on-timeout.js"
324
325if [ $? -ne 0 ]; then
326 echo "test file stdout and stderr was not properly captured during test timeout"
327 exit 1
328fi
329
330# Verify that when a test file timeout the tests which haven't time out are
331# reported properly
332"$E/test-succeeded-tests-are-reported-on-timeout.js"
333
334if [ $? -ne 0 ]; then
335 echo "succeeded tests were not reported properly upon a test file timeout"
336 exit 1
337fi
338
339# Verify that coverage works properly
340if [ "$(which jscoverage)" ]; then
341 "$E/test-jscoverage.js"
342
343 if [ $? -ne 0 ]; then
344 echo "coverage does not work properly"
345 exit 1
346 fi
347else
348 echo 'jscoverage not installed, skipping coverage tests'
349fi
350
351# Make sure that the child which blocks after call .finish() is killed and
352# timeout properly reported
353$W --timeout 1000 \
354 --tests "$E/test-timeout-after-finish.js"
355
356if [ $? -ne 1 ]; then
357 echo "1 test should timeout"
358 exit 1
359fi
360
361# Scope leaks test (sequential and parallel mode)
362"$E/test-leaks.js"
363
364if [ $? -ne 0 ]; then
365 echo "scope leaks were not reported properly"
366 exit 1
367fi
368
369# No test function is exported, it should quit immediately
370$W --timeout 1000 \
371 --tests "$E/test-no-test-functions.js"
372
373if [ $? -ne 0 ]; then
374 echo "test didn't exit with zero exit code"
375 exit 1
376fi
377
378$W --timeout 1000 \
379 --tests "$E/test-skipped.js"
380
381if [ $? -ne 0 ]; then
382 echo "test didn't exit with zero exit code"
383 exit 1
384fi
385
386$W --timeout 1000 \
387 --tests "$E/test-custom-assert-methods.js"
388
389if [ $? -ne 0 ]; then
390 echo "test didn't exit with zero exit code"
391 exit 1
392fi
393
394# Test pattern name matching
395$W --timeout 1000 \
396 --tests "example.test-failure.test_one_is_not*"
397
398if [ $? -ne 1 ]; then
399 echo "test didn't exit with 1 exit code"
400 exit 1
401fi
402
403$W --timeout 1000 \
404 --tests "$E/test-getFilePathAndPattern.js"
405
406if [ $? -ne 0 ]; then
407 echo "test didn't exit with zero exit code"
408 exit 1
409fi
410
411$W --timeout 1000 \
412 --tests "$E/test-spyon.js"
413
414if [ $? -ne 0 ]; then
415 echo "Test didn't exit with zero exit code."
416 exit 1
417fi
418
419$W --timeout 1000 \
420--tests "$E/test-bdd.js"
421
422if [ $? -ne 0 ]; then
423 echo "BDD test didn't exit with zero exit code."
424 exit 1
425fi
426
427$W --timeout 1000 \
428--tests "$E/test-bdd-failures.js"
429
430if [ $? -ne 4 ]; then
431 echo "BDD failure test didn't fail as expected."
432 exit 1
433fi
434
435$W --tests "$E/test-throw-string.js"
436
437if [ $? -ne 2 ]; then
438 echo "2 tests should have failed"
439 exit 1
440fi
441
442echo ""
443echo "* * * Whiskey test suite PASSED. * * *"
444exit 0