-
Notifications
You must be signed in to change notification settings - Fork 29
/
functional_test.sh
executable file
·98 lines (79 loc) · 2.91 KB
/
functional_test.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#! /bin/sh
TEST_PATH=./tmp_testfolder
FAILED=0
export TRYMODULE_PATH=$TEST_PATH
export TRYMODULE_NONINTERACTIVE=true
run_test()
{
echo "--------------"
echo "## $1 | $2"
$2
}
run_test_command()
{
echo "--------------"
echo "## $1"
echo "## $2 ?= $3"
x=$(echo "$2" | ./cli.js colors | grep "$3")
[ "${x}" != "$3" ]
}
check_failure()
{
if [ $? -ne 0 ]
then
echo "######## $1 !!!!!!!!!!!!!!"
FAILED=1
fi
}
check_should_error()
{
if [ $? -ne 1 ]
then
echo "######## $1 !!!!!!!!!!!!!!"
FAILED=1
fi
}
# Install one package
run_test "Can install package 'colors'" "./cli.js colors"
test -d $TEST_PATH/node_modules/colors
check_failure "node_modules/colors was not installed"
# Install two packages
run_test "Can install packages 'colors' & 'lodash'" "./cli.js colors lodash"
test -d $TEST_PATH/node_modules/colors
check_failure "node_modules/colors was not installed"
test -d $TEST_PATH/node_modules/lodash
check_failure "node_modules/lodash was not installed"
# Install two packages and bind to custom variable names
run_test "Can install packages 'colors' & 'lodash' as 'c' and '_'" "./cli.js colors=c lodash=_"
check_failure "Could not assign to custom variable names"
# Can't install packages that doesn't exists
run_test "Cannot install missing package 'coloursssss'" "./cli.js coloursssss"
test -d $TEST_PATH/node_modules/coloursssss
check_should_error "node_modules/coloursssss was installed"
echo "NOTE: Above error is normal and is fine, we're testing that we cannot install missing packages"
# Check that Promises are detected
run_test_command "Can detect that a Promise is NOT returned" "'OK_TOKEN'" "OK_TOKEN"
check_failure "Incorrectly detected a Promise"
run_test_command "Can detect that a Promise is returned" "new Promise(function(){})" "Returned a Promise. waiting for result..."
check_failure "Could not detect a Promise"
run_test_command "Can detect when a non-native Promise is returned" "{then: function() {}}" "Returned a Promise. waiting for result..."
check_failure "Could not detect a non-native Promise"
run_test_command "Can output the result of a Promise" "new Promise(function(resolve){ resolve('OK_TOKEN') })" "OK_TOKEN"
check_failure "Did not output the result of a Promise"
run_test_command "Can output the result of an async Promise (2 sec)" "new Promise(function(resolve){ setTimeout(function(){resolve('OK_TOKEN')}, 2000) })" "OK_TOKEN"
check_failure "Did not output the result of an async Promise"
run_test_command "Can output when a Promise is rejected" "new Promise(function(resolve, reject){ reject(new Error('REJECT_TOKEN')) })" "REJECT_TOKEN"
check_failure "Did not output the result of a Promise"
# Clear cache
run_test "Can clear the cache" "./cli.js --clear"
test -d $TEST_PATH/node_modules
check_should_error "node_modules existed!"
if [ $FAILED -eq 0 ]
then
echo "\n\nALL TESTS PASSED!"
rm -fr $TEST_PATH
exit 0
fi
echo "\n\nFAILING TESTS!"
rm -fr $TEST_PATH
exit 1