-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.sh
executable file
·112 lines (88 loc) · 1.94 KB
/
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#!/usr/bin/env bash
function pushd () {
command pushd "$@" > /dev/null
}
function popd () {
command popd "$@" > /dev/null
}
function tmpdir() {
mktemp -d -t nnny-test-XXXXXX
}
function verify_node() {
expected_version="v$1"
actual_version=$(node --version)
if [ ${expected_version} != ${actual_version} ]; then
echo "Expected npm version to be ${expected_version}, but was ${actual_version}"
exit 1
fi
}
function verify_yarn() {
expected_version=$1
if [ ${expected_version} == "none" ]; then
if type yarn 2> /dev/null; then
echo "Expected yarn to not be installed, but it was"
exit 1
fi
else
actual_version=$(yarn --version)
if [ ${expected_version} != ${actual_version} ]; then
echo "Expected yarn version to be ${expected_version}, but was ${actual_version}"
exit 1
fi
fi
}
function verify_npm() {
expected_version=$1
actual_version=$(npm --version)
if [ ${expected_version} != ${actual_version} ]; then
echo "Expected npm version to be ${expected_version}, but was ${actual_version}"
exit 1
fi
}
function run_nnny() {
(
curl -so- https://raw.githubusercontent.com/MeLlamoPablo/nnny/master/nnny.sh | bash
) > /dev/null
}
function cleanup() {
rm -rf /usr/bin/node \
/usr/bin/npm \
/usr/bin/yarn \
/usr/bin/npx \
/usr/bin/nnny
}
pushd $(tmpdir)
printf "nnny should install node and yarn, and update npm..."
cat > package.json <<- EOF
{
"engines": {
"node": "8.11.0",
"yarn": "1.5.1",
"npm": "5.7.1"
}
}
EOF
run_nnny
verify_node 8.11.0
verify_yarn 1.5.1
verify_npm 5.7.1
printf "\rnnny should install node and yarn, and update npm... Pass\n"
popd
cleanup
pushd $(tmpdir)
printf "nnny should install only node..."
cat > package.json <<- EOF
{
"engines": {
"node": "8.11.0"
}
}
EOF
run_nnny
verify_node 8.11.0
verify_npm 5.6.0 # Bundled with node
verify_yarn none
printf "\rshould install only node... Pass\n"
popd
echo ""
echo "All tests passed successfully!"