-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathbuild_test.sh
More file actions
executable file
·257 lines (143 loc) · 4.99 KB
/
build_test.sh
File metadata and controls
executable file
·257 lines (143 loc) · 4.99 KB
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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
#!/usr/bin/env bash
set -e
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
source $SCRIPT_DIR/.test_support.sh
# include source files
source $SCRIPT_DIR/../lib/common.sh
source $SCRIPT_DIR/../lib/build.sh
# override node/npm commands for cache_versions tests
node() {
echo "v20.0.0"
}
npm() {
echo "9.6.7"
}
# TESTS
######################
suite "cache_versions"
test "stores node version to cache dir"
cache_dir=$TEST_DIR/cache_cv
mkdir -p $cache_dir
cache_versions
[ -f $cache_dir/node-version ]
[ "v20.0.0" == "$(cat $cache_dir/node-version | tr -d '[:space:]')" ]
rm -rf $cache_dir
test "stores npm version to cache dir"
cache_dir=$TEST_DIR/cache_cv2
mkdir -p $cache_dir
cache_versions
[ -f $cache_dir/npm-version ]
[ "9.6.7" == "$(cat $cache_dir/npm-version | tr -d '[:space:]')" ]
rm -rf $cache_dir
suite "write_profile"
test "creates .profile.d directory"
build_dir=$TEST_DIR/build_wp
mkdir -p $build_dir
phoenix_relative_path=.
write_profile
[ -d $build_dir/.profile.d ]
rm -rf $build_dir
test "creates profile script with correct PATH exports"
build_dir=$TEST_DIR/build_wp2
mkdir -p $build_dir
phoenix_relative_path=.
write_profile
[ -f $build_dir/.profile.d/phoenix_static_buildpack_paths.sh ]
grep -q 'HOME/.heroku/node/bin' $build_dir/.profile.d/phoenix_static_buildpack_paths.sh
grep -q 'HOME/.heroku/yarn/bin' $build_dir/.profile.d/phoenix_static_buildpack_paths.sh
grep -q 'node_modules/.bin' $build_dir/.profile.d/phoenix_static_buildpack_paths.sh
rm -rf $build_dir
test "uses custom phoenix_relative_path in profile"
build_dir=$TEST_DIR/build_wp3
mkdir -p $build_dir
phoenix_relative_path=apps/my_app
write_profile
grep -q 'apps/my_app/node_modules/.bin' $build_dir/.profile.d/phoenix_static_buildpack_paths.sh
rm -rf $build_dir
suite "setup_phx_envvars"
test "creates env file with PHX_SERVER default"
build_dir=$TEST_DIR/build_phx
mkdir -p $build_dir
setup_phx_envvars
[ -f $build_dir/.profile.d/phoenix_static_buildpack_env.sh ]
grep -q 'PHX_SERVER' $build_dir/.profile.d/phoenix_static_buildpack_env.sh
rm -rf $build_dir
test "creates env file with PHX_HOST default"
build_dir=$TEST_DIR/build_phx2
mkdir -p $build_dir
setup_phx_envvars
grep -q 'PHX_HOST' $build_dir/.profile.d/phoenix_static_buildpack_env.sh
grep -q 'gigalixirapp.com' $build_dir/.profile.d/phoenix_static_buildpack_env.sh
rm -rf $build_dir
test "creates .profile.d directory if missing"
build_dir=$TEST_DIR/build_phx3
mkdir -p $build_dir
setup_phx_envvars
[ -d $build_dir/.profile.d ]
rm -rf $build_dir
suite "finalize_node"
test "calls write_profile when remove_node is false"
build_dir=$TEST_DIR/build_fn
mkdir -p $build_dir
remove_node=false
phoenix_relative_path=.
finalize_node
[ -f $build_dir/.profile.d/phoenix_static_buildpack_paths.sh ]
rm -rf $build_dir
test "removes node when remove_node is true"
build_dir=$TEST_DIR/build_fn2
heroku_dir=$TEST_DIR/build_fn2/.heroku
assets_dir=$TEST_DIR/build_fn2/assets
mkdir -p $heroku_dir/node
mkdir -p $assets_dir/node_modules
touch $heroku_dir/node/node_binary
touch $assets_dir/node_modules/some_module
remove_node=true
finalize_node
[ ! -d $assets_dir/node_modules ]
[ ! -d $heroku_dir/node ]
rm -rf $build_dir
suite "load_previous_npm_node_versions"
test "loads cached npm and node versions"
cache_dir=$TEST_DIR/cache_prev
mkdir -p $cache_dir
echo "9.0.0" > $cache_dir/npm-version
echo "v18.0.0" > $cache_dir/node-version
load_previous_npm_node_versions
[ "9.0.0" == "$(echo $old_npm | tr -d '[:space:]')" ]
[ "v18.0.0" == "$(echo $old_node | tr -d '[:space:]')" ]
rm -rf $cache_dir
test "handles missing cache files"
cache_dir=$TEST_DIR/cache_prev_empty
mkdir -p $cache_dir
unset old_npm old_node
load_previous_npm_node_versions
# should not error when files don't exist
suite "cleanup_cache"
test "cleans cache when clean_cache is true"
cache_dir=$TEST_DIR/cache_clean
mkdir -p $cache_dir/node_modules
mkdir -p $cache_dir/phoenix-static
mkdir -p $cache_dir/yarn-cache
echo "v18" > $cache_dir/node-version
echo "9.0" > $cache_dir/npm-version
clean_cache=true
old_node=""
node_version=""
cleanup_cache
[ ! -f $cache_dir/node-version ]
[ ! -f $cache_dir/npm-version ]
[ ! -d $cache_dir/phoenix-static ]
[ ! -d $cache_dir/yarn-cache ]
[ ! -d $cache_dir/node_modules ]
rm -rf $cache_dir
test "preserves cache when clean_cache is false"
cache_dir=$TEST_DIR/cache_keep
mkdir -p $cache_dir/node_modules
echo "v18" > $cache_dir/node-version
clean_cache=false
cleanup_cache
[ -f $cache_dir/node-version ]
[ -d $cache_dir/node_modules ]
rm -rf $cache_dir
PASSED_ALL_TESTS=true