forked from heroku/heroku-buildpack-nodejs
/
test
executable file
·138 lines (114 loc) · 3.27 KB
/
test
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
#!/usr/bin/env bash
# See README.md for info on running these tests.
testDetectWithPackageJson() {
detect "stable-node"
assertCaptured "Node.js"
assertCapturedSuccess
}
testDetectWithoutPackageJson() {
detect "no-package-json"
assertCapturedError 1 ""
}
testNoVersion() {
compile "no-version"
assertCaptured "PRO TIP: Specify a node version in package.json"
assertCaptured "Defaulting to latest stable node"
assertCapturedSuccess
}
testDangerousRangeStar() {
compile "dangerous-range-star"
assertCaptured "PRO TIP: Avoid using semver ranges like '*'"
assertCaptured "Requested node range: *"
assertCaptured "Resolved node version: 0.10"
assertCapturedSuccess
}
testDangerousRangeGreaterThan() {
compile "dangerous-range-greater-than"
assertCaptured "PRO TIP: Avoid using semver ranges starting with '>'"
assertCaptured "Requested node range: >"
assertCaptured "Resolved node version: 0.10."
assertCapturedSuccess
}
testRangeWithSpace() {
compile "range-with-space"
assertCaptured "Requested node range: >= 0.8.x"
assertCaptured "Resolved node version: 0.10."
assertCapturedSuccess
}
testStableVersion() {
compile "stable-node"
assertNotCaptured "PRO TIP: Avoid using semver"
assertNotCaptured "PRO TIP: Specify"
assertCaptured "Resolved node version"
assertCapturedSuccess
}
testUnstableVersion() {
compile "unstable-version"
assertCaptured "Requested node range: >0.11.0"
assertCaptured "Resolved node version: 0.11."
assertCapturedSuccess
}
testProfileCreated() {
compile "stable-node"
assertCaptured "Building runtime environment"
assertFile "export PATH=\"\$HOME/vendor/node/bin:\$HOME/bin:\$HOME/node_modules/.bin:\$PATH\"" ".profile.d/nodejs.sh"
assertCapturedSuccess
}
testInvalidDependency() {
compile "invalid-dependency"
assertCaptured "not in the npm registry"
assertCapturedError 1 ""
}
testNodeModulesCached() {
cache=$(mktmpdir)
compile "caching" $cache
assertCaptured "Caching node"
assertEquals "1" "$(ls -1 $cache/ | wc -l)"
}
testModulesCheckedIn() {
compile "modules-checked-in"
assertCaptured "Found existing node_modules directory; skipping cache"
assertCaptured "Rebuilding any native dependencies"
assertCapturedSuccess
}
testUserConfig() {
compile "userconfig"
assertCaptured "https://www.google.com/"
assertCaptured "registry error"
assertCapturedError 1 ""
}
testProcfileAbsentNpmStartPresent() {
compile "procfile-absent-npm-start-present"
assertCaptured "No Procfile found; Adding npm start to new Procfile"
assertFile "web: npm start" "Procfile"
assertCapturedSuccess
}
testProcfileAbsentNpmStartAbsent() {
compile "procfile-absent-npm-start-absent"
assertCaptured "Create a Procfile or specify a start script in package.json"
assertCapturedSuccess
}
# Utils
pushd $(dirname 0) >/dev/null
bp_dir=$(pwd)
popd >/dev/null
source ${bp_dir}/vendor/test-utils/test-utils
mktmpdir() {
dir=$(mktemp -t testXXXXX)
rm -rf $dir
mkdir $dir
echo $dir
}
detect() {
capture ${bp_dir}/bin/detect ${bp_dir}/test/$1
}
compile_dir=""
compile() {
compile_dir=$(mktmpdir)
cp -r ${bp_dir}/test/$1/. ${compile_dir}
capture ${bp_dir}/bin/compile ${compile_dir} ${2:-$(mktmpdir)}
}
assertFile() {
assertEquals "$1" "$(cat ${compile_dir}/$2)"
}
source ${bp_dir}/vendor/shunit2/shunit2